Skip to content

Commit

Permalink
test(traceql): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Aug 1, 2023
1 parent 47dc61f commit fc31324
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 5 deletions.
5 changes: 0 additions & 5 deletions internal/traceql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
106 changes: 106 additions & 0 deletions internal/traceql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down

0 comments on commit fc31324

Please sign in to comment.