From e52b7ee1aa752a9301fd44b8ea51610fbe892248 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 30 Aug 2024 18:27:08 +0200 Subject: [PATCH] Support toLabel in SOSL queries --- antlr/ApexParser.g4 | 1 + .../apexparser/SOSLParserTest.java | 8 +++++++ npm/src/__tests__/SOSLParserTest.ts | 21 +++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/antlr/ApexParser.g4 b/antlr/ApexParser.g4 index d6a259b..d38e5ca 100644 --- a/antlr/ApexParser.g4 +++ b/antlr/ApexParser.g4 @@ -864,6 +864,7 @@ fieldSpec fieldList : soslId (COMMA fieldList)* + | TOLABEL LPAREN soslId RPAREN ; updateList diff --git a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java index cc218a1..a272c81 100644 --- a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java +++ b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOSLParserTest.java @@ -76,4 +76,12 @@ void testWithSystemModeQuery() { assertNotNull(context); assertEquals(0, parserAndCounter.getValue().getNumErrors()); } + + @Test + void testToLabel() { + Map.Entry parserAndCounter = createParser("[FIND :searchTerm IN ALL FIELDS RETURNING Account(Id, toLabel(Name)) LIMIT 10]"); + ApexParser.SoslLiteralContext context = parserAndCounter.getKey().soslLiteral(); + assertNotNull(context); + assertEquals(0, parserAndCounter.getValue().getNumErrors()); + } } diff --git a/npm/src/__tests__/SOSLParserTest.ts b/npm/src/__tests__/SOSLParserTest.ts index 59f1721..1f15193 100644 --- a/npm/src/__tests__/SOSLParserTest.ts +++ b/npm/src/__tests__/SOSLParserTest.ts @@ -65,17 +65,26 @@ test('testQuotesFailOnAltFormat', () => { test('testWithUserModeQuery', () => { const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH USER_MODE WITH METADATA='Labels']") - const context = parser.soslLiteralAlt() + const context = parser.soslLiteral() - expect(context).toBeInstanceOf(SoslLiteralAltContext) - expect(errorCounter.getNumErrors()).toEqual(1) + expect(context).toBeInstanceOf(SoslLiteralContext) + expect(errorCounter.getNumErrors()).toEqual(0) }) test('testWithSystemModeQuery', () => { const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH METADATA='Labels' WITH SYSTEM_MODE]") - const context = parser.soslLiteralAlt() + const context = parser.soslLiteral() - expect(context).toBeInstanceOf(SoslLiteralAltContext) - expect(errorCounter.getNumErrors()).toEqual(1) + expect(context).toBeInstanceOf(SoslLiteralContext) + expect(errorCounter.getNumErrors()).toEqual(0) +}) + +test('testToLabel', () => { + const [parser, errorCounter] = createParser("[FIND :searchTerm IN ALL FIELDS RETURNING Account(Id, toLabel(Name)) LIMIT 10]") + + const context = parser.soslLiteral() + + expect(context).toBeInstanceOf(SoslLiteralContext) + expect(errorCounter.getNumErrors()).toEqual(0) })