You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.1 KiB

#include "netrunner.h"
#include "CFGFileParser.h"
#ifdef _WIN32
extern "C"{void init_heap();}
#endif
int main(void){
#ifdef _WIN32
init_heap();
#endif
5 years ago
// test vectors
// This is our reference, should always be valid.
5 years ago
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.";
// 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.";
5 years ago
// 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.";
5 years ago
// 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);
5 years ago
CFGFileParser test7(buf7);
CFGFileParser test8(buf8);
CFGFileParser test9(buf9);
CFGFileParser test10(buf10);
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{
5 years ago
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");
}
else{
puts("Test 3 FAILED: see above\n");
}
if (test4.ParseText()){
puts("Test 4 passed.\n");
}
else{
5 years ago
puts("Test 4 FAILED: A stray comment.\n");
}
if (test5.ParseText()){
puts("Test 5 passed.");
}
else{
5 years ago
puts("Test 5 FAILED: Old-style Lynx CFG directive. No longer valid here.\n");
}
if (test6.ParseText()){
puts("Test 6 passed.");
}
else{
5 years ago
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;
}