aboutsummaryrefslogtreecommitdiff
path: root/spec/test/parser_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-08-03 23:07:06 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-08-05 02:36:21 +0900
commit2fcab705ddf787fa0f4edab2f2dc7e579ca982d9 (patch)
treebf4d37e9985109c7456a48fa61cc53d688ef3376 /spec/test/parser_test.go
parentFix parse error messages for tree parser (diff)
downloadcotia-2fcab705ddf787fa0f4edab2f2dc7e579ca982d9.tar.gz
cotia-2fcab705ddf787fa0f4edab2f2dc7e579ca982d9.tar.xz
Prohibit error node having children
Diffstat (limited to 'spec/test/parser_test.go')
-rw-r--r--spec/test/parser_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/test/parser_test.go b/spec/test/parser_test.go
index 7a8984e..cbf96c0 100644
--- a/spec/test/parser_test.go
+++ b/spec/test/parser_test.go
@@ -330,6 +330,83 @@ foo
`,
parseErr: true,
},
+ // A node may have just one string node.
+ {
+ src: `test
+----
+foo bar
+----
+(foo (bar 'bar'))
+`,
+ tc: &TestCase{
+ Description: "test",
+ Source: []byte("foo bar"),
+ Output: NewNonTerminalTree("foo",
+ NewTerminalNode("bar", "bar"),
+ ).Fill(),
+ },
+ },
+ // A node may have just one pattern node.
+ {
+ src: `test
+----
+foo bar
+----
+(foo (bar "bar"))
+`,
+ tc: &TestCase{
+ Description: "test",
+ Source: []byte("foo bar"),
+ Output: NewNonTerminalTree("foo",
+ NewTerminalNode("bar", "bar"),
+ ).Fill(),
+ },
+ },
+ // A node may be the error node.
+ {
+ src: `test
+----
+foo x
+----
+(foo (error))
+`,
+ tc: &TestCase{
+ Description: "test",
+ Source: []byte("foo x"),
+ Output: NewNonTerminalTree("foo",
+ NewTerminalNode("error", ""),
+ ).Fill(),
+ },
+ },
+ // The error node cannot have a string node.
+ {
+ src: `test
+----
+foo x
+----
+(foo (error 'x'))
+`,
+ parseErr: true,
+ },
+ // The error node cannot have a pattern node.
+ {
+ src: `test
+----
+foo x
+----
+(foo (error "x"))
+`,
+ parseErr: true,
+ },
+ {
+ src: `test
+----
+foo x
+----
+(foo (error (_ (x 'x'))))
+`,
+ parseErr: true,
+ },
{
src: `test
---