diff --git a/tests/closure.grnd b/tests/closure.grnd index f180a77..b12405b 100644 --- a/tests/closure.grnd +++ b/tests/closure.grnd @@ -1,27 +1,15 @@ set &x 5 -PAUSE - fun !dingle -function -int &a - - PAUSE - fun !capture -int -int &b - - PAUSE - add $a $b &tmp add $tmp $x &tmp return $tmp endfun - return $capture - endfun +set &x 10 call !dingle 3 &result - -PAUSE - call !result 5 &y -println $y +println $y $x \ No newline at end of file diff --git a/tests/drop.grnd b/tests/drop.grnd index f4186d4..6412152 100644 --- a/tests/drop.grnd +++ b/tests/drop.grnd @@ -1,4 +1,4 @@ set &x "dingus" -PAUSE +println $x drop &x -PAUSE +println $x \ No newline at end of file diff --git a/tests/lib.grnd b/tests/lib.grnd new file mode 100644 index 0000000..a10f4e3 --- /dev/null +++ b/tests/lib.grnd @@ -0,0 +1,4 @@ +fun !lib_PrintHello -int + println "Hello" + return 0 +endfun \ No newline at end of file diff --git a/tests/list.grnd b/tests/list.grnd index a9ea3e1..bd3a27f 100644 --- a/tests/list.grnd +++ b/tests/list.grnd @@ -1,5 +1,6 @@ # A cool list -setlist &favWords "hello" "there" "general" "kenobi" +setlist &favWords "hello" "there" "general" +listappend &favWords "kenobi" println $favWords set &count 0 diff --git a/tests/log.txt b/tests/log.txt new file mode 100644 index 0000000..6d2e196 --- /dev/null +++ b/tests/log.txt @@ -0,0 +1,5 @@ +[hello, there, general, hello] +hello +there +general + ,WV diff --git a/tests/pause.grnd b/tests/pause.grnd deleted file mode 100644 index a7faa7b..0000000 --- a/tests/pause.grnd +++ /dev/null @@ -1,11 +0,0 @@ -fun !dingle -int - -endfun - -set &x 5 -set &y "dingle" -PAUSE -println "continuing" -println "step through here" -println "step again" -println "and again" diff --git a/tests/recursivefib.grnd b/tests/recursivefib.grnd index df24554..7866e9b 100644 --- a/tests/recursivefib.grnd +++ b/tests/recursivefib.grnd @@ -18,7 +18,7 @@ fun !fib -int -int &n -function &fib endfun # Main program -println "Computing fib(30) recursively..." -call !fib 30 $fib &answer +println "Computing fib(20) recursively..." +call !fib 20 $fib &answer println "Result:" $answer end diff --git a/tests/string.grnd b/tests/string.grnd index 8e0b4e2..0313a01 100644 --- a/tests/string.grnd +++ b/tests/string.grnd @@ -2,10 +2,10 @@ input &str getstrsize $str &size set &idx 0 @loop -getstrcharat $str $idx &char -println $char -add 1 $idx &idx -equal $idx $size &cond -if $cond %loopend -jump %loop + getstrcharat $str $idx &char + println $char + add 1 $idx &idx + equal $idx $size &cond + if $cond %loopend + jump %loop @loopend diff --git a/tests/unit.sh b/tests/unit.sh new file mode 100755 index 0000000..970b39a --- /dev/null +++ b/tests/unit.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +echo "" > log.txt +for f in *.grnd; do + [ -e "$f" ] || continue # skip if no files match + # Files to skip over + if [[ "$f" == "lib.grnd" ]] || + [[ "$f" == "string.grnd" ]] || + [[ "$f" == "test.grnd" ]] || + [[ "$f" == "to1000.grnd" ]] || + [[ "$f" == "uhoh.grnd" ]]; + then continue + fi + echo "Running $f" + ground "$f" > log.txt + + FILE="log.txt" + FAILED="\033[31mFailed:\n\033[0m" + if [[ "$f" == "closure.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "13 10\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "convs.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "32\n12\n3.140000\na\n97\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "drop.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "dingus\nGround runtime error:\n ErrorType: UnknownVariable\n ErrorInstruction: println \$x\n ErrorLine: 4\n")); + then printf "\033[31mFailed\n\033[0m" + exit 1 + fi + elif [[ "$f" == "error.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "Ground runtime error:\n ErrorType: Hello\n ErrorContext: [1, 2, 3, Hi!]\n ErrorInstruction: error \"Hello\" [1, 2, 3, Hi!] 1\n ErrorLine: 2\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "fib.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "Fibonacci result: 7540113804746346429\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "function.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "dingle\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "list.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "[hello, there, general, kenobi]\nhello\nthere\ngeneral\nkenobi\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "recursivefib.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "Computing fib(20) recursively...\nResult: 6765\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "simple.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "dingus\ndinglefart\n5.840000\n464773025\n5164.120000\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "struct.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "53\n32\n")); + then printf $FAILED + exit 1 + fi + elif [[ "$f" == "use.grnd" ]]; then + if !(cmp -s "$FILE" <(printf "Hello\n")); + then printf $FAILED + exit 1 + fi + else + printf "\033[31mCould not find test case\n\033[0m" + exit 1 + fi +done +printf "\033[32mAll tests passed!\n\033[0m" +exit 0 diff --git a/tests/use.grnd b/tests/use.grnd new file mode 100644 index 0000000..f26cf2e --- /dev/null +++ b/tests/use.grnd @@ -0,0 +1,2 @@ +use "lib" +call !lib_PrintHello &tmp \ No newline at end of file