TEST(ParserTest, listInList) {
string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
- " [ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, listsInMaps) {
string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
- "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, mapsInLists) {
- string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
- " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 }, "
+ "{ \"body\": \"mars\", \"gravity\": 0.376 } ]";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, types) {
- string txt = "{ \"string\": \"foo\","
- "\"integer\": 42,"
- "\"boolean\": true,"
- "\"map\": { \"foo\": \"bar\" },"
- "\"list\": [ 1, 2, 3 ],"
- "\"null\": null }";
+ string txt = "{ \"string\": \"foo\", "
+ "\"integer\": 42, "
+ "\"boolean\": true, "
+ "\"map\": { \"foo\": \"bar\" }, "
+ "\"list\": [ 1, 2, 3 ], "
+ "\"null\": null }";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, keywordJSON) {
- string txt = "{ \"name\": \"user\","
- "\"type\": \"password\","
- "\"user\": \"name\","
- "\"password\": \"type\" }";
+ string txt = "{ \"name\": \"user\", "
+ "\"type\": \"password\", "
+ "\"user\": \"name\", "
+ "\"password\": \"type\" }";
testParser(txt, ParserContext::PARSER_JSON);
}
" }"
" ]"
"}";
+
// This is only a subset of full config, so we'll parse with PARSER_SUB_AGENT.
testParser(txt, ParserContext::PARSER_SUB_AGENT);
testParser(txt, ParserContext::PARSER_JSON);
// Tests if bash (#) comments are supported. That's the only comment type that
// was supported by the old parser.
TEST(ParserTest, bashComments) {
- string txt = "{ \"Control-agent\": {"
- " \"http-host\": \"localhost\","
+ string txt = "{ \"Control-agent\": {\n"
+ " \"http-host\": \"localhost\",\n"
" \"http-port\": 9000,\n"
" \"control-sockets\": {\n"
" \"d2\": {\n"
// Tests if C++ (//) comments can start anywhere, not just in the first line.
TEST(ParserTest, cppComments) {
- string txt = "{ \"Control-agent\": {"
- " \"http-host\": \"localhost\","
+ string txt = "{ \"Control-agent\": {\n"
+ " \"http-host\": \"localhost\",\n"
" \"http-port\": 9001, // the level is over 9000!\n"
" \"control-sockets\": {\n"
" // Let's try talking to D2. Sadly, it never talks"
// Tests if bash (#) comments can start anywhere, not just in the first line.
TEST(ParserTest, bashCommentsInline) {
- string txt= "{ \"Control-agent\": {"
- " \"http-host\": \"localhost\","
+ string txt= "{ \"Control-agent\": {\n"
+ " \"http-host\": \"localhost\",\n"
" \"http-port\": 9000,\n"
" \"control-sockets\": {\n"
" \"d2\": {"
// Tests if multi-line C style comments are handled correctly.
TEST(ParserTest, multilineComments) {
- string txt = "{ \"Control-agent\": {"
- " \"http-host\": \"localhost\","
+ string txt = "{ \"Control-agent\": {\n"
+ " \"http-host\": \"localhost\",\n"
" \"http-port\": 9000,\n"
" \"control-sockets\": {\n"
" \"dhcp4\": {\n"
// Tests if embedded comments are handled correctly.
TEST(ParserTest, embbededComments) {
- string txt = "{ \"Control-agent\": {"
- " \"comment\": \"a comment\","
- " \"http-host\": \"localhost\","
+ string txt = "{ \"Control-agent\": {\n"
+ " \"comment\": \"a comment\",\n"
+ " \"http-host\": \"localhost\",\n"
" \"http-port\": 9000,\n"
" \"control-sockets\": {\n"
" \"dhcp4\": {\n"
TEST(ParserTest, listInList) {
string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
- " [ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
testParser(txt, D2ParserContext::PARSER_JSON);
}
TEST(ParserTest, listsInMaps) {
string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
- "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
testParser(txt, D2ParserContext::PARSER_JSON);
}
TEST(ParserTest, mapsInLists) {
- string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
- " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 }, "
+ "{ \"body\": \"mars\", \"gravity\": 0.376 } ]";
testParser(txt, D2ParserContext::PARSER_JSON);
}
TEST(ParserTest, types) {
- string txt = "{ \"string\": \"foo\","
- "\"integer\": 42,"
- "\"boolean\": true,"
- "\"map\": { \"foo\": \"bar\" },"
- "\"list\": [ 1, 2, 3 ],"
- "\"null\": null }";
+ string txt = "{ \"string\": \"foo\", "
+ "\"integer\": 42, "
+ "\"boolean\": true, "
+ "\"map\": { \"foo\": \"bar\" }, "
+ "\"list\": [ 1, 2, 3 ], "
+ "\"null\": null }";
testParser(txt, D2ParserContext::PARSER_JSON);
}
TEST(ParserTest, keywordJSON) {
- string txt = "{ \"name\": \"user\","
- "\"type\": \"password\","
- "\"user\": \"name\","
- "\"password\": \"type\" }";
+ string txt = "{ \"name\": \"user\", "
+ "\"type\": \"password\", "
+ "\"user\": \"name\", "
+ "\"password\": \"type\" }";
testParser(txt, D2ParserContext::PARSER_JSON);
}
TEST(ParserTest, bashComments) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"ip-address\": \"192.168.77.1\", \n"
- "# this is a comment\n"
- " \"port\": 777, \n "
- " \"ncr-protocol\": \"UDP\", \n"
- "# lots of comments here\n"
- "# and here\n"
- " \"tsig-keys\": [], \n"
- " \"forward-ddns\" : {}, \n"
- " \"reverse-ddns\" : {} \n"
- "} \n"
- "} \n";
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ "# this is a comment\n"
+ " \"port\": 777, \n "
+ " \"ncr-protocol\": \"UDP\", \n"
+ "# lots of comments here\n"
+ "# and here\n"
+ " \"tsig-keys\": [], \n"
+ " \"forward-ddns\" : {}, \n"
+ " \"reverse-ddns\" : {} \n"
+ " } \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
}
TEST(ParserTest, cppComments) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"ip-address\": \"192.168.77.1\", \n"
- " \"port\": 777, // this is a comment \n"
- " \"ncr-protocol\": \"UDP\", // everything after // is ignored\n"
- " \"tsig-keys\": [], // this will be ignored, too\n"
- " \"forward-ddns\" : {}, \n"
- " \"reverse-ddns\" : {} \n"
- "} \n"
- "} \n";
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, // this is a comment \n"
+ " \"ncr-protocol\": \"UDP\", // everything after // is ignored\n"
+ " \"tsig-keys\": [], // this will be ignored, too\n"
+ " \"forward-ddns\" : {}, \n"
+ " \"reverse-ddns\" : {} \n"
+ " } \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
TEST(ParserTest, bashCommentsInline) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"ip-address\": \"192.168.77.1\", \n"
- " \"port\": 777, # this is a comment \n"
- " \"ncr-protocol\": \"UDP\", # everything after # is ignored\n"
- " \"tsig-keys\": [], # this will be ignored, too\n"
- " \"forward-ddns\" : {}, \n"
- " \"reverse-ddns\" : {} \n"
- "} \n"
- "} \n";
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, # this is a comment \n"
+ " \"ncr-protocol\": \"UDP\", # everything after # is ignored\n"
+ " \"tsig-keys\": [], # this will be ignored, too\n"
+ " \"forward-ddns\" : {}, \n"
+ " \"reverse-ddns\" : {} \n"
+ " } \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
TEST(ParserTest, multilineComments) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"ip-address\": \"192.168.77.1\", \n"
- " \"port\": 777, /* this is a C style comment\n"
- "that\n can \n span \n multiple \n lines */ \n"
- " \"ncr-protocol\": \"UDP\", \n"
- " \"tsig-keys\": [], \n"
- " \"forward-ddns\" : {}, \n"
- " \"reverse-ddns\" : {} \n"
- "} \n"
- "} \n";
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, /* this is a C style comment\n"
+ "that\n can \n span \n multiple \n lines */ \n"
+ " \"ncr-protocol\": \"UDP\", \n"
+ " \"tsig-keys\": [], \n"
+ " \"forward-ddns\" : {}, \n"
+ " \"reverse-ddns\" : {} \n"
+ " } \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
TEST(ParserTest, embbededComments) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"comment\": \"a comment\",\n"
- " \"ip-address\": \"192.168.77.1\", \n"
- " \"port\": 777, \n "
- " \"ncr-protocol\": \"UDP\", \n"
- " \"tsig-keys\" : [ { \n"
- " \"name\" : \"d2.md5.key\", \n"
- " \"user-context\" : { \"comment\" : \"indirect\" } } ], \n"
- " \"forward-ddns\" : {}, \n"
- " \"reverse-ddns\" : {}, \n"
- " \"user-context\": { \"compatible\": true }"
- "} \n"
- "} \n";
+ "{ \n"
+ " \"comment\": \"a comment\",\n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, \n "
+ " \"ncr-protocol\": \"UDP\", \n"
+ " \"tsig-keys\" : [ { \n"
+ " \"name\" : \"d2.md5.key\", \n"
+ " \"user-context\" : { \"comment\" : \"indirect\" } } ], \n"
+ " \"forward-ddns\" : {}, \n"
+ " \"reverse-ddns\" : {}, \n"
+ " \"user-context\": { \"compatible\": true }"
+ " } \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
TEST(ParserTest, outputDashOptions) {
string txt =
"{ \"DhcpDdns\" : \n"
- "{ \n"
- " \"loggers\": [ {\n"
- " \"name\": \"kea-dhcp-ddns\",\n"
- " \"output-options\": [ { \"output\": \"stdout\" } ],\n"
- " \"severity\": \"INFO\" } ]\n"
- "} \n"
+ "{ \n"
+ " \"loggers\": [ {\n"
+ " \"name\": \"kea-dhcp-ddns\",\n"
+ " \"output-options\": [ { \"output\": \"stdout\" } ],\n"
+ " \"severity\": \"INFO\" } ]\n"
+ " } \n"
"} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
TEST(ParserTest, listInList) {
string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
- " [ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
testParser(txt, Parser4Context::PARSER_JSON);
}
TEST(ParserTest, listsInMaps) {
string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
- "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
testParser(txt, Parser4Context::PARSER_JSON);
}
TEST(ParserTest, mapsInLists) {
- string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
- " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 }, "
+ "{ \"body\": \"mars\", \"gravity\": 0.376 } ]";
testParser(txt, Parser4Context::PARSER_JSON);
}
TEST(ParserTest, types) {
- string txt = "{ \"string\": \"foo\","
- "\"integer\": 42,"
- "\"boolean\": true,"
- "\"map\": { \"foo\": \"bar\" },"
- "\"list\": [ 1, 2, 3 ],"
- "\"null\": null }";
+ string txt = "{ \"string\": \"foo\", "
+ "\"integer\": 42, "
+ "\"boolean\": true, "
+ "\"map\": { \"foo\": \"bar\" }, "
+ "\"list\": [ 1, 2, 3 ], "
+ "\"null\": null }";
testParser(txt, Parser4Context::PARSER_JSON);
}
TEST(ParserTest, keywordJSON) {
- string txt = "{ \"name\": \"user\","
- "\"type\": \"password\","
- "\"user\": \"name\","
- "\"password\": \"type\" }";
+ string txt = "{ \"name\": \"user\", "
+ "\"type\": \"password\", "
+ "\"user\": \"name\", "
+ "\"password\": \"type\" }";
testParser(txt, Parser4Context::PARSER_JSON);
}
TEST(ParserTest, listInList) {
string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
- " [ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
testParser(txt, Parser6Context::PARSER_JSON);
}
TEST(ParserTest, listsInMaps) {
string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
- "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
testParser(txt, Parser6Context::PARSER_JSON);
}
TEST(ParserTest, mapsInLists) {
- string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
- " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 }, "
+ "{ \"body\": \"mars\", \"gravity\": 0.376 } ]";
testParser(txt, Parser6Context::PARSER_JSON);
}
TEST(ParserTest, types) {
- string txt = "{ \"string\": \"foo\","
- "\"integer\": 42,"
- "\"boolean\": true,"
- "\"map\": { \"foo\": \"bar\" },"
- "\"list\": [ 1, 2, 3 ],"
- "\"null\": null }";
+ string txt = "{ \"string\": \"foo\", "
+ "\"integer\": 42, "
+ "\"boolean\": true, "
+ "\"map\": { \"foo\": \"bar\" }, "
+ "\"list\": [ 1, 2, 3 ], "
+ "\"null\": null }";
testParser(txt, Parser6Context::PARSER_JSON);
}
TEST(ParserTest, keywordJSON) {
- string txt = "{ \"name\": \"user\","
- "\"type\": \"password\","
- "\"user\": \"name\","
- "\"password\": \"type\" }";
+ string txt = "{ \"name\": \"user\", "
+ "\"type\": \"password\", "
+ "\"user\": \"name\", "
+ "\"password\": \"type\" }";
testParser(txt, Parser6Context::PARSER_JSON);
}
TEST(ParserTest, listInList) {
string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
- " [ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, listsInMaps) {
string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
- "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, mapsInLists) {
- string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
- " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 }, "
+ "{ \"body\": \"mars\", \"gravity\": 0.376 } ]";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, types) {
- string txt = "{ \"string\": \"foo\","
- "\"integer\": 42,"
- "\"boolean\": true,"
- "\"map\": { \"foo\": \"bar\" },"
- "\"list\": [ 1, 2, 3 ],"
- "\"null\": null }";
+ string txt = "{ \"string\": \"foo\", "
+ "\"integer\": 42, "
+ "\"boolean\": true, "
+ "\"map\": { \"foo\": \"bar\" }, "
+ "\"list\": [ 1, 2, 3 ], "
+ "\"null\": null }";
testParser(txt, ParserContext::PARSER_JSON);
}
TEST(ParserTest, keywordJSON) {
- string txt = "{ \"name\": \"user\","
- "\"type\": \"password\","
- "\"user\": \"name\","
- "\"password\": \"type\" }";
+ string txt = "{ \"name\": \"user\", "
+ "\"type\": \"password\", "
+ "\"user\": \"name\", "
+ "\"password\": \"type\" }";
testParser(txt, ParserContext::PARSER_JSON);
}