File: parse_tree_test.go

package info (click to toggle)
golang-github-influxdata-influxql 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 632 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (2)
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")
	}
}