diff options
author | JSDurand <mmemmew@gmail.com> | 2023-07-16 18:06:18 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-07-16 18:06:18 +0800 |
commit | 780f3cc80cadf87ecfdb702ef90fcb606f2783fd (patch) | |
tree | 7d978d43b1c6f58c358e6f8e8d9f30c0303a7a98 /src/test.c | |
parent | 6a24e0a805c597b8f835c5c72a0e4dcdd64ca39b (diff) |
Fix the bug of forgetting to check cloned nodes.
In the process of splitting, cloning, and planting the forest, I
forgot to check whether some cloned node of the node inquestion
satisfy the condition. This used to cause forests that violate some
fundamental assumptions. Now this is supposed to be fixed, but more
tests await us.
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -19,7 +19,24 @@ main(int argc, char **argv) error_vec.len = error_vec_len; error_vec.capacity = error_vec_cap; - struct parser *parser = new_parser("start = \"a\"\"b\"\n", &error_vec); + char *grammar_string = "document = 1*( item )\n" +"\n" +"item = header [ price ] *1( note )\n" +"\n" +"header = *1star \"SP\" title %xA *( \"SP\" / %xA )\n" +"\n" +"title = 1*\"TEXT\"\n" +"\n" +"star = %x2A\n" +"\n" +"note = \"note:\" note-content %xA *( \"SP\" / %xA )\n" +"\n" +"note-content = 1*\"TEXT\"\n" +"\n" +"price = \"price:\" \"SP\" 1*\"DIGIT\" %xA *( \"SP\" / %xA )\n"; + + struct parser *parser = new_parser(grammar_string, &error_vec); + /* struct parser *parser = new_parser("start = \"a\"\"b\"\n", &error_vec); */ uint64_t error_length = from_big_endian(error_vec.len); @@ -39,7 +56,7 @@ main(int argc, char **argv) return 1; } - unsigned char *input = malloc (sizeof(unsigned char) * 16); + unsigned char *input = malloc (sizeof(unsigned char) * 10 * 8); if (input == NULL) { clean_parser(parser); @@ -49,14 +66,16 @@ main(int argc, char **argv) return EXIT_FAILURE; } - for (int i = 0; i < 16; i++) *(input+i) = 0; + int input_unenc[10] = { 3, 0, 2, 2, 2, 1, 1, 1, 0, 1 }; - *(input+15) = 1; + for (int i = 0; i < 10; i++) + to_big_endian(input_unenc[i], input + (8 * i)); unsigned char input_len[8] = { 0 }; - input_len[7] = 16; + input_len[7] = 8*2; - struct UnsignedVec input_vec = (struct UnsignedVec) { input_len, NULL, input }; + struct UnsignedVec input_vec = + (struct UnsignedVec) { input_len, NULL, input }; int result = parser_recognize (parser, |