From efe230205f254fc5369b53d3de2841723beb6ff8 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 21 Aug 2026 20:38:39 +0000 Subject: Start work on testing the evaluator FossilOrigin-Name: 530cc9567bc825fd8a7eb21f2ca12dbf7ecbecae3ed02638537dc4a8dca9ae1a --- tests/aplwc_eval.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ tests/aplwc_eval/good/1.txt | 1 + tests/aplwc_eval/good/2.txt | 2 ++ tests/aplwc_eval/good/3.txt | 1 + 4 files changed, 69 insertions(+) create mode 100644 tests/aplwc_eval.c create mode 100644 tests/aplwc_eval/good/1.txt create mode 100644 tests/aplwc_eval/good/2.txt create mode 100644 tests/aplwc_eval/good/3.txt (limited to 'tests') 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 +#include +#include + +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 -- cgit v1.2.3