aboutsummaryrefslogtreecommitdiff
path: root/compiler/ast_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-04-11 20:12:54 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-04-12 22:43:29 +0900
commitfd1e20085306c60520d6b44938097cb3145c35f0 (patch)
tree608a89ad04673394fb8eb364c32c3cf86591d204 /compiler/ast_test.go
parentFix grammar the parser accepts (diff)
downloadtre-fd1e20085306c60520d6b44938097cb3145c35f0.tar.gz
tre-fd1e20085306c60520d6b44938097cb3145c35f0.tar.xz
Increase the maximum number of symbol positions per pattern
This commit increases the maximum number of symbol positions per pattern to 2^15 (= 32,768). When the limit is exceeded, the parse method returns an error.
Diffstat (limited to 'compiler/ast_test.go')
-rw-r--r--compiler/ast_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/compiler/ast_test.go b/compiler/ast_test.go
index 7ea59e2..8b0a0ee 100644
--- a/compiler/ast_test.go
+++ b/compiler/ast_test.go
@@ -5,6 +5,79 @@ import (
"testing"
)
+func TestNewSymbolPosition(t *testing.T) {
+ tests := []struct {
+ n uint16
+ endMark bool
+ err bool
+ }{
+ {
+ n: 0,
+ endMark: false,
+ err: true,
+ },
+ {
+ n: 0,
+ endMark: true,
+ err: true,
+ },
+ {
+ n: symbolPositionMin - 1,
+ endMark: false,
+ err: true,
+ },
+ {
+ n: symbolPositionMin - 1,
+ endMark: true,
+ err: true,
+ },
+ {
+ n: symbolPositionMin,
+ endMark: false,
+ },
+ {
+ n: symbolPositionMin,
+ endMark: true,
+ },
+ {
+ n: symbolPositionMax,
+ endMark: false,
+ },
+ {
+ n: symbolPositionMax,
+ endMark: true,
+ },
+ {
+ n: symbolPositionMax + 1,
+ endMark: false,
+ err: true,
+ },
+ {
+ n: symbolPositionMax + 1,
+ endMark: true,
+ err: true,
+ },
+ }
+ for i, tt := range tests {
+ t.Run(fmt.Sprintf("#%v n: %v, endMark: %v", i, tt.n, tt.endMark), func(t *testing.T) {
+ pos, err := newSymbolPosition(tt.n, tt.endMark)
+ if tt.err {
+ if err == nil {
+ t.Fatal("err is nil")
+ }
+ return
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ n, endMark := pos.describe()
+ if n != tt.n || endMark != tt.endMark {
+ t.Errorf("unexpected symbol position; want: n: %v, endMark: %v, got: n: %v, endMark: %v", tt.n, tt.endMark, n, endMark)
+ }
+ })
+ }
+}
+
func TestASTNode(t *testing.T) {
tests := []struct {
root astNode