This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from nawforce/41-member-declarations-missing-f…
…rom-triggerunit-rule Add triggerUnit2 for trigger parsing fixes
- Loading branch information
Showing
3 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
jvm/src/test/java/com/nawforce/apexparser/ApexTrigger2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.nawforce.apexparser; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static com.nawforce.apexparser.SyntaxErrorCounter.createParser; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ApexTrigger2Test { | ||
|
||
@Test | ||
void testEmptyTrigger() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithStatement() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {System.debug('');}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithMethod() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {public void func() {}}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithField() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {String a;}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithInterface() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {interface Foo {}}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithClass() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {class Foo {}}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithEnum() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) {enum Foo {}}"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
@Test | ||
void testTriggerWithProperty() { | ||
Map.Entry<ApexParser, SyntaxErrorCounter> parserAndCounter = createParser("trigger test on Account (before update, after update) { String a {get { return a; } set { a = value; }} }"); | ||
ApexParser.TriggerUnit2Context context = parserAndCounter.getKey().triggerUnit2(); | ||
assertNotNull(context); | ||
assertEquals(0, parserAndCounter.getValue().getNumErrors()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {TriggerUnit2Context} from "../ApexParser"; | ||
import { createParser } from "./SyntaxErrorCounter"; | ||
|
||
test('Empty Trigger', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with statement', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {System.debug('');}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with method', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {public void func() {}}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with field', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {String a;}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with interface', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {interface Foo {}}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with class', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {class Foo {}}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with enum', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) {enum Foo {}}") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) | ||
|
||
test('Trigger with property', () => { | ||
const [parser, errorCounter] = createParser("test.trigger", "trigger test on Account (before update, after update) { String a {get { return a; } set { a = value; }} }") | ||
const context = parser.triggerUnit2() | ||
|
||
expect(context).toBeInstanceOf(TriggerUnit2Context) | ||
expect(errorCounter.getNumErrors()).toEqual(0) | ||
}) |