Skip to content

Commit

Permalink
refactor misc tests for no-channels lexer
Browse files Browse the repository at this point in the history
Signed-off-by: James Ranson <james@ranson.org>
  • Loading branch information
jranson committed Aug 13, 2024
1 parent 365b2cf commit 8de61a9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
61 changes: 33 additions & 28 deletions pkg/backends/clickhouse/parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,49 +162,51 @@ func TestParseErrors(t *testing.T) {

func TestAtWith(t *testing.T) {

rs := parsing.NewRunState(context.Background())
ch := rs.Tokens()
ch <- &token.Token{Typ: token.Space, Val: " "}
tk := token.Tokens{&token.Token{Typ: token.Space, Val: " "}}
rs := parsing.NewRunState(context.Background(), tk)
rs.Next()
f := atWith(nil, nil, rs)
if f != nil {
t.Error("expected nil StateFn")
}

rs = parsing.NewRunState(context.Background())
ch = rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenWith, Val: "with"}
tk = token.Tokens{&token.Token{Typ: lsql.TokenWith, Val: "with"}}
rs = parsing.NewRunState(context.Background(), tk)
rs.Next()
atWith(nil, nil, rs)
if rs.Error() != parsing.ErrUnsupportedParser {
t.Error("expected ErrUnsupportedParser")
}

rs = parsing.NewRunState(context.Background())
ch = rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenWith, Val: "with"}
ch <- &token.Token{Typ: lsql.TokenSelect, Val: "select"}
tk = token.Tokens{
&token.Token{Typ: lsql.TokenWith, Val: "with"},
&token.Token{Typ: lsql.TokenSelect, Val: "select"},
}

rs = parsing.NewRunState(context.Background(), tk)
rs.Next()
f = atWith(parser, parser, rs)
if f == nil {
t.Error("expected non-nil StateFn")
}

rs = parsing.NewRunState(context.Background())
ch = rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenWith, Val: "with"}
ch <- &token.Token{Typ: token.EOF}
tk = token.Tokens{
&token.Token{Typ: lsql.TokenWith, Val: "with"},
&token.Token{Typ: token.EOF},
}
rs = parsing.NewRunState(context.Background(), tk)
rs.Next()
f = atWith(parser, parser, rs)
if f != nil {
t.Error("expected nil StateFn")
}

rs = parsing.NewRunState(context.Background())
ch = rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenWith, Val: "with"}
ch <- &token.Token{Typ: token.Identifier, Val: "x"}
ch <- &token.Token{Typ: lsql.TokenSelect, Val: "select"}
tk = token.Tokens{
&token.Token{Typ: lsql.TokenWith, Val: "with"},
&token.Token{Typ: token.Identifier, Val: "x"},
&token.Token{Typ: lsql.TokenSelect, Val: "select"},
}
rs = parsing.NewRunState(context.Background(), tk)
rs.Next()
f = atWith(parser, parser, rs)
if f != nil {
Expand All @@ -216,7 +218,7 @@ func TestAtWith(t *testing.T) {
}

func TestAtPreWhere(t *testing.T) {
rs := parsing.NewRunState(context.Background())
rs := parsing.NewRunState(context.Background(), nil)
f := atPreWhere(nil, nil, rs)
if f != nil {
t.Error("expected nil StateFn")
Expand All @@ -227,19 +229,22 @@ func TestAtPreWhere(t *testing.T) {
}

func TestAtFormat(t *testing.T) {
rs := parsing.NewRunState(context.Background())
ch := rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenComment}
ch <- &token.Token{Typ: token.EOF}

tk := token.Tokens{
&token.Token{Typ: lsql.TokenComment},
&token.Token{Typ: token.EOF},
}
rs := parsing.NewRunState(context.Background(), tk)
f := atFormat(nil, nil, rs)
if f != nil {
t.Error("expected nil StateFn")
}

rs = parsing.NewRunState(context.Background())
ch = rs.Tokens()
ch <- &token.Token{Typ: token.Identifier, Val: "UnsupportedFormat"}
ch <- &token.Token{Typ: token.EOF}
tk = token.Tokens{
&token.Token{Typ: token.Identifier, Val: "UnsupportedFormat"},
&token.Token{Typ: token.EOF},
}
rs = parsing.NewRunState(context.Background(), tk)
f = atFormat(nil, nil, rs)
if f != nil {
t.Error("expected nil StateFn")
Expand Down
7 changes: 4 additions & 3 deletions pkg/timeseries/sqlparser/sqlparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ func TestParseComment(t *testing.T) {
trq := &timeseries.TimeRangeQuery{Statement: "trickster"}
ro := &timeseries.RequestOptions{TimeFormat: 42}
rc := NewRunContext(trq, ro)
rs := parsing.NewRunState(rc)
ch := rs.Tokens()
ch <- &token.Token{Typ: lsql.TokenComment, Val: ":)"}
tk := token.Tokens{
&token.Token{Typ: lsql.TokenComment, Val: ":)"},
}
rs := parsing.NewRunState(rc, tk)
rs.Next()
ParseFVComment(nil, nil, rs)
if rs.Current().Typ != lsql.TokenComment {
Expand Down

0 comments on commit 8de61a9

Please sign in to comment.