forked from influxdata/influxql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_tree_test.go
32 lines (27 loc) · 1009 Bytes
/
parse_tree_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
package influxql_test
import (
"reflect"
"strings"
"testing"
"github.com/influxdata/influxql"
)
func TestParseTree_Clone(t *testing.T) {
// Clone the default language parse tree and add a new syntax node.
language := influxql.Language.Clone()
language.Group(influxql.CREATE).Handle(influxql.STATS, func(p *influxql.Parser) (influxql.Statement, error) {
return &influxql.ShowStatsStatement{}, nil
})
// Create a parser with CREATE STATS and parse the statement.
parser := influxql.NewParser(strings.NewReader(`CREATE STATS`))
stmt, err := language.Parse(parser)
if err != nil {
t.Fatalf("unexpected error: %s", err)
} else if !reflect.DeepEqual(stmt, &influxql.ShowStatsStatement{}) {
t.Fatalf("unexpected statement returned from parser: %s", stmt)
}
// Recreate the parser and try parsing with the original parsing. This should fail.
parser = influxql.NewParser(strings.NewReader(`CREATE STATS`))
if _, err := parser.ParseStatement(); err == nil {
t.Fatal("expected error")
}
}