aboutsummaryrefslogtreecommitdiff
path: root/spec/parser_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-05-09 00:36:06 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-05-10 23:14:52 +0900
commitdd5fd3372cdb53e7a3a36b5ef61b0b0c35023798 (patch)
treee29796e3c0aee95e443aeabe6b24e2ed4c81dac0 /spec/parser_test.go
parentAdd #assign directive (diff)
downloadurubu-dd5fd3372cdb53e7a3a36b5ef61b0b0c35023798.tar.gz
urubu-dd5fd3372cdb53e7a3a36b5ef61b0b0c35023798.tar.xz
Add ordered symbol notation
Diffstat (limited to 'spec/parser_test.go')
-rw-r--r--spec/parser_test.go41
1 files changed, 36 insertions, 5 deletions
diff --git a/spec/parser_test.go b/spec/parser_test.go
index 3fe950f..15f1330 100644
--- a/spec/parser_test.go
+++ b/spec/parser_test.go
@@ -14,14 +14,12 @@ func TestParse(t *testing.T) {
Parameters: []*ParameterNode{param},
}
}
-
prec := func(param *ParameterNode) *DirectiveNode {
return &DirectiveNode{
Name: "prec",
Parameters: []*ParameterNode{param},
}
}
-
leftAssoc := func(params ...*ParameterNode) *DirectiveNode {
return &DirectiveNode{
Name: "left",
@@ -82,6 +80,11 @@ func TestParse(t *testing.T) {
ID: id,
}
}
+ ordSymParam := func(id string) *ParameterNode {
+ return &ParameterNode{
+ OrderedSymbol: id,
+ }
+ }
exp := func(param *ParameterNode) *ParameterNode {
param.Expansion = true
return param
@@ -152,9 +155,9 @@ func TestParse(t *testing.T) {
#name test;
#prec (
- #left a b
- #right c d
- #assign e f
+ #left a b $x1
+ #right c d $x2
+ #assign e f $x3
);
`,
ast: &RootNode{
@@ -182,6 +185,10 @@ func TestParse(t *testing.T) {
idParam("b"),
newPos(5),
),
+ withParamPos(
+ ordSymParam("x1"),
+ newPos(5),
+ ),
),
newPos(5),
),
@@ -195,6 +202,10 @@ func TestParse(t *testing.T) {
idParam("d"),
newPos(6),
),
+ withParamPos(
+ ordSymParam("x2"),
+ newPos(6),
+ ),
),
newPos(6),
),
@@ -208,6 +219,10 @@ func TestParse(t *testing.T) {
idParam("f"),
newPos(7),
),
+ withParamPos(
+ ordSymParam("x3"),
+ newPos(7),
+ ),
),
newPos(7),
),
@@ -237,6 +252,15 @@ func TestParse(t *testing.T) {
synErr: synErrUnclosedDirGroup,
},
{
+ caption: "an ordered symbol marker '$' must be followed by and ID",
+ src: `
+#prec (
+ #assign $
+);
+`,
+ synErr: synErrNoOrderedSymbolName,
+ },
+ {
caption: "single production is a valid grammar",
src: `a: "a";`,
ast: &RootNode{
@@ -299,6 +323,13 @@ c: ;
},
},
{
+ caption: "a production cannot contain an ordered symbol",
+ src: `
+a: $x;
+`,
+ synErr: synErrNoSemicolon,
+ },
+ {
caption: "`fragment` is a reserved word",
src: `fragment: 'fragment';`,
synErr: synErrNoProductionName,