From: Francis Dupont Date: Sun, 27 Nov 2016 10:28:03 +0000 (+0100) Subject: [5014_phase2] More tests and fixes X-Git-Tag: trac5036_base2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2508dd159fe79779b910b66ec066e46212fca69d;p=thirdparty%2Fkea.git [5014_phase2] More tests and fixes --- diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index 69a651d1ff..b93b988ef0 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -110,7 +110,6 @@ JSONString \"{JSONStringCharacter}*\" if (start_token_flag) { start_token_flag = false; - BEGIN(0); switch (start_token_value) { case Parser6Context::PARSER_DHCP6: return isc::dhcp::Dhcp6Parser::make_TOPLEVEL_DHCP6(loc); @@ -780,10 +779,6 @@ JSONString \"{JSONStringCharacter}*\" std::string tmp(yytext); double fp = 0.0; try { - // In substring we want to use negative values (e.g. -1). - // In enterprise-id we need to use values up to 0xffffffff. - // To cover both of those use cases, we need at least - // int64_t. fp = boost::lexical_cast(tmp); } catch (const boost::bad_lexical_cast &) { driver.error(loc, "Failed to convert " + tmp + " to a floating point."); @@ -825,6 +820,10 @@ using namespace isc::dhcp; void Parser6Context::scanStringBegin(const std::string& str, ParserType parser_type) { + locs.clear(); + files.clear(); + states.clear(); + static_cast(parser6_lex_destroy()); start_token_flag = true; start_token_value = parser_type; @@ -848,8 +847,12 @@ Parser6Context::scanStringEnd() void Parser6Context::scanFileBegin(FILE * f, const std::string& filename, - ParserType parser_type) { - + ParserType parser_type) +{ + locs.clear(); + files.clear(); + states.clear(); + static_cast(parser6_lex_destroy()); start_token_flag = true; start_token_value = parser_type; diff --git a/src/bin/dhcp6/tests/parser_unittest.cc b/src/bin/dhcp6/tests/parser_unittest.cc index f2d2c7e081..1315fac84e 100644 --- a/src/bin/dhcp6/tests/parser_unittest.cc +++ b/src/bin/dhcp6/tests/parser_unittest.cc @@ -264,8 +264,9 @@ void testError(const std::string& txt, } } -// Check lexer errors -TEST(ParserTest, lexerErrors) { +// Check errors +TEST(ParserTest, errors) { + // no input testError("", Parser6Context::PARSER_GENERIC_JSON, ":1.1: syntax error, unexpected end of file, " @@ -278,6 +279,8 @@ TEST(ParserTest, lexerErrors) { Parser6Context::PARSER_GENERIC_JSON, ":2.1: syntax error, unexpected end of file, " "expecting {"); + + // comments testError("# nothing\n", Parser6Context::PARSER_GENERIC_JSON, ":2.1: syntax error, unexpected end of file, " @@ -305,10 +308,21 @@ TEST(ParserTest, lexerErrors) { 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, + ":1.3-8: Invalid character: *"); + testError("{ /* // *// }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3-11: Invalid character: /"); + testError("{ /* // */// }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":2.1: syntax error, unexpected end of file, " + "expecting }"); + + // includes testError("/n", + Parser6Context::PARSER_GENERIC_JSON, + "Can't open include file /foo/bar"); + + // numbers + testError("123", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-3: syntax error, unexpected integer, " + "expecting {"); + testError("-456", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-4: syntax error, unexpected integer, " + "expecting {"); + testError("-0001", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-5: syntax error, unexpected integer, " + "expecting {"); + testError("1234567890123456789012345678901234567890", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-40: Failed to convert " + "1234567890123456789012345678901234567890" + " to an integer."); + testError("-3.14e+0", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-8: syntax error, unexpected floating point, " + "expecting {"); + testError("1e50000", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-7: Failed to convert 1e50000 " + "to a floating point."); + + // strings + testError("\"aabb\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-6: syntax error, unexpected constant string, " + "expecting {"); + testError("{ \"aabb\"err", + Parser6Context::PARSER_GENERIC_JSON, + ":1.9: Invalid character: e"); + testError("{ err\"aabb\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3: Invalid character: e"); + testError("\"a\n\tb\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-6: syntax error, unexpected constant string, " + "expecting {"); + testError("\"a\\n\\tb\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-8: syntax error, unexpected constant string, " + "expecting {"); + testError("\"a\\x01b\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1: Invalid character: \""); + testError("\"a\\u0062\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1-9: syntax error, unexpected constant string, " + "expecting {"); + testError("\"a\\u062z\"", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1: Invalid character: \""); + + // want a map + testError("[]\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.1: syntax error, unexpected [, " + "expecting {"); + testError("[]\n", + Parser6Context::PARSER_DHCP6, + ":1.1: syntax error, unexpected [, " + "expecting {"); + testError("{ 123 }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3-5: syntax error, unexpected integer, " + "expecting }"); + testError("{ 123 }\n", + Parser6Context::PARSER_DHCP6, + ":1.3-5: syntax error, unexpected integer, " + "expecting Dhcp6 or Logging"); + testError("{ \"foo\" }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.9: syntax error, unexpected }, " + "expecting :"); + testError("{ \"foo\" }\n", + Parser6Context::PARSER_DHCP6, + ":1.3-7: syntax error, unexpected constant string, " + "expecting Dhcp6 or Logging"); + testError("{ \"Dhcp6\" }\n", + Parser6Context::PARSER_DHCP6, + ":1.11: syntax error, unexpected }, " + "expecting :"); + testError("{}{}", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3: syntax error, unexpected {, " + "expecting end of file"); + + // bad commas + testError("{ , }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3: syntax error, unexpected \",\", " + "expecting }"); + testError("{ , \"foo\":true }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.3: syntax error, unexpected \",\", " + "expecting }"); + testError("{ \"foo\":true, }\n", + Parser6Context::PARSER_GENERIC_JSON, + ":1.15: syntax error, unexpected }, " + "expecting constant string"); + + // bad type + testError("{ \"Dhcp6\":{\n" + " \"preferred-lifetime\":false }}\n", + Parser6Context::PARSER_DHCP6, + ":2.24-28: syntax error, unexpected boolean, " + "expecting integer"); + + // unknown keyword + testError("{ \"Dhcp6\":{\n" + " \"preferred_lifetime\":600 }}\n", + Parser6Context::PARSER_DHCP6, + ":2.2-21: got unexpected keyword " + "\"preferred_lifetime\" in Dhcp6 map."); } };