aboutsummaryrefslogtreecommitdiff
path: root/tests/builtins.sh
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-01 03:22:10 -0500
committerMustafa Quraish <[email protected]>2022-02-01 03:22:10 -0500
commit7aab3bded245de89a8bab23847f074e3b2572c5a (patch)
treeab915eae99832d1717edecc228825eaf7c849c8a /tests/builtins.sh
parentGlobal variables now supported! + some fixes to OP_ASSIGN (diff)
downloadcup-7aab3bded245de89a8bab23847f074e3b2572c5a.tar.xz
cup-7aab3bded245de89a8bab23847f074e3b2572c5a.zip
Testing: Add support for testing stdout results, check builtins
Diffstat (limited to 'tests/builtins.sh')
-rwxr-xr-xtests/builtins.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/builtins.sh b/tests/builtins.sh
new file mode 100755
index 0000000..c37cc2e
--- /dev/null
+++ b/tests/builtins.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+# Test Builtin functions
+
+. tests/common.sh
+
+set -e
+
+echo -n "- Print: "
+assert_stdout_text \
+"fn main() {
+ print(10); print(20);
+}" \
+"10
+20"
+
+assert_stdout_text \
+"fn test(a: int) {
+ print(100*a);
+}
+fn main() {
+ test(10);
+}" \
+"1000"
+
+# We don't print negative values yet, need to fix this
+assert_stdout_text \
+"fn main() {
+ print(-1);
+}" \
+"18446744073709551615"
+
+echo " OK"
+
+echo -n "- putc: "
+assert_stdout_text \
+"fn main() {
+ putc(65);
+}" \
+"A"
+
+assert_stdout_text \
+"fn main(a: int) {
+ let i: int = 65;
+ for (; i < 65 + 26; i = i + 1)
+ putc(i);
+}" \
+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+assert_stdout_text \
+"fn main() {
+ putc(72);
+ putc(101);
+ putc(108);
+ putc(108);
+ putc(111);
+ putc(44);
+ putc(32);
+ putc(87);
+ putc(111);
+ putc(114);
+ putc(108);
+ putc(100);
+ putc(33);
+}" \
+"Hello, World!"
+
+echo " OK" \ No newline at end of file