Browse Source

More test cases

master
despair 2 years ago
parent
commit
8c884baf09
1 changed files with 46 additions and 7 deletions
  1. 46
    7
      tests/TestCFG.cpp

+ 46
- 7
tests/TestCFG.cpp View File

@@ -8,10 +8,10 @@ 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.";
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.\nDIRECTIVE2:[sometext]\n\n";
// 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.";
@@ -27,14 +27,29 @@ int main(void){
// Invalid leading character.
ntr::fast_string buf6 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\n^bad_directive:[ssometext]\n# One more comment.";
// Incomplete directive.
ntr::fast_string buf7 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ssometext\n# One more comment.";
// Incomplete directive.
ntr::fast_string buf8 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:ssometext]\n# One more comment.";
// Incomplete directive.
ntr::fast_string buf9 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive [ssometext]\n# One more comment.";
// The casts LOOK useless, but they're not.
// Must have a space
ntr::fast_string buf10 = "# Comment.\n.h2 Perl formatting junk.\n# Another comment.\nbad_directive:[ ]\n# One more comment.";
CFGFileParser test1(buf1);
CFGFileParser test2(buf2);
CFGFileParser test3(buf3);
CFGFileParser test4(buf4);
CFGFileParser test5(buf5);
CFGFileParser test6(buf6);
CFGFileParser test7(buf7);
CFGFileParser test8(buf8);
CFGFileParser test9(buf9);
CFGFileParser test10(buf10);
puts("CFG Parser Test for /ntr/\n<despair@netrunner.cc>\n");
@@ -48,7 +63,7 @@ int main(void){
puts("Test 2 passed.\n");
}
else{
puts("Test 2 FAILED: see above\nDirectives must not begin with a number.\n");
puts("Test 2 FAILED: Directives must not begin with a number.\n");
}
if (test3.ParseText()){
puts("Test 3 passed. Mixed-case directives are valid.\n");
@@ -60,19 +75,43 @@ int main(void){
puts("Test 4 passed.\n");
}
else{
puts("Test 4 FAILED: see above\nA stray comment.\n");
puts("Test 4 FAILED: A 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");
puts("Test 5 FAILED: Old-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");
puts("Test 6 FAILED: Leading non-alpha symbol\n");
}
if (test7.ParseText()){
puts("Test 7 passed.");
}
else{
puts("Test 7 FAILED: Missing terminator\n");
}
if (test8.ParseText()){
puts("Test 8 passed.");
}
else{
puts("Test 8 FAILED: Missing separator\n");
}
if (test9.ParseText()){
puts("Test 9 passed.");
}
else{
puts("Test 9 FAILED: Missing colon separator\n");
}
if (test10.ParseText()){
puts("Test 10 passed. Blank directives MUST have at least one space");
}
else{
puts("Test 10 FAILED: Null directive\n");
}
return 0;
}

Loading…
Cancel
Save