From ff73190df5cd750221bcc4c090d37957578c5409 Mon Sep 17 00:00:00 2001 From: Tom Wright Date: Tue, 1 Oct 2024 02:04:48 +0100 Subject: [PATCH] Add string concat test --- execution/execute_test.go | 5 +++++ selector/parser/parse_group.go | 5 +++++ selector/parser/parser.go | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/execution/execute_test.go b/execution/execute_test.go index 08bef00..efbeea6 100644 --- a/execution/execute_test.go +++ b/execution/execute_test.go @@ -196,6 +196,11 @@ func TestExecuteSelector_HappyPath(t *testing.T) { s: `name.first`, out: model.NewStringValue("Tom"), })) + t.Run("concat", runTest(testCase{ + in: inputMap(), + s: `title + " " + (name.first) + " " + (name.last)`, + out: model.NewStringValue("Mr Tom Wright"), + })) }) t.Run("object", func(t *testing.T) { diff --git a/selector/parser/parse_group.go b/selector/parser/parse_group.go index 354f959..5136e17 100644 --- a/selector/parser/parse_group.go +++ b/selector/parser/parse_group.go @@ -21,6 +21,11 @@ func parseGroup(p *Parser) (ast.Expr, error) { break } + if p.current().IsKind(lexer.Dot) { + p.advance() + continue + } + expr, err := p.parseExpression(bpDefault) if err != nil { return nil, err diff --git a/selector/parser/parser.go b/selector/parser/parser.go index 48706af..a50784c 100644 --- a/selector/parser/parser.go +++ b/selector/parser/parser.go @@ -53,7 +53,7 @@ func (p *Parser) endOfExpressionTokens() []lexer.TokenKind { case scopeObject: return []lexer.TokenKind{lexer.CloseCurly, lexer.Equals, lexer.Number, lexer.Symbol, lexer.Comma} case scopeGroup: - return []lexer.TokenKind{lexer.CloseParen} + return append([]lexer.TokenKind{lexer.CloseParen, lexer.Dot}, leftDenotationTokens...) default: return nil }