Improved testing. Added `spent` and '"' to pebble
Tests automatically run on `make`. Removed breaking cleanObject() in parseEval()
This commit is contained in:
parent
d83fa29bb4
commit
263af226b7
|
@ -1,11 +1,11 @@
|
||||||
all:
|
all:
|
||||||
gcc -g -O0 -o pebblisp -D STANDALONE pebblisp.c tokens.c object.c
|
gcc -g -O0 -o pebblisp -D STANDALONE pebblisp.c tokens.c object.c && ./tests.sh
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
gcc -g -O0 -o pebblisp -D STANDALONE -D DEBUG pebblisp.c tokens.c object.c
|
gcc -g -O0 -o pebblisp -D STANDALONE -D DEBUG pebblisp.c tokens.c object.c && ./tests.sh
|
||||||
|
|
||||||
phrase:
|
phrase:
|
||||||
gcc -g -O0 -o pebblisp -D STANDALONE -D DEBUG -D NO_REPL pebblisp.c tokens.c object.c
|
gcc -g -O0 -o pebblisp -D STANDALONE -D DEBUG -D NO_REPL pebblisp.c tokens.c object.c && ./tests.sh
|
||||||
|
|
||||||
run:
|
run:
|
||||||
./pebblisp
|
./pebblisp
|
||||||
|
|
|
@ -43,6 +43,8 @@ char *tokens[] = {
|
||||||
"7","8","9", "0",
|
"7","8","9", "0",
|
||||||
"a", "b", "c", "d", "e",
|
"a", "b", "c", "d", "e",
|
||||||
"= ", "< ", "> ",
|
"= ", "< ", "> ",
|
||||||
|
"spent",
|
||||||
|
"\"",
|
||||||
"map", "fn", "def", "if", "\n",
|
"map", "fn", "def", "if", "\n",
|
||||||
END_PHRASE
|
END_PHRASE
|
||||||
};
|
};
|
||||||
|
|
|
@ -490,3 +490,9 @@ inline Object errorObject(enum errorCode err)
|
||||||
o.err = err;
|
o.err = err;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Object toBool(const Object test)
|
||||||
|
{
|
||||||
|
if(test.number == 0)
|
||||||
|
return boolObject(0);
|
||||||
|
}
|
||||||
|
|
|
@ -231,8 +231,8 @@ void eval_forms(Object *destList, const Object *src, struct Environment *env)
|
||||||
|
|
||||||
Object eval(const Object *obj, struct Environment *env)
|
Object eval(const Object *obj, struct Environment *env)
|
||||||
{
|
{
|
||||||
printd("eval():\n");
|
// printf("eval():\n");
|
||||||
debugObj(obj);
|
// printObj(obj);
|
||||||
switch(obj->type) {
|
switch(obj->type) {
|
||||||
case TYPE_NUMBER:
|
case TYPE_NUMBER:
|
||||||
case TYPE_BOOL:
|
case TYPE_BOOL:
|
||||||
|
@ -284,6 +284,7 @@ Object eval(const Object *obj, struct Environment *env)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// printf("Return list as passed");
|
||||||
return *obj;
|
return *obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,8 +495,7 @@ struct Environment defaultEnv() {
|
||||||
(cat \"Tip: $\" (/ a 5) \".\" \
|
(cat \"Tip: $\" (/ a 5) \".\" \
|
||||||
(/ (* 100 (% a 5)) 5) \
|
(/ (* 100 (% a 5)) 5) \
|
||||||
) \
|
) \
|
||||||
))",
|
))", &e);
|
||||||
&e);
|
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -518,9 +518,7 @@ Object parseEval(const char *input, struct Environment *env)
|
||||||
#endif
|
#endif
|
||||||
Object parsed = parse(tokens).obj;
|
Object parsed = parse(tokens).obj;
|
||||||
free(tokens);
|
free(tokens);
|
||||||
Object ret = eval(&parsed, env);
|
return eval(&parsed, env);
|
||||||
cleanObject(&parsed);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
|
@ -531,8 +529,8 @@ int repl(struct Environment *env)
|
||||||
printf("pebblisp>> ");
|
printf("pebblisp>> ");
|
||||||
fgets(input, 100, stdin);
|
fgets(input, 100, stdin);
|
||||||
Object obj = parseEval(input, env);
|
Object obj = parseEval(input, env);
|
||||||
// printAndClean(&obj);
|
printAndClean(&obj);
|
||||||
printObj(&obj);
|
// printObj(&obj);
|
||||||
// printEnv(env);
|
// printEnv(env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/tests.sh
35
src/tests.sh
|
@ -3,12 +3,12 @@ PASSES=0
|
||||||
FAILS=0
|
FAILS=0
|
||||||
|
|
||||||
pass() {
|
pass() {
|
||||||
echo "$1 test PASSED"
|
echo "[0;32m$1 test PASSED[0m"
|
||||||
((PASSES++))
|
((PASSES++))
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
echo "$1 test FAILED"
|
echo "[1;31m$1 test FAILED[0m"
|
||||||
((FAILS++))
|
((FAILS++))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,28 +18,49 @@ check() {
|
||||||
pass $1
|
pass $1
|
||||||
else
|
else
|
||||||
fail $1
|
fail $1
|
||||||
|
echo " Expected '$3' but received '$output'"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check "PlainRet" "5" "5"
|
||||||
|
echo ""
|
||||||
check "Addition" "(+ 1093 102852)" "103945"
|
check "Addition" "(+ 1093 102852)" "103945"
|
||||||
check "Multiply" "(* 1000 10000)" "10000000"
|
check "Multiply" "(*1000 10000)" "10000000"
|
||||||
check "Division" "(/ 6418425 65)" "98745"
|
check "Division" "(/ 6418425 65)" "98745"
|
||||||
echo ""
|
echo ""
|
||||||
check "ChainAdd" "(+ 3917 17304 1293844 400 100000)" "1415465"
|
check "ChainAdd" "(+ 3917 17304 1293844 400 100000)" "1415465"
|
||||||
check "ChainMul" "(* 8263 23 123)" "23376027"
|
check "ChainMul" "(* 8263 23 123)" "23376027"
|
||||||
check "ChainDiv" "(/ 1493856 741 96 7)" "3"
|
check "ChainDiv" "(/ 1493856 741 96 7)" "3"
|
||||||
echo ""
|
echo ""
|
||||||
|
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 )"
|
||||||
|
echo ""
|
||||||
check "GratrThn" "(> 23847123 19375933)" "T"
|
check "GratrThn" "(> 23847123 19375933)" "T"
|
||||||
check "LessThan" "(< 23847123 19375933)" "F"
|
check "LessThan" "(< 23847123 19375933)" "F"
|
||||||
check "Equality" "(= 987654321 987654321 )" "T"
|
check "Equality" "(= 987654321 987654321 )" "T"
|
||||||
echo ""
|
echo ""
|
||||||
check "IfReturn" "(if (T) 123456789 987654321)" "123456789"
|
check "IfReturn" "(if (T) 123456789 987654321)" "123456789"
|
||||||
check "IfRetTwo" "(if F 123456789 987654321)" "987654321"
|
check "IfRetTwo" "(if F 123456789 987654321)" "987654321"
|
||||||
check "IfRetTwo" "(if () 123456789 987654321)" "987654321"
|
check "EmptyCnd" "(if () T F)" "F"
|
||||||
# check "IfRetTwo" "(if (()) 123456789 987654321)" "123456789"
|
# check "EtyLstLt" "(if (()) T F)" "T"
|
||||||
echo ""
|
echo ""
|
||||||
check "RegLists" "(1 2 3 4 5)" "( 1 2 3 4 5 )"
|
check "RegLists" "(1 2 3 4 5)" "( 1 2 3 4 5 )"
|
||||||
|
check "EmptyLst" "()" "( )"
|
||||||
|
check "EmptLst2" "( )" "( )"
|
||||||
|
echo ""
|
||||||
|
check "DenseSpc" "(+1093 102852)" "103945"
|
||||||
|
check "WideSpac" "( + 1093 102852 )" "103945"
|
||||||
|
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
||||||
|
echo ""
|
||||||
|
check "DemoFunc" "(spent 68)" "Tip: \$13.60"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "$PASSES Tests Passed"
|
|
||||||
echo "$FAILS Tests Failed"
|
if [ "$FAILS" -ne "0" ]; then
|
||||||
|
echo "[1;31m$FAILS Tests Failed[0m"
|
||||||
|
else
|
||||||
|
echo "$FAILS Tests Failed[0m"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[1;32m$PASSES Tests Passed[0m"
|
||||||
|
|
Loading…
Reference in New Issue