github.com/influxdata/influxql@v1.1.0/parse_tree_test.go (about) 1 package influxql_test 2 3 import ( 4 "reflect" 5 "strings" 6 "testing" 7 8 "github.com/influxdata/influxql" 9 ) 10 11 func TestParseTree_Clone(t *testing.T) { 12 // Clone the default language parse tree and add a new syntax node. 13 language := influxql.Language.Clone() 14 language.Group(influxql.CREATE).Handle(influxql.STATS, func(p *influxql.Parser) (influxql.Statement, error) { 15 return &influxql.ShowStatsStatement{}, nil 16 }) 17 18 // Create a parser with CREATE STATS and parse the statement. 19 parser := influxql.NewParser(strings.NewReader(`CREATE STATS`)) 20 stmt, err := language.Parse(parser) 21 if err != nil { 22 t.Fatalf("unexpected error: %s", err) 23 } else if !reflect.DeepEqual(stmt, &influxql.ShowStatsStatement{}) { 24 t.Fatalf("unexpected statement returned from parser: %s", stmt) 25 } 26 27 // Recreate the parser and try parsing with the original parsing. This should fail. 28 parser = influxql.NewParser(strings.NewReader(`CREATE STATS`)) 29 if _, err := parser.ParseStatement(); err == nil { 30 t.Fatal("expected error") 31 } 32 }