}
}
-// Check lexer errors
-TEST(ParserTest, lexerErrors) {
+// Check errors
+TEST(ParserTest, errors) {
+ // no input
testError("",
Parser6Context::PARSER_GENERIC_JSON,
"<string>:1.1: syntax error, unexpected end of file, "
Parser6Context::PARSER_GENERIC_JSON,
"<string>:2.1: syntax error, unexpected end of file, "
"expecting {");
+
+ // comments
testError("# nothing\n",
Parser6Context::PARSER_GENERIC_JSON,
"<string>:2.1: syntax error, unexpected end of file, "
testError("/* nothing\n",
Parser6Context::PARSER_GENERIC_JSON,
"Comment not closed. (/* in line 1");
- fprintf(stderr, "got 124?\n");
- testError("/**/\n\n\n/* nothing\n",
+ testError("\n\n\n/* nothing\n",
Parser6Context::PARSER_GENERIC_JSON,
"Comment not closed. (/* in line 4");
+ testError("{ /* */*/ }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3-8: Invalid character: *");
+ testError("{ /* // *// }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3-11: Invalid character: /");
+ testError("{ /* // */// }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:2.1: syntax error, unexpected end of file, "
+ "expecting }");
+
+ // includes
testError("<?\n",
Parser6Context::PARSER_GENERIC_JSON,
"Directive not closed.");
Parser6Context::PARSER_GENERIC_JSON,
"Directive not closed.");
string file = string(CFG_EXAMPLES) + "/" + "stateless.json";
- fprintf(stderr, "doing include\n");
testError("<?include \"" + file + "\"\n",
Parser6Context::PARSER_GENERIC_JSON,
"Directive not closed.");
+ testError("<?include \"/foo/bar\" ?>/n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "Can't open include file /foo/bar");
+
+ // numbers
+ testError("123",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-3: syntax error, unexpected integer, "
+ "expecting {");
+ testError("-456",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-4: syntax error, unexpected integer, "
+ "expecting {");
+ testError("-0001",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-5: syntax error, unexpected integer, "
+ "expecting {");
+ testError("1234567890123456789012345678901234567890",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-40: Failed to convert "
+ "1234567890123456789012345678901234567890"
+ " to an integer.");
+ testError("-3.14e+0",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-8: syntax error, unexpected floating point, "
+ "expecting {");
+ testError("1e50000",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-7: Failed to convert 1e50000 "
+ "to a floating point.");
+
+ // strings
+ testError("\"aabb\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-6: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("{ \"aabb\"err",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.9: Invalid character: e");
+ testError("{ err\"aabb\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3: Invalid character: e");
+ testError("\"a\n\tb\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-6: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("\"a\\n\\tb\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-8: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("\"a\\x01b\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1: Invalid character: \"");
+ testError("\"a\\u0062\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1-9: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("\"a\\u062z\"",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1: Invalid character: \"");
+
+ // want a map
+ testError("[]\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.1: syntax error, unexpected [, "
+ "expecting {");
+ testError("[]\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:1.1: syntax error, unexpected [, "
+ "expecting {");
+ testError("{ 123 }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3-5: syntax error, unexpected integer, "
+ "expecting }");
+ testError("{ 123 }\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:1.3-5: syntax error, unexpected integer, "
+ "expecting Dhcp6 or Logging");
+ testError("{ \"foo\" }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.9: syntax error, unexpected }, "
+ "expecting :");
+ testError("{ \"foo\" }\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:1.3-7: syntax error, unexpected constant string, "
+ "expecting Dhcp6 or Logging");
+ testError("{ \"Dhcp6\" }\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:1.11: syntax error, unexpected }, "
+ "expecting :");
+ testError("{}{}",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3: syntax error, unexpected {, "
+ "expecting end of file");
+
+ // bad commas
+ testError("{ , }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3: syntax error, unexpected \",\", "
+ "expecting }");
+ testError("{ , \"foo\":true }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.3: syntax error, unexpected \",\", "
+ "expecting }");
+ testError("{ \"foo\":true, }\n",
+ Parser6Context::PARSER_GENERIC_JSON,
+ "<string>:1.15: syntax error, unexpected }, "
+ "expecting constant string");
+
+ // bad type
+ testError("{ \"Dhcp6\":{\n"
+ " \"preferred-lifetime\":false }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:2.24-28: syntax error, unexpected boolean, "
+ "expecting integer");
+
+ // unknown keyword
+ testError("{ \"Dhcp6\":{\n"
+ " \"preferred_lifetime\":600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:2.2-21: got unexpected keyword "
+ "\"preferred_lifetime\" in Dhcp6 map.");
}
};