Adjust test formatting.

Replace plfunc.h comments with simple type hints.
This commit is contained in:
Sage Vaillancourt 2022-03-24 23:32:51 -04:00
parent 3398729ab8
commit 62e430af69
3 changed files with 54 additions and 32 deletions

View File

@ -332,7 +332,7 @@ fnn(segfault, "seg", "Induces a segfault.")
// Returns number of failures // Returns number of failures
int runTests() int runTests()
{ {
printf("Running tests...\n"); printf("::NATIVE TESTS::\n");
int failureCount = 0; int failureCount = 0;
int passCount = 0; int passCount = 0;
for (int hi = 0; hi < currentHelp; hi++) { for (int hi = 0; hi < currentHelp; hi++) {

View File

@ -28,33 +28,39 @@ BASIC_OP(or);
#undef BASIC_OP #undef BASIC_OP
/// ANY => STRING
fn(catObjects, fn(catObjects,
"Concatenate string versions of the given objects.", "Concatenate string versions of the given objects.",
"(cat \"Stuff: \" (1 2 3))", "Stuff: ( 1 2 3 )", "(cat \"Stuff: \" (1 2 3))", "Stuff: ( 1 2 3 )",
); // (Object obj1, Object obj2, struct Environment* env); );
/// FUNCY, LIST => LIST
fn(filter, fn(filter,
"Filter a list based on the given condition.", "Filter a list based on the given condition.",
"(fil (fn (a) (< 50 a)) (25 60 100))", "( 60 100 )", "(fil (fn (a) (< 50 a)) (25 60 100))", "( 60 100 )",
); // (Object condition, Object list, struct Environment* env); );
/// LIST, ANY => LIST
fn(append, fn(append,
"Append the given element. Creates a new list.", "Append the given element. Creates a new list.",
"(ap (1 2) 3)", "( 1 2 3 )", "(ap (1 2) 3)", "( 1 2 3 )",
); // (Object list, Object newElement, struct Environment* env); );
/// LIST, ANY => LIST
fn(prepend, fn(prepend,
"Prepend the given element. Creates a new list", "Prepend the given element. Creates a new list",
"(pre (2 3) 1)", "( 1 2 3 )", "(pre (2 3) 1)", "( 1 2 3 )",
); // (Object list, Object newElement, struct Environment* env); );
/// LIST => NUMBER
fn(len, fn(len,
"Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.", "Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.",
"(len (2 3))", "2", "(len (2 3))", "2",
"(len ())", "0", "(len ())", "0",
"(len \"string\")", "NOT_A_LIST", "(len \"string\")", "NOT_A_LIST",
); // (Object obj1, Object o_ignore, struct Environment* e_ignore); );
/// LIST, FUNCY, ANY => ANY
fn(reduce, fn(reduce,
"Performs a simple reduction. Does not currently work with lambdas.\n" "Performs a simple reduction. Does not currently work with lambdas.\n"
"Takes three arguments:\n" "Takes three arguments:\n"
@ -63,99 +69,107 @@ fn(reduce,
" - An initial value", " - An initial value",
"(reduce 5 + 6)", "11", "(reduce 5 + 6)", "11",
"(reduce (1 2 3) + 0)", "6", "(reduce (1 2 3) + 0)", "6",
); // (Object listInitial, Object func, struct Environment* env); );
/// NUMBER, LIST => ANY
fn(at, fn(at,
"Get item at the given index in the given list.", "Get item at the given index in the given list.",
"(at 1 (1 2 3))", "2", "(at 1 (1 2 3))", "2",
"(at 99 (1 2 3))", "INDEX_PAST_END", "(at 99 (1 2 3))", "INDEX_PAST_END",
"(at 99 \"string\")", "INDEX_PAST_END", "(at 99 \"string\")", "INDEX_PAST_END",
); // (Object index, Object list, struct Environment* env); );
/// LIST => LIST
fn(rest, fn(rest,
"Get the tail of a list. All but the first element.", "Get the tail of a list. All but the first element.",
"(rest (1 2 3))", "( 2 3 )", "(rest (1 2 3))", "( 2 3 )",
"(rest ())", "( )", "(rest ())", "( )",
"(rest \"string\")", "( )", "(rest \"string\")", "( )",
); // (Object list, Object ignore, struct Environment* env); );
/// LIST => LIST
fn(reverse, fn(reverse,
"Reverse a list.", "Reverse a list.",
"(rev (1 2 3))", "( 3 2 1 )", "(rev (1 2 3))", "( 3 2 1 )",
"(rev \"string\")", "NOT_A_LIST", "(rev \"string\")", "NOT_A_LIST",
); // (Object _list, Object ignore, struct Environment* ignore2); );
/// ANY => BOOL
fn(isNum, fn(isNum,
"Returns `T` only if the argument evaluates to a number.", "Returns `T` only if the argument evaluates to a number.",
"(isnum 1)", "T", "(isnum 1)", "T",
"(isnum (+ 5 5))", "T", "(isnum (+ 5 5))", "T",
"(isnum '(+ 5 5))", "F", "(isnum '(+ 5 5))", "F",
"(isnum \"Hello\")", "F", "(isnum \"Hello\")", "F",
); // (Object test, Object ignore, struct Environment* ignore2); );
/// ANY => BOOL
fn(isList, fn(isList,
"Returns `T` only if the argument is a list.", "Returns `T` only if the argument is a list.",
"(islist (1 2 3))", "T", "(islist (1 2 3))", "T",
"(islist ())", "T", "(islist ())", "T",
"(islist \"Stringy\")", "F", "(islist \"Stringy\")", "F",
); // (Object test, Object ignore, struct Environment* ignore2); );
/// ANY => BOOL
fn(isString, fn(isString,
"Returns `T` only if the argument is a string.", "Returns `T` only if the argument is a string.",
"(isstr \"Heyo\")", "T", "(isstr \"Heyo\")", "T",
"(isstr \"\")", "T", "(isstr \"\")", "T",
"(isstr (cat 5 5))", "T", "(isstr (cat 5 5))", "T",
"(isstr 10)", "F", "(isstr 10)", "F",
); // (Object test, Object ignore, struct Environment* ignore2); );
/// ANY => BOOL
fn(isErr, fn(isErr,
"Check if the argument is an error.", "Check if the argument is an error.",
"(iserr (at 10 ()))", "T", "(iserr (at 10 ()))", "T",
"(iserr 5)", "F", "(iserr 5)", "F",
); // (Object test, Object ignore, struct Environment* ignore2); );
/// STRING => STRING
fn(charAt, fn(charAt,
"Get the char in the given string at the given index.", "Get the char in the given string at the given index.",
"(chat \"Hello\" 1)", "e", "(chat \"Hello\" 1)", "e",
"(chat \"Hello\" 10)", "", "(chat \"Hello\" 10)", "",
); // (Object string, Object at, struct Environment* ignore); );
/// STRING => NUMBER
fn(charVal, fn(charVal,
"Get the ascii integer representaton of the given character.", "Get the ascii integer representaton of the given character.",
"(char \"h\")", "104", "(char \"h\")", "104",
"(char \"hello\")", "104", "(char \"hello\")", "104",
"(char \"\")", "0", "(char \"\")", "0",
); // (Object test, Object ignore, struct Environment* ignore2); );
/// STRING/SLIST => ANY
fn(parseEvalO, fn(parseEvalO,
"Evaluate the given string or quoted list.", "Evaluate the given string or quoted list.",
"(eval \"(1 2 3)\")", "( 1 2 3 )", "(eval \"(1 2 3)\")", "( 1 2 3 )",
"(eval '(+ 5 5))", "10", "(eval '(+ 5 5))", "10",
); // (Object text, Object ignore, struct Environment* env); );
/// STRUCT, STRING => ANY
fn(possessive, fn(possessive,
"(struct Post (title body))\n" "(struct Post (title body))\n"
"(def p (Post \"TI\" \"BO\"))\n" "(def p (Post \"TI\" \"BO\"))\n"
"p's title => TI" "p's title => TI"
); // (Object structo, Object field, struct Environment* env); );
#ifdef STANDALONE #ifdef STANDALONE
fn(print, "Prints the string representation of the given object to stdout."); fn(print, "Prints the string representation of the given object to stdout.");
//(Object p, Object ignore, struct Environment* ignore2);
fn(pChar, "Prints the ascii character for the given number value."); fn(pChar, "Prints the ascii character for the given number value.");
//(Object c, Object i1, struct Environment* i2);
fn(printEnvO, "Prints out the current scoped environment."); fn(printEnvO, "Prints out the current scoped environment.");
//(Object i1, Object i2, struct Environment* env);
fn(systemCall, fn(systemCall,
"Opens a shell and runs the given command, returning the command's exit code.\n" "Opens a shell and runs the given command, returning the command's exit code.\n"
"(sys \"echo yee\")\n" "(sys \"echo yee\")\n"
"yee\n" "yee\n"
"=> 0" "=> 0"
); // (Object process, Object _, struct Environment* env); );
fn(loadFile, fn(loadFile,
"Loads and parses the given file.\n" "Loads and parses the given file.\n"
@ -163,24 +177,31 @@ fn(loadFile,
"(loadfile \"printdate.pl\")\n" "(loadfile \"printdate.pl\")\n"
"Mon 21 Mar 2022 10:35:03 AM EDT\n" "Mon 21 Mar 2022 10:35:03 AM EDT\n"
"=> 0" "=> 0"
); // (Object filename, Object _, struct Environment* env); );
/// @code
/// () => STRING
/// STRING => STRING
fn(takeInput, fn(takeInput,
"Take console input with an optional prompt. For example:\n" "Take console input with an optional prompt. For example:\n"
"`(def x (input))` will wait for user input with no prompt.\n" "`(def x (input))` will wait for user input with no prompt.\n"
"`(def x (input \">> \"))` wait for input, but prompt the user with '>> '.\n" "`(def x (input \">> \"))` wait for input, but prompt the user with '>> '.\n"
); // (Object i1, Object i2, struct Environment* i3); );
/// STRING => STRING
fn(help, fn(help,
"Displays help text for the given function.\n" "Displays help text for the given function.\n"
"Currently requires the function name as a string, but future syntactic sugar may\n" "Currently requires the function name as a string, but future syntactic sugar may\n"
"loosen this requirement.\n" "loosen this requirement.\n"
"(? \"+\") => \"(+ 1 2) => 3\"" "(? \"+\") => \"(+ 1 2) => 3\""
); // (Object symbol, Object ignore, struct Environment* ignore2); );
/// STRING => STRING
fn(readFileToObject, fn(readFileToObject,
"Read a file into a string object." "Read a file into a string object."
); // (Object filename, Object ignore, struct Environment* ignore2); );
#endif // STANDALONE #endif // STANDALONE

View File

@ -77,7 +77,7 @@ check() {
FAIL_OUTPUT="${FAIL_OUTPUT}\n  expected '$3' but received '$output'\n" FAIL_OUTPUT="${FAIL_OUTPUT}\n  expected '$3' but received '$output'\n"
} }
echo "STARTING TESTS" echo "::SHELL TESTS::"
title "Plain returns" title "Plain returns"
check "PlainRet" "10" "10" check "PlainRet" "10" "10"
@ -239,15 +239,16 @@ for c in {0..50}; do hard_test_string="(def a$c 1)$hard_test_string"; done
check "HardEnvStressTest" "$hard_test_string n" "1000" check "HardEnvStressTest" "$hard_test_string n" "1000"
echo "" echo ""
echo ""
if [ "$TOTAL_FAILS" -ne "0" ]; then
echo -n ""
fi
echo "$TOTAL_FAILS Tests Failed"
if [ "$TOTAL_PASSES" -ne "0" ]; then if [ "$TOTAL_PASSES" -ne "0" ]; then
echo -n "" echo -n ""
fi fi
echo "$TOTAL_PASSES Tests Passed" echo "$TOTAL_PASSES Tests Passed"
if [ "$TOTAL_FAILS" -ne "0" ]; then
echo -n ""
fi
echo "$TOTAL_FAILS Tests Failed"
echo "" echo ""