-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
validate_test.go
40 lines (31 loc) · 1.04 KB
/
validate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package participle_test
import (
"testing"
require "github.com/alecthomas/assert/v2"
"github.com/alecthomas/participle/v2"
)
type leftRecursionSimple struct {
Begin string ` @Ident`
More *leftRecursionSimple `| @@ "more"`
}
func TestValidateLeftRecursion(t *testing.T) {
_, err := participle.Build[leftRecursionSimple]()
require.Error(t, err)
require.Equal(t, err.Error(), `left recursion detected on
LeftRecursionSimple = <ident> | (LeftRecursionSimple "more") .`)
}
type leftRecursionNestedInner struct {
Begin string ` @Ident`
Next *leftRecursionNested `| @@`
}
type leftRecursionNested struct {
Begin string ` @Ident`
More *leftRecursionNestedInner `| @@ "more"`
}
func TestValidateLeftRecursionNested(t *testing.T) {
_, err := participle.Build[leftRecursionNested]()
require.Error(t, err)
require.Equal(t, err.Error(), `left recursion detected on
LeftRecursionNested = <ident> | (LeftRecursionNestedInner "more") .
LeftRecursionNestedInner = <ident> | LeftRecursionNested .`)
}