Skip to content

Commit

Permalink
Support USER/SYSTEM mode on SOSL
Browse files Browse the repository at this point in the history
  • Loading branch information
nawforce committed May 12, 2024
1 parent 2f9160c commit 8245711
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# apex-parser - Changelog

## 4.0.0 - 2023-03-28
## 4.1.0 - 2024-05-12

- Allow WITH USER_MODE or SYSTEM_MODE on SOSL queries

## 4.0.0 - 2024-03-28

- Correct trigger body parsing to allow member declarations
- Add support for TYPEOF in SOQL subqueries
Expand Down
20 changes: 13 additions & 7 deletions antlr/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,23 @@ soslLiteralAlt
soslClauses
: (IN searchGroup)?
(RETURNING fieldSpecList)?
(WITH DIVISION ASSIGN StringLiteral)?
(WITH DATA CATEGORY filteringExpression)?
(WITH SNIPPET (LPAREN TARGET_LENGTH ASSIGN IntegerLiteral RPAREN)? )?
(WITH NETWORK IN LPAREN networkList RPAREN)?
(WITH NETWORK ASSIGN StringLiteral)?
(WITH PRICEBOOKID ASSIGN StringLiteral)?
(WITH METADATA ASSIGN StringLiteral)?
soslWithClause*
limitClause?
(UPDATE updateList)?
;

soslWithClause
: WITH DIVISION ASSIGN StringLiteral
| WITH DATA CATEGORY filteringExpression
| WITH SNIPPET (LPAREN TARGET_LENGTH ASSIGN IntegerLiteral RPAREN)?
| WITH NETWORK IN LPAREN networkList RPAREN
| WITH NETWORK ASSIGN StringLiteral
| WITH PRICEBOOKID ASSIGN StringLiteral
| WITH METADATA ASSIGN StringLiteral
| WITH USER_MODE
| WITH SYSTEM_MODE
;

searchGroup
: (ALL|EMAIL|NAME|PHONE|SIDEBAR) FIELDS
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ void testQuotesFailOnAltFormat() {
assertNotNull(context);
assertEquals(1, parserAndCounter.getValue().getNumErrors());
}

@Test
void testWithUserModeQuery() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("[Find 'something' RETURNING Account WITH USER_MODE WITH METADATA='Labels']");
ApexParser.SoslLiteralContext context = parserAndCounter.getKey().soslLiteral();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}

@Test
void testWithSystemModeQuery() {
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("[Find 'something' RETURNING Account WITH METADATA='Labels' WITH SYSTEM_MODE]");
ApexParser.SoslLiteralContext context = parserAndCounter.getKey().soslLiteral();
assertNotNull(context);
assertEquals(0, parserAndCounter.getValue().getNumErrors());
}
}
18 changes: 18 additions & 0 deletions npm/src/__tests__/SOSLParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,21 @@ test('testQuotesFailOnAltFormat', () => {
expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

test('testWithUserModeQuery', () => {
const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH USER_MODE WITH METADATA='Labels']")

const context = parser.soslLiteralAlt()

expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

test('testWithSystemModeQuery', () => {
const [parser, errorCounter] = createParser("[Find 'something' RETURNING Account WITH METADATA='Labels' WITH SYSTEM_MODE]")

const context = parser.soslLiteralAlt()

expect(context).toBeInstanceOf(SoslLiteralAltContext)
expect(errorCounter.getNumErrors()).toEqual(1)
})

0 comments on commit 8245711

Please sign in to comment.