From b86284cba09843ccccba6d037c858da1208ae97a Mon Sep 17 00:00:00 2001 From: Ian Piumarta Date: Wed, 22 Mar 2023 18:44:19 +0900 Subject: [PATCH] Add parsimony tests. --- tests/parsimony/001 | 7 +++++++ tests/parsimony/001.c | 19 +++++++++++++++++++ tests/parsimony/002 | 6 ++++++ tests/parsimony/002.c | 17 +++++++++++++++++ tests/parsimony/003 | 6 ++++++ tests/parsimony/003.c | 35 +++++++++++++++++++++++++++++++++++ tests/parsimony/004 | 8 ++++++++ tests/parsimony/004.c | 18 ++++++++++++++++++ tests/parsimony/005 | 5 +++++ tests/parsimony/005.c | 22 ++++++++++++++++++++++ tests/parsimony/006 | 12 ++++++++++++ tests/parsimony/006.c | 36 ++++++++++++++++++++++++++++++++++++ tests/parsimony/007 | 3 +++ tests/parsimony/007.c | 16 ++++++++++++++++ tests/parsimony/008 | 1 + tests/parsimony/008.c | 6 ++++++ tests/parsimony/009 | 8 ++++++++ tests/parsimony/009.c | 15 +++++++++++++++ tests/parsimony/map | 8 ++++++++ tests/parsimony/map.c | 20 ++++++++++++++++++++ 20 files changed, 268 insertions(+) create mode 100644 tests/parsimony/001 create mode 100644 tests/parsimony/001.c create mode 100644 tests/parsimony/002 create mode 100644 tests/parsimony/002.c create mode 100644 tests/parsimony/003 create mode 100644 tests/parsimony/003.c create mode 100644 tests/parsimony/004 create mode 100644 tests/parsimony/004.c create mode 100644 tests/parsimony/005 create mode 100644 tests/parsimony/005.c create mode 100644 tests/parsimony/006 create mode 100644 tests/parsimony/006.c create mode 100644 tests/parsimony/007 create mode 100644 tests/parsimony/007.c create mode 100644 tests/parsimony/008 create mode 100644 tests/parsimony/008.c create mode 100644 tests/parsimony/009 create mode 100644 tests/parsimony/009.c create mode 100644 tests/parsimony/map create mode 100644 tests/parsimony/map.c diff --git a/tests/parsimony/001 b/tests/parsimony/001 new file mode 100644 index 0000000..8cf8ff2 --- /dev/null +++ b/tests/parsimony/001 @@ -0,0 +1,7 @@ +enum foo { FOO, BAR, BAZ }; + +char *x[] = {"X","Y","Z"}; +int i = 42; +char *c = "42"; +int i = 14; +char *foos[] = { "FOO", "BAR", "BAZ" }; diff --git a/tests/parsimony/001.c b/tests/parsimony/001.c new file mode 100644 index 0000000..18279dc --- /dev/null +++ b/tests/parsimony/001.c @@ -0,0 +1,19 @@ +@{ + newObject(type, fields) { fields.__proto__ = type; fields } + newCint(text) { newObject(C_int, { text: text }) } + newCstring(text) { newObject(C_stringLiteral, { text: "\""+text+"\"" }) } + newCinitializer(list) { { __proto__: C_initializer, leftCurly: lcurly, initList: list, rightCurly: rcurly } } + newToken(text) { { __proto__: Token, text: text } } + comma = newToken(","); + lcurly = newToken("{"); + rcurly = newToken("}"); + nil; +} + +enum foo { FOO, BAR, BAZ }; + +char *x[] = @(newCinitializer([newCstring("X"), comma, newCstring("Y"), comma, newCstring("Z")])); +int i = @(newCint("42")); +char *c = @(newCstring("42")); +int i = @({ __proto__: Token, text: "14" }); +char *foos[] = { "FOO", "BAR", "BAZ" }; diff --git a/tests/parsimony/002 b/tests/parsimony/002 new file mode 100644 index 0000000..3d62b8c --- /dev/null +++ b/tests/parsimony/002 @@ -0,0 +1,6 @@ +char t = 10; +int i = 2; +int q = 10; +int k = (1,2,"stringy thingy",21<<1); +int i = (1,2,"string",21<<1); +int w = 10; diff --git a/tests/parsimony/002.c b/tests/parsimony/002.c new file mode 100644 index 0000000..3345312 --- /dev/null +++ b/tests/parsimony/002.c @@ -0,0 +1,17 @@ +@{ + saved = `expression (1,2,"string",21<<1); + first = `constant 2; + nil; +} + +@{ + second = `constant 10; + nil; +} + +char t = @(`constant @second); +int i = @first; +int q = @(`constant 10); +int k = @(`expression (1,2,"stringy thingy",21<<1)); +int i = @saved; +int w = @second; diff --git a/tests/parsimony/003 b/tests/parsimony/003 new file mode 100644 index 0000000..ec2aa78 --- /dev/null +++ b/tests/parsimony/003 @@ -0,0 +1,6 @@ +int main() +{ + for (int i = 0; i < 10; ++i) printf("%d\n", i);for (int i = 0; i < 10; ++i) printf("%d\n", i);; + for (int i = 0; i < 10; ++i) printf("%d\n", i);while (i < 10) { printf("%d\n", i); ++il; }; + return 0; +} diff --git a/tests/parsimony/003.c b/tests/parsimony/003.c new file mode 100644 index 0000000..87a344f --- /dev/null +++ b/tests/parsimony/003.c @@ -0,0 +1,35 @@ +@{import("../src/parsimonyLibrary/boot.mc");} + +@{ + nTimes = `constant 10; + forLoop = `statement for (int i = 0; i < 10; ++i) printf("%d\n", i);; + whileLoop = `statement while (i < 10) { printf("%d\n", i); ++il; }; + useForLoop = 1; + nil; +} + +int main() +{ + @{ + l = {}; + append(l, forLoop); + if (useForLoop) { + append(l, forLoop); + } else { + append(l, whileLoop); + } + l; + }; + @{ + l = {}; + useForLoop = 0; + append(l, forLoop); + if (useForLoop) { + append(l, forLoop); + } else { + append(l, whileLoop); + } + l; + }; + return 0; +} diff --git a/tests/parsimony/004 b/tests/parsimony/004 new file mode 100644 index 0000000..5fee3e3 --- /dev/null +++ b/tests/parsimony/004 @@ -0,0 +1,8 @@ +int x = 2 * 21; + +int main() { + int i = 2 * 21; + int y = 2 * 10; + int a = 2 * 21; + return 0; +} \ No newline at end of file diff --git a/tests/parsimony/004.c b/tests/parsimony/004.c new file mode 100644 index 0000000..efc66e2 --- /dev/null +++ b/tests/parsimony/004.c @@ -0,0 +1,18 @@ +@{ + num = `constant 21; + test = `expression 2 * 10; + nil; +} + +int x = @{`expression 2 * @num;}; + +int main() { + int i = @(`expression 2 * @num); + int y = @test; + int a = @{ + num = `constant 21; + test = 2; + `expression 2 * @num; + }; + return 0; +} \ No newline at end of file diff --git a/tests/parsimony/005 b/tests/parsimony/005 new file mode 100644 index 0000000..9b122a2 --- /dev/null +++ b/tests/parsimony/005 @@ -0,0 +1,5 @@ +int a = 5;int b = 2;int main() { + int c = 5;int d = 2;for(int i =0; i < 10; i++) { + a = 2; + }; +} \ No newline at end of file diff --git a/tests/parsimony/005.c b/tests/parsimony/005.c new file mode 100644 index 0000000..91a9790 --- /dev/null +++ b/tests/parsimony/005.c @@ -0,0 +1,22 @@ +@{import("../src/parsimonyLibrary/boot.mc");} + +@{ + l = {}; + append(l, `declaration int a = 5;); + append(l, `declaration int b = 2;); + l; +} + +int main() { + @{ + l = {}; + a = (`declaration int a = 2;); + append(l, `declaration int c = 5;); + b = 5; + append(l, `declaration int d = 2;); + append(l, `statement for(int i =0; i < 10; i++) { + a = 2; + }); + l; + }; +} \ No newline at end of file diff --git a/tests/parsimony/006 b/tests/parsimony/006 new file mode 100644 index 0000000..29f4f9d --- /dev/null +++ b/tests/parsimony/006 @@ -0,0 +1,12 @@ +int a = 5;int a = 5;; + +int a = 5;; +int abc = 2;; + +int main() { + int a = 5;; + int b = 0; + int c = 0;int d = 5;int d = 5;; + int e = 0; + return 0; +} \ No newline at end of file diff --git a/tests/parsimony/006.c b/tests/parsimony/006.c new file mode 100644 index 0000000..9f9c2d6 --- /dev/null +++ b/tests/parsimony/006.c @@ -0,0 +1,36 @@ +@{import("../src/parsimonyLibrary/boot.mc");} + +@{ + l = {}; + append(l, `declaration int a = 5;); + a = (`declaration int a = 5;); + append(l, `declaration int a = 5;); + l; +}; + +@a; +@{ + t = `constant 2; + nil; +} +@(`declaration int abc = @t;); + +int main() { + @a; + int b = 0; + @{ + l = {}; + append(l, `declaration int c = 0;); + x = (`declaration int d = 5;); + append(l, x); + if (1) { + if (1) { + x = (`declaration int d = 5;); + append(l, x); + } + } + l; + }; + int e = 0; + return 0; +} \ No newline at end of file diff --git a/tests/parsimony/007 b/tests/parsimony/007 new file mode 100644 index 0000000..f343edd --- /dev/null +++ b/tests/parsimony/007 @@ -0,0 +1,3 @@ +int a = 0;int b = 0;int c = 0;; + +int b = 0;; \ No newline at end of file diff --git a/tests/parsimony/007.c b/tests/parsimony/007.c new file mode 100644 index 0000000..487dfbc --- /dev/null +++ b/tests/parsimony/007.c @@ -0,0 +1,16 @@ +@{import("../src/parsimonyLibrary/boot.mc");} + +@{ + l = {}; + append(l, `declaration int a = 0;); + a = (`declaration int b = 0;); + append(l, a); + if (1) { + append(l, `declaration int c = 0;); + } else { + append(l, `declaration int c = 1;); + } + l; +}; + +@a; \ No newline at end of file diff --git a/tests/parsimony/008 b/tests/parsimony/008 new file mode 100644 index 0000000..4c2f455 --- /dev/null +++ b/tests/parsimony/008 @@ -0,0 +1 @@ +int x; \ No newline at end of file diff --git a/tests/parsimony/008.c b/tests/parsimony/008.c new file mode 100644 index 0000000..52dc0d5 --- /dev/null +++ b/tests/parsimony/008.c @@ -0,0 +1,6 @@ +@{ + f(n) { + `declaration int @@(n);; + } + f("x"); +} \ No newline at end of file diff --git a/tests/parsimony/009 b/tests/parsimony/009 new file mode 100644 index 0000000..2c1ccd8 --- /dev/null +++ b/tests/parsimony/009 @@ -0,0 +1,8 @@ +x = 1, y = 2, z = 3 +x = 1, y = 2, z = 3 +x = 1, y = 3, z = null +x = 1, y = null, z = 3 +x = 3, y = null, z = 1 +x = 3, y = 1, z = null +x = null, y = 1, z = 3 +x = null, y = 3, z = 1 diff --git a/tests/parsimony/009.c b/tests/parsimony/009.c new file mode 100644 index 0000000..aba28cf --- /dev/null +++ b/tests/parsimony/009.c @@ -0,0 +1,15 @@ +@{ + f(x, y, z) { + print("x = ", x, ", y = ", y, ", z = ", z, "\n"); + nil; + } + + f(1, 2, 3); + f(x:1, y:2, z:3); + f(x:1, y:3); + f(x:1, z:3); + f(z:1,x:3); + f(y:1,x:3); + f(y:1,z:3); + f(z:1,y:3); +} \ No newline at end of file diff --git a/tests/parsimony/map b/tests/parsimony/map new file mode 100644 index 0000000..cc6745c --- /dev/null +++ b/tests/parsimony/map @@ -0,0 +1,8 @@ +enum foo { A, B, C }; +enum oof { A, B, C }; + +char *a[] = { "A""B""C"}; + +char *b[] = { "A", "B", "C"}; + +char *c[] = { "A", "B", "C"}; \ No newline at end of file diff --git a/tests/parsimony/map.c b/tests/parsimony/map.c new file mode 100644 index 0000000..6117c3a --- /dev/null +++ b/tests/parsimony/map.c @@ -0,0 +1,20 @@ +@{import("../src/parsimonyLibrary/boot.mc");} + +enum foo { A, B, C }; +enum oof { A, B, C }; + +@{ + isEnum(x) { x.__proto__ == C_enum } + notToken(x) { x.__proto__ != Token } + to_C_string(x) {{ __proto__: C_string, value: "\"" + string(x.name.identifier) + "\"" }} + a = map(to_C_string, select(isEnum, program.enums.foo.enumList)); + b = map(to_C_string, program.enums.foo.enumList, notToken); + c = map(to_C_string, program.enums.foo.enumList, isEnum); + nil; +} + +char *a[] = { @a }; + +char *b[] = { @b }; + +char *c[] = { @c }; \ No newline at end of file