summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpeter <peter@pmikkelsen.com>2026-08-21 20:38:39 +0000
committerpeter <peter@pmikkelsen.com>2026-08-21 20:38:39 +0000
commitefe230205f254fc5369b53d3de2841723beb6ff8 (patch)
tree39e096bf204f2fc33ba140f44566127985422b0c /tests
parent2d34e3d861e14d58faad68ea5c7d37f1b201addf (diff)
Start work on testing the evaluator
FossilOrigin-Name: 530cc9567bc825fd8a7eb21f2ca12dbf7ecbecae3ed02638537dc4a8dca9ae1a
Diffstat (limited to 'tests')
-rw-r--r--tests/aplwc_eval.c65
-rw-r--r--tests/aplwc_eval/good/1.txt1
-rw-r--r--tests/aplwc_eval/good/2.txt2
-rw-r--r--tests/aplwc_eval/good/3.txt1
4 files changed, 69 insertions, 0 deletions
diff --git a/tests/aplwc_eval.c b/tests/aplwc_eval.c
new file mode 100644
index 0000000..8f6abe0
--- /dev/null
+++ b/tests/aplwc_eval.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <aplwc.h>
+
+int
+main(int argc, char *argv[])
+{
+ uint8_t data[APLWC_MIN_MEM+1000];
+ char *input;
+ struct aplwc *aplwc;
+ struct aplwc_line *line;
+ struct aplwc_value *value;
+ enum aplwc_rc ret;
+ FILE *f;
+ long input_size;
+ long i, j;
+
+ if(argc != 2)
+ return 1;
+
+ f = fopen(argv[1], "r");
+ if(f == NULL)
+ return 1;
+ if(fseek(f, 0, SEEK_END))
+ return 1;
+ input_size = ftell(f);
+ if(input_size < 0)
+ return 1;
+ rewind(f);
+
+ input = malloc(input_size+1);
+ if(input == NULL)
+ return 1;
+ if(fread(input, 1, input_size, f) < (size_t)input_size)
+ return 1;
+ input[input_size] = 0;
+
+ ret = aplwc_new(&aplwc, data, sizeof(data));
+ if(ret)
+ return 1;
+
+ i = j = 0;
+ do{
+ for(i = j; (input[i] != '\n') && (input[i] != 0); i++);
+
+ input[i] = 0;
+ line = aplwc_read(aplwc, &input[j]);
+ if(line == NULL)
+ return 1;
+
+ value = aplwc_eval(line);
+ if((value == NULL) && (aplwc_last_error(aplwc) != APLWC_OUT_OF_MEMORY))
+ return 1;
+
+ aplwc_free_value(value);
+ aplwc_free_line(line);
+
+ j = i+1;
+ }while(j < input_size);
+
+ aplwc_destroy(aplwc);
+ free(input);
+
+ return 0;
+}
diff --git a/tests/aplwc_eval/good/1.txt b/tests/aplwc_eval/good/1.txt
new file mode 100644
index 0000000..190a180
--- /dev/null
+++ b/tests/aplwc_eval/good/1.txt
@@ -0,0 +1 @@
+123
diff --git a/tests/aplwc_eval/good/2.txt b/tests/aplwc_eval/good/2.txt
new file mode 100644
index 0000000..93be7e0
--- /dev/null
+++ b/tests/aplwc_eval/good/2.txt
@@ -0,0 +1,2 @@
+abc←123
+abc
diff --git a/tests/aplwc_eval/good/3.txt b/tests/aplwc_eval/good/3.txt
new file mode 100644
index 0000000..cee2abc
--- /dev/null
+++ b/tests/aplwc_eval/good/3.txt
@@ -0,0 +1 @@
+abc←123 ⋄ abc