From fc3132494604c04c1f05bd72c1703611497dd6d2 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 1 Aug 2023 06:57:14 +0300 Subject: [PATCH] test(traceql): add more tests --- internal/traceql/parser.go | 5 -- internal/traceql/parser_test.go | 106 ++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/internal/traceql/parser.go b/internal/traceql/parser.go index 4c248955..2e8c734d 100644 --- a/internal/traceql/parser.go +++ b/internal/traceql/parser.go @@ -73,11 +73,6 @@ func (p *parser) consumeText(tt lexer.TokenType) (string, error) { return t.Text, nil } -func (p *parser) parseString() (string, error) { - s, err := p.consumeText(lexer.String) - return s, err -} - func (p *parser) parseInteger() (int64, error) { text, err := p.consumeText(lexer.Integer) if err != nil { diff --git a/internal/traceql/parser_test.go b/internal/traceql/parser_test.go index b398a6e5..3ba85368 100644 --- a/internal/traceql/parser_test.go +++ b/internal/traceql/parser_test.go @@ -450,6 +450,54 @@ var tests = []TestCase{ }, false, }, + { + `1+2*3^4 = 163`, + &SpansetPipeline{ + Pipeline: []PipelineStage{ + &ScalarFilter{ + Left: &BinaryScalarExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(1)}, + Op: OpAdd, + Right: &BinaryScalarExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(2)}, + Op: OpMul, + Right: &BinaryScalarExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(3)}, + Op: OpPow, + Right: &Static{Type: StaticInteger, Data: uint64(4)}, + }, + }, + }, + Op: OpEq, + Right: &Static{Type: StaticInteger, Data: uint64(163)}, + }, + }, + }, + false, + }, + { + `{ 1+2*3^4 }`, + &SpansetPipeline{ + Pipeline: []PipelineStage{ + &SpansetFilter{ + Expr: &BinaryFieldExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(1)}, + Op: OpAdd, + Right: &BinaryFieldExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(2)}, + Op: OpMul, + Right: &BinaryFieldExpr{ + Left: &Static{Type: StaticInteger, Data: uint64(3)}, + Op: OpPow, + Right: &Static{Type: StaticInteger, Data: uint64(4)}, + }, + }, + }, + }, + }, + }, + false, + }, { `2+3*4+5 = 19`, &SpansetPipeline{ @@ -619,6 +667,51 @@ var tests = []TestCase{ }, false, }, + { + `( { .a } | coalesce() ) && ( { .b } | coalesce() ) >> ( { .c } | coalesce() ) && ( { .d } | coalesce() )`, + &BinaryExpr{ + Left: &SpansetPipeline{ + Pipeline: []PipelineStage{ + &SpansetFilter{ + Expr: &Attribute{Name: "a"}, + }, + &CoalesceOperation{}, + }, + }, + Op: SpansetOpAnd, + Right: &BinaryExpr{ + Left: &BinaryExpr{ + Left: &SpansetPipeline{ + Pipeline: []PipelineStage{ + &SpansetFilter{ + Expr: &Attribute{Name: "b"}, + }, + &CoalesceOperation{}, + }, + }, + Op: SpansetOpDescendant, // Higher precedence then and. + Right: &SpansetPipeline{ + Pipeline: []PipelineStage{ + &SpansetFilter{ + Expr: &Attribute{Name: "c"}, + }, + &CoalesceOperation{}, + }, + }, + }, + Op: SpansetOpAnd, + Right: &SpansetPipeline{ + Pipeline: []PipelineStage{ + &SpansetFilter{ + Expr: &Attribute{Name: "d"}, + }, + &CoalesceOperation{}, + }, + }, + }, + }, + false, + }, // Invalid syntax. {`{`, nil, true}, @@ -634,6 +727,19 @@ var tests = []TestCase{ {`{} | by(.foo`, nil, true}, {`{} | coalesce(`, nil, true}, {`{} | select(.foo`, nil, true}, + {`(`, nil, true}, + {`()`, nil, true}, + {`(( { .a } )`, nil, true}, + // Missing expression. + {`{ .a = }`, nil, true}, + {`20 >`, nil, true}, + {`1 > 1+`, nil, true}, + {`{ .a } ~ `, nil, true}, + {`{ .a } && { .b } ~ `, nil, true}, + {`({ .a }) ~ `, nil, true}, + {`({ .a }) ~ ()`, nil, true}, + {`({ .a } | by(.b)) ~ `, nil, true}, + {`({ .a } | by(.b)) && ({ .b } | by(.b)) ~`, nil, true}, // Parameter is required, {`{} | max()`, nil, true}, {`{} | min()`, nil, true},