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
int runTests()
{
printf("Running tests...\n");
printf("::NATIVE TESTS::\n");
int failureCount = 0;
int passCount = 0;
for (int hi = 0; hi < currentHelp; hi++) {

View File

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

View File

@ -77,7 +77,7 @@ check() {
FAIL_OUTPUT="${FAIL_OUTPUT}\n  expected '$3' but received '$output'\n"
}
echo "STARTING TESTS"
echo "::SHELL TESTS::"
title "Plain returns"
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"
echo ""
if [ "$TOTAL_FAILS" -ne "0" ]; then
echo -n ""
fi
echo "$TOTAL_FAILS Tests Failed"
echo ""
if [ "$TOTAL_PASSES" -ne "0" ]; then
echo -n ""
fi
echo "$TOTAL_PASSES Tests Passed"
if [ "$TOTAL_FAILS" -ne "0" ]; then
echo -n ""
fi
echo "$TOTAL_FAILS Tests Failed"
echo ""