From bbb2cb471ee81d6750b1607755b420bc387d6595 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 16 Mar 2022 16:57:37 -0400 Subject: [PATCH] Improve testing. Remove explicit endBlock function. Test some of the new features. --- src/tests.sh | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/tests.sh b/src/tests.sh index 9bb2b74..790239b 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -15,17 +15,19 @@ if [ "$1" == "-val" ]; then VALGRIND=true fi -endBlock() { - echo "" - if (($FAILS != 0)); then - echo -e "$FAIL_OUTPUT" - FAIL_OUTPUT="" - fi - FAILS=0 - DISABLED=false -} - +FIRST_TITLE=true title() { + if ! $FIRST_TITLE; then + echo "" + if (($FAILS != 0)); then + echo -e "$FAIL_OUTPUT" + FAIL_OUTPUT="" + fi + FAILS=0 + DISABLED=false + else + FIRST_TITLE=false + fi echo -n "[$1] " if [[ "$2" == "disable" ]]; then echo -n "DISABLED" @@ -72,7 +74,6 @@ check "StrRetrn" "\"hey\"" "hey" check "SingleStrRetrn" "\"hey\"" "hey" check "HexReturn" "0x0f0f0" "61680" check "BinaryReturn" "0b011010011010011" "13523" -endBlock title "Arithmetic" check "Addition" "(+ 1093 102852)" "103945" @@ -84,7 +85,6 @@ check "ChainDiv" "(/ 1493856 741 96 7)" "3" check "ListAddi" "(+ 5 (1 2 3 (+ 10 10)))" "( 6 7 8 25 )" check "ListModu" "(% 5 (1 2 3 (* 11 11)))" "( 1 2 3 1 )" check "ListsMul" "(* (10 20 30) (1 20 300))" "( 10 400 9000 )" -endBlock title "Comparison" check "GratrThn" "(> 23847123 19375933)" "T" @@ -93,7 +93,6 @@ check "Equality" "(= 987654321 987654321 )" "T" check "StringEquality" "(= \"Bean\" \"Bean\" )" "T" check "StringInequality" "(= \"Beans\" \"Bean\" )" "F" check "NullInequality" "(= \"Beans\" \"\" )" "F" -endBlock title "TypeCheck" check "IsNum" "(isnum 23847123)" "T" @@ -102,14 +101,12 @@ check "IsString" "(isstr \"words\")" "T" check "IsStringEmpty" "(isstr \"\")" "T" check "NumNotString" "(isstr 5)" "F" check "ListNotString" "(isstr (\"hello\"))" "F" -endBlock title "Ifs/Bools" check "IfReturn" "(if (T) 123456789 987654321)" "123456789" check "IfRetTwo" "(if F 123456789 987654321)" "987654321" check "EmptyCnd" "(if () T F)" "F" check "EtyLstLt" "(if (()) T F)" "T" -endBlock title "Lists" check "RegLists" "(1 2 3 4 5)" "( 1 2 3 4 5 )" @@ -124,13 +121,14 @@ check "PrependToList" "(pre (1 20 300 4000 50000) 600000)" "( 600000 1 20 300 40 check "PrepndToEnvList" "(def l (50000 4000 300 20)) (def l (pre l 1)) l" "( 1 50000 4000 300 20 )" check "Rest(Tail)OfList" "(def l (50000 4000 300 20)) (rest l)" "( 4000 300 20 )" check "ListLength" "(def l (1 20 3 \"abc\" \"banana\" (+ 10 5))) (len l)" "6" -endBlock +check "Identifying list" "(islist (1 2 3))" "T" +check "Identifying empty list" "(islist ())" "T" +check "Identifying not a list" "(islist 1)" "F" title "Spacing" check "DenseSpc" "(+1093 102852)" "103945" check "WideSpac" "( + 1093 102852 )" "103945" check "VWidwSpc" " ( + 1093 102852 ) " "103945" -endBlock title "DemoFunctions" check "Squaring" "(sq 9876)" "97535376" @@ -140,7 +138,6 @@ check "MaxRight" "(max 5 20)" "20" check "MaxLeft" "(max 135890 98372)" "135890" check "MinRight" "(min 8429 192449)" "8429" check "MinLeft" "(min 17294722 17294721)" "17294721" -endBlock title "Lambdas" check "MultStmt" "(def yee (fn (a) (* 10 a))) ; (yee 5)" "50" @@ -163,7 +160,6 @@ check "Factorial" "\ (fac 11)" "39916800" check "LambdaClone" "(def y (fn (a) (* 10 a))) (def b y) (def y 12345) ((b 5) y)" "( 50 12345 )" check "Duplicate" "(def dupe (fn (a) (() (a a a))));(dupe (*10 10))" "( 100 100 100 )" -endBlock title "Cat" check "ExplicitCat" "(cat \"Big\" \" Kitty\")" "Big Kitty" @@ -171,19 +167,26 @@ check "CatNums" "(cat \"There are \" (+ 2 3) \" kitties\")" "There are 5 kitties check "ImplicitCat" "(+ \"There are \" (* 5 4) \" bonks\")" "There are 20 bonks" # Mixing of `+` and implicit cat currently expected but not recommended: check "CatAssocLeft" "(+ 10 20 \" rascals\")" "30 rascals" -endBlock title "Filtering" check "Filtering" "(fil (< 321) (30 300 90 1200 135 801))" "( 1200 801 )" check "FilterEval" "(fil (= 1000) ((+ 450 550) (* 20 50) (/ 30 3) (- 10000 100)))" "( 1000 1000 )" check "MapFilter" "(fil (< 50) (map sq (1 2 3 4 5 6 7 8 9 10 11 12)))" "( 64 81 100 121 144 )" -endBlock + +title "Structs" +check "StructDef" "(struct Post (title body))" "T" +check "Building a struct"\ + '(struct Post (title body)) (Post "A title" "The Body")'\ + '{ title: "A title", body: "The Body" }' +check "Accessing struct fields"\ + "(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p's title p's body)"\ + "( TITLE BODY )" title "HigherOrder" +check "Simple reducing" '(reduce ((1 2 3) 0) +)' '6' check "FuncReturningAFunc" "(def plusser (fn (outer) (fn (inner) (+ outer inner))))\ (def plusFive (plusser 5))\ (plusFive 10)" "15" -endBlock title "ShouldError" check "LenOfNotList" "(len 5)" "NOT_A_LIST" @@ -202,24 +205,20 @@ check "BadParens4" ")))hey" \ "'MISMATCHED_PARENS': (loadfile \"examples/lib.pbl\") )))hey" check "BadParens5" "hey))(" \ "'MISMATCHED_PARENS': (loadfile \"examples/lib.pbl\") hey))(" -endBlock title "Eval" check "BasicNumberEval" "(eval \"5\")" "5" check "BasicOpEval" "(eval \"(+ 5 10)\")" "15" check "MapFilter" "(eval \"(fil (< 50) (map sq (1 2 3 4 5 6 7 8 9 10 11 12)))\")" "( 64 81 100 121 144 )" -endBlock title "Forbble" disable check "BasicForbbleOp" "(loadfile \"examples/forbble.pbl\") (feval (10 10 * .)) \"\"" "100" check "FibForbble" "(loadfile \"examples/forbble.pbl\") (feval (1 1 _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f .)) \"\"" "28657" check "ForbbleDefine" "(loadfile \"examples/forbble.pbl\") (feval ( : \"cubed\" dup dup * * $ )) (feval (4 cubed .)) \"\"" "64" -endBlock title "Environment" check "EnvStressTestEarly" "(def a 1)(def b 20)(def c \"yee\")(def d \"yeehunnid\")(def e 3) (a)" "( 1 )" check "EnvStressTestLate" "(def a 1)(def b 2)(def c 3)(def d 4)(def e 5)(def g 6)(def n 40) n" "40" -endBlock echo ""