7 changed files with 108 additions and 6 deletions
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
#include "netrunner.h" |
||||
#include "CFGFileParser.h" |
||||
#ifdef _WIN32 |
||||
extern "C"{void init_heap();} |
||||
#endif |
||||
|
||||
int main(void){ |
||||
#ifdef _WIN32 |
||||
init_heap(); |
||||
#endif |
||||
|
||||
// test vectors
|
||||
// This is our reference, should always be valid.
|
||||
ntr::fast_string buf1 = "# This is a comment.\n.This is a formatting directive.\n# The following is a valid directive:\nHOMEPAGE:[http://motherfuckingwebsite.com]\n# Another comment."; |
||||
|
||||
// Leading number.
|
||||
ntr::fast_string buf2 = "# This is a comment.\n.This is a formatting directive.\n# Not a valid directive:\n4chan:[sometext here]\n# Still another comment."; |
||||
|
||||
// Lowercase letters. Also a valid directive.
|
||||
ntr::fast_string buf3 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ssometext]\n# One more comment."; |
||||
|
||||
// Unescaped comment.
|
||||
ntr::fast_string buf4 = "# A comment.\nUnescaped comment!\n# A valid comment.\n\n# The following directive is untouched, since the parser SHOULD have quit earlier:\nBUGURL:[http://rvx86.net]\n# One final comment."; |
||||
|
||||
// Old-style Lynx directive. Invalid here.
|
||||
ntr::fast_string buf5 = "# This is a comment.\n.This is a formatting directive.\n# The following is a valid directive in Lynx, but not for NetRunner:\nHOMEPAGE:http://motherfuckingwebsite.com\n# Another comment."; |
||||
|
||||
// Invalid leading character.
|
||||
ntr::fast_string buf6 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\n^bad_directive:[ssometext]\n# One more comment."; |
||||
|
||||
// The casts LOOK useless, but they're not.
|
||||
CFGFileParser test1(buf1); |
||||
CFGFileParser test2(buf2); |
||||
CFGFileParser test3(buf3); |
||||
CFGFileParser test4(buf4); |
||||
CFGFileParser test5(buf5); |
||||
CFGFileParser test6(buf6); |
||||
|
||||
puts("CFG Parser Test for /ntr/\n<despair@netrunner.cc>\n"); |
||||
|
||||
if (test1.ParseText()){ |
||||
puts("Test 1 passed. This is the reference string.\n"); |
||||
} |
||||
else{ |
||||
puts("Test 1 FAILED!\n"); |
||||
} |
||||
if (test2.ParseText()){ |
||||
puts("Test 2 passed.\n"); |
||||
} |
||||
else{ |
||||
puts("Test 2 FAILED: see above\nDirectives must not begin with a number.\n"); |
||||
} |
||||
if (test3.ParseText()){ |
||||
puts("Test 3 passed. Mixed-case directives are valid.\n"); |
||||
} |
||||
else{ |
||||
puts("Test 3 FAILED: see above\n"); |
||||
} |
||||
if (test4.ParseText()){ |
||||
puts("Test 4 passed.\n"); |
||||
} |
||||
else{ |
||||
puts("Test 4 FAILED: see above\nA stray comment.\n"); |
||||
} |
||||
if (test5.ParseText()){ |
||||
puts("Test 5 passed."); |
||||
} |
||||
else{ |
||||
puts("Test 5 FAILED: see above\nOld-style Lynx CFG directive. No longer valid here.\n"); |
||||
} |
||||
if (test6.ParseText()){ |
||||
puts("Test 6 passed."); |
||||
} |
||||
else{ |
||||
puts("Test 6 FAILED: see above\nLeading non-alpha symbol\n"); |
||||
} |
||||
return 0; |
||||
} |
Loading…
Reference in new issue