Skip to content

Commit

Permalink
Support toLabel in SOSL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Aug 30, 2024
1 parent fee3a16 commit e52b7ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions antlr/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ fieldSpec

fieldList
: soslId (COMMA fieldList)*
| TOLABEL LPAREN soslId RPAREN
;

updateList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ void testWithSystemModeQuery() {
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testToLabel() {
Map.Entry<ApexParser, SyntaxErrorCounter> 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());
}
}
21 changes: 15 additions & 6 deletions npm/src/__tests__/SOSLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit e52b7ee

Please sign in to comment.