summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-13 15:32:12 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-13 15:32:12 -0400
commit7bb5ac5863bdb4bc7af04ee18e81657a85aa97f2 (patch)
tree3e0be40e792e403eb7d9f6c0f88c732203757894 /tests
parent45e0055c8bbfa5474fcd7c951428b4ca84b0ed04 (diff)
added where conditions for functions, discovered bug with eval returning
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.sh1
-rw-r--r--tests/where.toc30
-rw-r--r--tests/where_expected1
3 files changed, 32 insertions, 0 deletions
diff --git a/tests/test.sh b/tests/test.sh
index 5b2cb14..31ccb6b 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -8,6 +8,7 @@ foreign
params
nms
varargs
+where
misc'
STARTPWD=$(pwd)
diff --git a/tests/where.toc b/tests/where.toc
new file mode 100644
index 0000000..4223656
--- /dev/null
+++ b/tests/where.toc
@@ -0,0 +1,30 @@
+printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int;
+
+tprintf_valid ::= fn(fmt :: []char, nargs: int) bool {
+ if fmt[fmt.len-1] != '\0' {
+ return false;
+ }
+ count := 0;
+ for x, i := fmt {
+ if x == '%' {
+ if i == fmt.len-1 {
+ count += 1;
+ } elif fmt[i+1] != '%' {
+ count += 1;
+ } else {
+ count -= 1;
+ }
+ }
+ }
+ count == nargs
+};
+
+
+tprintf ::= fn(fmt :: []char, args: ..) where tprintf_valid(fmt, args.len) {
+ f := fmt;
+ printf(&f[0], args);
+};
+
+main ::= fn() {
+ tprintf("%d %d%%\n\0", 3, 4);
+};
diff --git a/tests/where_expected b/tests/where_expected
new file mode 100644
index 0000000..622c000
--- /dev/null
+++ b/tests/where_expected
@@ -0,0 +1 @@
+3 4%