[eclipse/xtext#1837] converted xtend 2 java

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2020-11-18 21:31:38 +01:00
parent ada9ba3f9c
commit 5745b5fad1
11 changed files with 761 additions and 2110 deletions

View file

@ -0,0 +1,335 @@
/**
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.generator.parser;
import org.junit.Test;
/**
* Contributes unit tests for {@link AntlrGrammarComparator}.
*
* @author Christian Schneider - Initial contribution and API
*/
public class AntlrGrammarComparatorTest {
private AntlrGrammarComparatorTestHelper antlrGrammarComparatorTestHelper = new AntlrGrammarComparatorTestHelper();
/**
* The pattern of "\"" is not expected to occur in ANTLR grammar, so I use
* it for testing the unmatched token check.
*/
@Test(expected = AssertionError.class)
public void unmatchedTokens01() {
String testee = "\"\"\"a\n";
antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test
public void stringMatch_00a() {
String testee = "hans\n";
String expected = "hans\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_00b() {
String testee = "hans";
String expected = "hans";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_01a() {
String testee = "hans hugo\n";
String expected = "hans hugo\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_01b() {
String testee = "hans hugo";
String expected = "hans hugo";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_01a() {
String testee = "hans hugo\n";
String expected = "hugo hans\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_01b() {
String testee = "hans hugo";
String expected = "hugo hans";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_02a() {
String testee = "hans\n";
String expected = "hans hugo\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_02b() {
String testee = "hans";
String expected = "hans hugo";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_03a() {
String testee = "hans hugo\n";
String expected = "hans\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_03b() {
String testee = "hans hugo";
String expected = "hans";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_04() {
String testee = "hans hu";
String expected = "hans hugo";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_05() {
String testee = "hans hugo";
String expected = "hans hu";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch01() {
String expected = "RULE_IN_RICH_STRING?\n";
String testee = "RULE_IN_RICH_STRING ?\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch02() {
String expected = "RULE_IN_RICH_STRING*\n";
String testee = "RULE_IN_RICH_STRING *\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch03() {
String expected = "RULE_IN_RICH_STRING+\n";
String testee = "RULE_IN_RICH_STRING +\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void snippetMatch01() {
String expected =
"grammar InternalStatemachine;\n" +
"options {\n" +
" superClass=AbstractInternalAntlrParser;\n" +
"}\n";
String testee =
"grammar InternalStatemachine ;\n" +
"options{\n" +
" superClass = AbstractInternalAntlrParser\n" +
" ;\n" +
"}\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void snippetMatch02() {
String expected =
"(( 'abstract' \n" +
" | 'annotation' \n" +
" | 'class' \n" +
" | '(' \n" +
" | RULE_ID | RULE_HEX )\n";
String testee =
"(\n" +
" ('abstract' | 'annotation' | 'class' | '(' | RULE_ID | RULE_HEX )\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void matchAllTokens01() {
String testee = "RULE_RICH_TEXT : ''''' RULE_IN_RICH_STRING* ('''''|(''' '''?)? EOF);\n";
antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test
public void matchAllTokens02() {
String testee =
"RULE_RICH_TEXT_START : '\\'\\'\\'' RULE_IN_RICH_STRING* ('\\'' '\\''?)? '\\u00AB';\n" +
"\n" +
"RULE_RICH_TEXT_END : '\\u00BB' RULE_IN_RICH_STRING* ('\\'\\'\\''|('\\'' '\\''?)? EOF);\n" +
"\n" +
"RULE_RICH_TEXT_INBETWEEN : '\\u00BB' RULE_IN_RICH_STRING* ('\\'' '\\''?)? '\\u00AB';\n" +
"\n" +
"RULE_COMMENT_RICH_TEXT_INBETWEEN : '\\u00AB\\u00AB' ~(('\\n'|'\\r'))* ('\\r'? '\\n' RULE_IN_RICH_STRING* ('\\'' '\\''?)? '\\u00AB')?;\n" +
"\n" +
"RULE_COMMENT_RICH_TEXT_END : '\\u00AB\\u00AB' ~(('\\n'|'\\r'))* ('\\r'? '\\n' RULE_IN_RICH_STRING* ('\\'\\'\\''|('\\'' '\\''?)? EOF)|EOF);n";
antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses01() {
String testee = "hans ( ( hugo )\n";
String expected = "hans ( hugo )\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses02() {
String testee = "hans ( hugo ) )\n";
String expected = "hans ( hugo )\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses03() {
String testee = "{ '(' ( ')' }\n";
String expected = "{ '(' ')' }\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses04() {
String testee = "{ '(' '( ')' }\n";
String expected = "{ '(' '(' ')' }\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void sLCommentIgnoring01() {
String testee =
"A: 'A'\n" +
"\n" +
"// rule B\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void sLCommentIgnoring01b() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected = "A: 'A'\n" +
"\n" +
"// rule B\n" +
"B: 'B'\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mismatchWithSLComment01() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"// rule B\n" +
"B: 'C'\n";
antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 4);
}
@Test(expected = AssertionError.class)
public void mismatchWithSLComment01b() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"// rule B\n" +
"B: 'C'\n";
// expected to fail because of wrong 'lineNoTestee'
antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 4, 4);
}
@Test
public void mLCommentIgnoring01() {
String testee =
"A: 'A'\n" +
"\n" +
"/*\n" +
" * rule B\n" +
" */\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mLCommentIgnoring01b() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"/*\n" +
" * rule B\n" +
" */\n" +
"B: 'B'\n";
antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mismatchWithMLComment01() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"/*\n" +
" * rule B\n" +
" */\n" +
"B: 'C'\n";
antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 6);
}
@Test(expected = AssertionError.class)
public void mismatchWithMLComment01b() {
String testee =
"A: 'A'\n" +
"\n" +
"B: 'B'\n";
String expected =
"A: 'A'\n" +
"\n" +
"/*\n" +
" * rule B\n" +
" */\n" +
"B: 'C'\n";
// expected to fail because of wrong 'lineNoExpected'
antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 5);
}
}

View file

@ -1,472 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.generator.parser
import org.junit.Test
/**
* Contributes unit tests for {@link AntlrGrammarComparator}.
*
* @author Christian Schneider - Initial contribution and API
*/
class AntlrGrammarComparatorTest {
extension AntlrGrammarComparatorTestHelper = new AntlrGrammarComparatorTestHelper();
/**
* The pattern of "\"" is not expected to occur in ANTLR grammar,
* so I use it for testing the unmatched token check.
*/
@Test(expected = AssertionError)
def void unmatchedTokens01() {
val testee = '''
"\""a
'''
testee.compare(testee)
}
@Test
def void stringMatch_00a() {
val testee = '''
hans
'''
val expected = '''
hans
'''
testee.compare(expected)
}
@Test
def void stringMatch_00b() {
val testee = '''hans'''
val expected = '''hans'''
testee.compare(expected)
}
@Test
def void stringMatch_01a() {
val testee = '''
hans hugo
'''
val expected = '''
hans hugo
'''
testee.compare(expected)
}
@Test
def void stringMatch_01b() {
val testee = '''hans hugo'''
val expected = '''hans hugo'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_01a() {
val testee = '''
hans hugo
'''
val expected = '''
hugo hans
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_01b() {
val testee = '''hans hugo'''
val expected = '''hugo hans'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_02a() {
val testee = '''
hans
'''
val expected = '''
hans hugo
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_02b() {
val testee = '''hans'''
val expected = '''hans hugo'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_03a() {
val testee = '''
hans hugo
'''
val expected = '''
hans
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_03b() {
val testee = '''hans hugo'''
val expected = '''hans'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_04() {
val testee = '''hans hu'''
val expected = '''hans hugo'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void stringMismatch_05() {
val testee = '''hans hugo'''
val expected = '''hans hu'''
testee.compare(expected)
}
@Test
def void regExMatch01() {
val expected = '''
RULE_IN_RICH_STRING?
'''
val testee = '''
RULE_IN_RICH_STRING ?
'''
testee.compare(expected)
}
@Test
def void regExMatch02() {
val expected = '''
RULE_IN_RICH_STRING*
'''
val testee = '''
RULE_IN_RICH_STRING *
'''
testee.compare(expected)
}
@Test
def void regExMatch03() {
val expected = '''
RULE_IN_RICH_STRING+
'''
val testee = '''
RULE_IN_RICH_STRING +
'''
testee.compare(expected)
}
@Test
def void snippetMatch01() {
val expected = '''
grammar InternalStatemachine;
options {
superClass=AbstractInternalAntlrParser;
}
'''
val testee = '''
grammar InternalStatemachine ;
options{
superClass = AbstractInternalAntlrParser
;
}
'''
testee.compare(expected)
}
@Test
def void snippetMatch02() {
val expected = '''
(( 'abstract'
| 'annotation'
| 'class'
| '('
| RULE_ID | RULE_HEX )
'''
val testee = '''
(
('abstract' | 'annotation' | 'class' | '(' | RULE_ID | RULE_HEX )
'''
testee.compare(expected)
}
@Test
def void matchAllTokens01() {
val testee = '''
RULE_RICH_TEXT : '\'\'\'' RULE_IN_RICH_STRING* ('\'\'\''|('\'' '\''?)? EOF);
'''
testee.compare(testee)
}
@Test
def void matchAllTokens02() {
val testee = '''
RULE_RICH_TEXT_START : '\'\'\'' RULE_IN_RICH_STRING* ('\'' '\''?)? '\u00AB';
RULE_RICH_TEXT_END : '\u00BB' RULE_IN_RICH_STRING* ('\'\'\''|('\'' '\''?)? EOF);
RULE_RICH_TEXT_INBETWEEN : '\u00BB' RULE_IN_RICH_STRING* ('\'' '\''?)? '\u00AB';
RULE_COMMENT_RICH_TEXT_INBETWEEN : '\u00AB\u00AB' ~(('\n'|'\r'))* ('\r'? '\n' RULE_IN_RICH_STRING* ('\'' '\''?)? '\u00AB')?;
RULE_COMMENT_RICH_TEXT_END : '\u00AB\u00AB' ~(('\n'|'\r'))* ('\r'? '\n' RULE_IN_RICH_STRING* ('\'\'\''|('\'' '\''?)? EOF)|EOF);
'''
testee.compare(testee)
}
@Test(expected = AssertionError)
def void mismatchOfParantheses01() {
val testee = '''
hans ( ( hugo )
'''
val expected = '''
hans ( hugo )
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void mismatchOfParantheses02() {
val testee = '''
hans ( hugo ) )
'''
val expected = '''
hans ( hugo )
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void mismatchOfParantheses03() {
val testee = '''
{ '(' ( ')' }
'''
val expected = '''
{ '(' ')' }
'''
testee.compare(expected)
}
@Test(expected = AssertionError)
def void mismatchOfParantheses04() {
val testee = '''
{ '(' '( ')' }
'''
val expected = '''
{ '(' '(' ')' }
'''
testee.compare(expected)
}
@Test
def void sLCommentIgnoring01() {
val testee = '''
A: 'A'
// rule B
B: 'B'
'''
val expected = '''
A: 'A'
B: 'B'
'''
testee.compare(expected)
}
@Test
def void sLCommentIgnoring01b() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
// rule B
B: 'B'
'''
testee.compare(expected)
}
@Test
def void mismatchWithSLComment01() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
// rule B
B: 'C'
'''
testee.compareAndExpectMismatchInLines(expected, 3, 4)
}
@Test(expected = AssertionError)
def void mismatchWithSLComment01b() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
// rule B
B: 'C'
'''
// expected to fail because of wrong 'lineNoTestee'
testee.compareAndExpectMismatchInLines(expected, 4, 4)
}
@Test
def void mLCommentIgnoring01() {
val testee = '''
A: 'A'
/*
* rule B
*/
B: 'B'
'''
val expected = '''
A: 'A'
B: 'B'
'''
testee.compare(expected)
}
@Test
def void mLCommentIgnoring01b() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
/*
* rule B
*/
B: 'B'
'''
testee.compare(expected)
}
@Test
def void mismatchWithMLComment01() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
/*
* rule B
*/
B: 'C'
'''
testee.compareAndExpectMismatchInLines(expected, 3, 6)
}
@Test(expected = AssertionError)
def void mismatchWithMLComment01b() {
val testee = '''
A: 'A'
B: 'B'
'''
val expected = '''
A: 'A'
/*
* rule B
*/
B: 'C'
'''
// expected to fail because of wrong 'lineNoExpected'
testee.compareAndExpectMismatchInLines(expected, 3, 5)
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -41,7 +41,7 @@ class GrammarPDAProviderTest {
@Inject ParseHelper<Grammar> parser
@Inject ValidationTestHelper validator
@Test def void testUnassignedAction() {
@Test def void testUnassignedAction() throws Exception {
val actual = '''
Rule: {Action};
'''.toPda
@ -53,7 +53,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testAssignedAction() {
@Test def void testAssignedAction() throws Exception {
val actual = '''
Rule: {Foo} {Action.feat=current};
'''.toPda
@ -66,7 +66,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testAssignedTerminalRuleCall() {
@Test def void testAssignedTerminalRuleCall() throws Exception {
val actual = '''
Rule: name=ID;
'''.toPda
@ -78,7 +78,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testAssignedEObjectRuleCall() {
@Test def void testAssignedEObjectRuleCall() throws Exception {
val actual = '''
Rule: call=Called;
Called: name=ID;
@ -94,7 +94,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testAssignedDatatypeRuleCall() {
@Test def void testAssignedDatatypeRuleCall() throws Exception {
val actual = '''
Rule: call=Called;
Called: "foo";
@ -107,7 +107,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedCalledAction() {
@Test def void testUnassignedCalledAction() throws Exception {
val actual = '''
Rule: D1 | D2;
D1: 'd1' A;
@ -155,7 +155,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedFragmentRuleCall() {
@Test def void testUnassignedFragmentRuleCall() throws Exception {
val actual = '''
Rule: Called;
fragment Called returns Abstract: name=ID;
@ -170,7 +170,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedDatatypeRule() {
@Test def void testUnassignedDatatypeRule() throws Exception {
val actual = '''
Rule: val=ID Called;
Called: 'kw1';
@ -184,7 +184,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedTerminalRule() {
@Test def void testUnassignedTerminalRule() throws Exception {
val actual = '''
Rule: val=ID Called;
terminal Called: 'kw1';
@ -198,7 +198,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedParserRuleCall() {
@Test def void testUnassignedParserRuleCall() throws Exception {
val actual = '''
Rule: Called;
Called returns Sub: name=ID;
@ -216,7 +216,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnassignedWildcardFragmentRuleCall() {
@Test def void testUnassignedWildcardFragmentRuleCall() throws Exception {
val actual = '''
Rule: Called;
fragment Called*: name=ID;
@ -231,7 +231,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testGroup() {
@Test def void testGroup() throws Exception {
val actual = '''
Rule: {Rule} 'a' 'b' 'c';
'''.toPda
@ -246,7 +246,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testAlternative() {
@Test def void testAlternative() throws Exception {
val actual = '''
Rule: {Rule} ('a' | 'b' | 'c');
'''.toPda
@ -261,7 +261,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnorderedGroup() {
@Test def void testUnorderedGroup() throws Exception {
val actual = '''
Rule: {Rule} ('a' & 'b' & 'c');
'''.toPda
@ -276,7 +276,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testUnorderedGroup2() {
@Test def void testUnorderedGroup2() throws Exception {
val actual = '''
Rule: {Rule} ('a' & 'b'? & 'c'* & 'd'+);
'''.toPda
@ -292,7 +292,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testTwoAssignedEObjectRuleCalls() {
@Test def void testTwoAssignedEObjectRuleCalls() throws Exception {
val actual = '''
Rule: foo1=Sub foo2=Sub; Sub: id='id';
'''.toPda
@ -308,7 +308,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testRecursion() {
@Test def void testRecursion() throws Exception {
val actual = '''
Recursion: val=ID | '(' Recursion ')';
'''.toPda
@ -324,7 +324,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testExpression1() {
@Test def void testExpression1() throws Exception {
val actual = '''
Exp: 'kw' Addit; Addit returns Exp: Prim ({Add.left=current} '+' right=Prim)*; Prim returns Exp: {Val} val=ID;
'''.toPda
@ -358,7 +358,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testActionAlternative() {
@Test def void testActionAlternative() throws Exception {
val actual = '''
Greeting: '(' Greeting ')' {Foo.child=current} | val=ID;
'''.toPda
@ -375,7 +375,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test @Ignore def void testFragmentWithAction() {
@Test @Ignore def void testFragmentWithAction() throws Exception {
val actual = '''
R: f1=ID F; fragment F returns R: {A.prev=current} f2=ID;
'''.toPda
@ -391,7 +391,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test @Ignore def void testFragmentWithAction2() {
@Test @Ignore def void testFragmentWithAction2() throws Exception {
val actual = '''
R: 'kw1a' f1=ID 'kw1b' F; fragment F returns R: 'kw2a' {A.prev=current} 'kw2b' f2=ID 'kw2c';
'''.toPda
@ -407,7 +407,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testParameter1() {
@Test def void testParameter1() throws Exception {
val actual = '''
M: "kw1" s=S<true> | "kw2" s=S<false>;
S <P>: <P> v1=ID | <!P> v2=ID;
@ -429,7 +429,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testDoubleFragment() {
@Test def void testDoubleFragment() throws Exception {
val actual = '''
R: F1 F2;
fragment F1: f1=ID;
@ -448,7 +448,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testFragmentLoop() {
@Test def void testFragmentLoop() throws Exception {
val actual = '''
R: F+;
fragment F: f+=ID;
@ -463,7 +463,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
@Test def void testParameterizedDoubleDelegation() {
@Test def void testParameterizedDoubleDelegation() throws Exception {
val actual = '''
R: F<true> | F<false>;
fragment F<X>: f+=ID;
@ -480,7 +480,7 @@ class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual)
}
def private String toPda(CharSequence rulesText) {
def private String toPda(CharSequence rulesText) throws Exception {
val grammar = parser.parse('''
grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals
@ -510,7 +510,7 @@ class GrammarPDAProviderTest {
}
}
def protected toDot(Pda<ISerState, RuleCall> pda, String name) {
def protected toDot(Pda<ISerState, RuleCall> pda, String name) throws Exception {
val test = Thread.currentThread.stackTrace.get(6).methodName
new PdaToDot().draw(pda, "dot2/" + test + "_" + name + ".pdf", "-T pdf")

View file

@ -0,0 +1,264 @@
/**
* Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.serializer;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Entity;
import org.eclipse.xtext.serializer.hiddentokensequencertest.HiddentokensequencertestFactory;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.util.Strings;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
/**
* @author Stefan Oehme - Initial contribution and API
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424027
*/
@RunWith(XtextRunner.class)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider.class)
public class SerializationAfterModelChangeTest {
@Inject
private ParseHelper<Model> parseHelper;
@Inject
private ISerializer serializer;
@Test
public void smokeTest() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" //before existing element\n" +
" Foo /* within existing element */ \"Bar\" /* after existing element*/\n" +
" \n" +
" //unrelated comment\n" +
" \n" +
" //before deleted element\n" +
" Baz \"Fizzle\" /* after deleted element */\n" +
" \n" +
" //between deleted elements\n" +
" \n" +
" //another deleted element\n" +
" Blurb /* a comment within a deleted element */ \"Bla\"\n" +
" \n" +
" //before inserted element\n" +
"end\n");
Entity event = HiddentokensequencertestFactory.eINSTANCE.createEntity();
event.setName("AAA");
event.setDescription("BBB");
model.getDomainModel().getEntities().remove(1);
model.getDomainModel().getEntities().remove(1);
model.getDomainModel().getEntities().add(event);
assertSerializesTo(model,
"entities\n" +
" //before existing element\n" +
" Foo /* within existing element */ \"Bar\" /* after existing element*/\n" +
" \n" +
" //unrelated comment\n" +
" \n" +
" \n" +
" \n" +
" //between deleted elements\n" +
" \n" +
" \n" +
" \n" +
" //before inserted element\n" +
"AAA \"BBB\" end");
}
/**
* TODO does not work yet, because HiddenTokenSequencer always searches in
* one direction, but the order of the elements has changed here.
*/
@Test
@Ignore
public void testMoveElement() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\"\n" +
"\n //comment between elements\n" +
" \n" +
" Baz \"Fizzle\"\n" +
"end\n");
Entity head = Iterables.getFirst(model.getDomainModel().getEntities(), null);
model.getDomainModel().getEntities().move(1, head);
assertSerializesTo(model,
"entities\n" +
" Baz \"Fizzle\"\n" +
"\n //comment between elements\n" +
" \n" +
" Foo \"Bar\"\n" +
"end\n");
}
@Test
public void testWhiteSpaceOnly() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\"\n" +
"end\n");
Entity event = HiddentokensequencertestFactory.eINSTANCE.createEntity();
event.setName("Baz");
event.setDescription("Fizzle");
model.getDomainModel().getEntities().add(event);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\"\n" +
"Baz \"Fizzle\" end");
}
@Test
public void testCommentBeforeInsertedElement() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" //comment before inserted element\n" +
"end\n");
Entity event = HiddentokensequencertestFactory.eINSTANCE.createEntity();
event.setName("Baz");
event.setDescription("Fizzle");
model.getDomainModel().getEntities().add(event);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" //comment before inserted element\n" +
"Baz \"Fizzle\" end");
}
@Test
public void testAddElementAfterInlineComment() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\" //inline comment before inserted element\n" +
"end\n");
Entity event = HiddentokensequencertestFactory.eINSTANCE.createEntity();
event.setName("Baz");
event.setDescription("Fizzle");
model.getDomainModel().getEntities().add(event);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\" //inline comment before inserted element\n" +
"Baz \"Fizzle\" end");
}
@Test
public void testCommentOnRemovedElement() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\" //inline comment before deleted element\n" +
" //comment on deleted element\n" +
" /**\n" +
" * another comment on the deleted element\n" +
" */\n" +
" Baz \"Fizzle\"\n" +
"end\n");
model.getDomainModel().getEntities().remove(1);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\" //inline comment before deleted element\n" +
"\nend");
}
@Test
public void testUnrelatedCommentBeforeRemovedElement() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" //unrelated comment before deleted element\n" +
" \n" +
" Baz \"Fizzle\"\n" +
"end\n");
model.getDomainModel().getEntities().remove(1);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" //unrelated comment before deleted element\n" +
" \n" +
" \n" +
"end");
}
@Test
public void testRemoveElementAfterInlineComment() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\" //inline comment before deleted element\n" +
" \n" +
" Baz \"Fizzle\"\n" +
"end\n");
model.getDomainModel().getEntities().remove(1);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\" //inline comment before deleted element\n" +
" \n" +
" \n" +
"end");
}
@Test
public void testRemoveElementWithInlineComment() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" Baz \"Fizzle\" //inline comment after deleted element\n" +
"end\n");
model.getDomainModel().getEntities().remove(1);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\"\n" +
" \n" +
" end");
}
@Test
public void testRemoveElementInSameLine() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" Foo \"Bar\" /* the foo */ Baz \"Fizzle\"\n" +
"end\n");
model.getDomainModel().getEntities().remove(1);
assertSerializesTo(model,
"entities\n" +
" Foo \"Bar\" /* the foo */\n" +
"end");
}
@Test
public void testAddElementBeforeCommentedElement() throws Exception {
Model model = parseHelper.parse(
"entities\n" +
" //the comment\n" +
" Foo \"Bar\"\n" +
"end\n");
Entity event = HiddentokensequencertestFactory.eINSTANCE.createEntity();
event.setName("Baz");
event.setDescription("Fizzle");
model.getDomainModel().getEntities().add(0, event);
assertSerializesTo(model,
"entities Baz \"Fizzle\"\n" +
" //the comment\n" +
" Foo \"Bar\"\n" +
"end\n");
}
private void assertSerializesTo(Model model, CharSequence expectation) {
Assert.assertEquals(expectation.toString(), Strings.toUnixLineSeparator(serializer.serialize(model)));
}
}

View file

@ -1,313 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.serializer
import com.google.inject.Inject
import org.eclipse.xtext.serializer.hiddentokensequencertest.HiddentokensequencertestFactory
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
/**
* @author Stefan Oehme - Initial contribution and API
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424027
*/
@RunWith(XtextRunner)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider)
class SerializationAfterModelChangeTest {
@Inject extension ParseHelper<Model>
@Inject extension ISerializer
@Test
def void smokeTest() {
val model = '''
entities
//before existing element
Foo /* within existing element */ "Bar" /* after existing element*/
//unrelated comment
//before deleted element
Baz "Fizzle" /* after deleted element */
//between deleted elements
//another deleted element
Blurb /* a comment within a deleted element */ "Bla"
//before inserted element
end
'''.parse
val event = HiddentokensequencertestFactory.eINSTANCE.createEntity => [
name = "AAA"
description = "BBB"
]
model.domainModel.entities.remove(1)
model.domainModel.entities.remove(1)
model.domainModel.entities.add(event)
model.assertSerializesTo(
'''
entities
//before existing element
Foo /* within existing element */ "Bar" /* after existing element*/
//unrelated comment
//between deleted elements
//before inserted element
AAA "BBB" end''')
}
/*
* TODO does not work yet, because HiddenTokenSequencer
* always searches in one direction,
* but the order of the elements has changed here.
*/
@Test
@Ignore
def void testMoveElement() {
val model = '''
entities
Foo "Bar"
//comment between elements
Baz "Fizzle"
end
'''.parse
val head = model.domainModel.entities.head
model.domainModel.entities.move(1, head)
model.assertSerializesTo(
'''
entities
Baz "Fizzle"
//comment between elements
Foo "Bar"
end
''')
}
@Test
def void testWhiteSpaceOnly() {
val model = '''
entities
Foo "Bar"
end
'''.parse
val event = HiddentokensequencertestFactory.eINSTANCE.createEntity => [
name = "Baz"
description = "Fizzle"
]
model.domainModel.entities.add(event)
model.assertSerializesTo(
'''
entities
Foo "Bar"
Baz "Fizzle" end''')
}
@Test
def void testCommentBeforeInsertedElement() {
val model = '''
entities
Foo "Bar"
//comment before inserted element
end
'''.parse
val event = HiddentokensequencertestFactory.eINSTANCE.createEntity => [
name = "Baz"
description = "Fizzle"
]
model.domainModel.entities.add(event)
model.assertSerializesTo(
'''
entities
Foo "Bar"
//comment before inserted element
Baz "Fizzle" end''')
}
@Test
def void testAddElementAfterInlineComment() {
val model = '''
entities
Foo "Bar" //inline comment before inserted element
end
'''.parse
val event = HiddentokensequencertestFactory.eINSTANCE.createEntity => [
name = "Baz"
description = "Fizzle"
]
model.domainModel.entities.add(event)
model.assertSerializesTo(
'''
entities
Foo "Bar" //inline comment before inserted element
Baz "Fizzle" end''')
}
@Test
def void testCommentOnRemovedElement() {
val model = '''
entities
Foo "Bar" //inline comment before deleted element
//comment on deleted element
/**
* another comment on the deleted element
*/
Baz "Fizzle"
end
'''.parse
model.domainModel.entities.remove(1)
model.assertSerializesTo(
'''
entities
Foo "Bar" //inline comment before deleted element
end''')
}
@Test
def void testUnrelatedCommentBeforeRemovedElement() {
val model = '''
entities
Foo "Bar"
//unrelated comment before deleted element
Baz "Fizzle"
end
'''.parse
model.domainModel.entities.remove(1)
model.assertSerializesTo(
'''
entities
Foo "Bar"
//unrelated comment before deleted element
end''')
}
@Test
def void testRemoveElementAfterInlineComment() {
val model = '''
entities
Foo "Bar" //inline comment before deleted element
Baz "Fizzle"
end
'''.parse
model.domainModel.entities.remove(1)
model.assertSerializesTo(
'''
entities
Foo "Bar" //inline comment before deleted element
end''')
}
@Test
def void testRemoveElementWithInlineComment() {
val model = '''
entities
Foo "Bar"
Baz "Fizzle" //inline comment after deleted element
end
'''.parse
model.domainModel.entities.remove(1)
model.assertSerializesTo(
'''
entities
Foo "Bar"
end''')
}
@Test
def void testRemoveElementInSameLine() {
val model = '''
entities
Foo "Bar" /* the foo */ Baz "Fizzle"
end
'''.parse
model.domainModel.entities.remove(1)
model.assertSerializesTo(
'''
entities
Foo "Bar" /* the foo */
end''')
}
@Test
def void testAddElementBeforeCommentedElement() {
val model = '''
entities
//the comment
Foo "Bar"
end
'''.parse
val event = HiddentokensequencertestFactory.eINSTANCE.createEntity => [
name = "Baz"
description = "Fizzle"
]
model.domainModel.entities.add(0, event)
model.assertSerializesTo(
'''
entities Baz "Fizzle"
//the comment
Foo "Bar"
end
''')
}
private def assertSerializesTo(Model model, CharSequence expectation) {
assertEquals(expectation.toString, model.serialize)
}
}

View file

@ -0,0 +1,73 @@
/**
* Copyright (c) 2014, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.serializer;
import java.util.concurrent.TimeUnit;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Entity;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
* @author Stefan Oehme - Initial contribution and API
*/
@RunWith(XtextRunner.class)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider.class)
public class SerializerPerformanceTest {
@Inject
private ParseHelper<Model> parseHelper;
@Inject
private ISerializer serializer;
@Rule
public Timeout timeout = new Timeout(5000, TimeUnit.MILLISECONDS);
private static int numberOfElements = 1000;
private static int editEvery = 100;
private Model model;
@Before
public void setup() throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("entities\n");
for (int i = 0; i < numberOfElements; i++) {
builder.append(" //comment before element\n");
builder.append(" Foo /* comment between elements*/ \"Bar\" //comment after element \n");
}
builder.append("end\n");
model = parseHelper.parse(builder.toString());
EList<Entity> entities = model.getDomainModel().getEntities();
Iterable<Entity> removeUs = Iterables.transform(
Iterables.filter(new ExclusiveRange(0, SerializerPerformanceTest.numberOfElements, true),
it -> it.intValue() % SerializerPerformanceTest.editEvery == 0),
it -> entities.get(it.intValue()));
Iterables.removeAll(entities, Sets.newHashSet(removeUs));
}
@Test
public void test() {
serializer.serialize(model);
}
}

View file

@ -1,57 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.serializer
import com.google.inject.Inject
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit
/**
* @author Stefan Oehme - Initial contribution and API
*/
@RunWith(XtextRunner)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider)
class SerializerPerformanceTest {
@Inject extension ParseHelper<Model>
@Inject extension ISerializer
@Rule
public val Timeout timeout = new Timeout(5000, TimeUnit.MILLISECONDS)
static val numberOfElements = 1000
static val editEvery = 100
var Model model
@Before
def void setup() {
model = '''
entities
«FOR i : 0 ..< numberOfElements»
//comment before element
Foo /* comment between elements*/ "Bar" //comment after element
«ENDFOR»
end
'''.parse
val entities = model.domainModel.entities
val removeUs = (0 ..< numberOfElements).filter[it % editEvery == 0].map[entities.get(it)]
entities.removeAll(removeUs)
}
@Test
def void test() {
model.serialize
}
}

View file

@ -1,551 +0,0 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.generator.parser;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.parser.AntlrGrammarComparatorTestHelper;
import org.eclipse.xtext.xbase.lib.Extension;
import org.junit.Test;
/**
* Contributes unit tests for {@link AntlrGrammarComparator}.
*
* @author Christian Schneider - Initial contribution and API
*/
@SuppressWarnings("all")
public class AntlrGrammarComparatorTest {
@Extension
private AntlrGrammarComparatorTestHelper _antlrGrammarComparatorTestHelper = new AntlrGrammarComparatorTestHelper();
/**
* The pattern of "\"" is not expected to occur in ANTLR grammar,
* so I use it for testing the unmatched token check.
*/
@Test(expected = AssertionError.class)
public void unmatchedTokens01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"\\\"\"a");
_builder.newLine();
final String testee = _builder.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test
public void stringMatch_00a() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_00b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_01a() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hugo");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void stringMatch_01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hugo");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_01a() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hugo hans");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hugo hans");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_02a() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hugo");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_02b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hugo");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_03a() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_03b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_04() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hu");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hugo");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void stringMismatch_05() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans hugo");
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans hu");
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("RULE_IN_RICH_STRING?");
_builder.newLine();
final String expected = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("RULE_IN_RICH_STRING ?");
_builder_1.newLine();
final String testee = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("RULE_IN_RICH_STRING*");
_builder.newLine();
final String expected = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("RULE_IN_RICH_STRING *");
_builder_1.newLine();
final String testee = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void regExMatch03() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("RULE_IN_RICH_STRING+");
_builder.newLine();
final String expected = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("RULE_IN_RICH_STRING +");
_builder_1.newLine();
final String testee = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void snippetMatch01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar InternalStatemachine;");
_builder.newLine();
_builder.append("options {");
_builder.newLine();
_builder.append("\t");
_builder.append("superClass=AbstractInternalAntlrParser;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String expected = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("grammar InternalStatemachine ;");
_builder_1.newLine();
_builder_1.append("options{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("superClass = AbstractInternalAntlrParser");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append(";");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String testee = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void snippetMatch02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("((\t\'abstract\' ");
_builder.newLine();
_builder.append(" ");
_builder.append("| \t\'annotation\' ");
_builder.newLine();
_builder.append(" ");
_builder.append("| \t\'class\' ");
_builder.newLine();
_builder.append(" ");
_builder.append("| \t\'(\' ");
_builder.newLine();
_builder.append(" ");
_builder.append("| RULE_ID | \tRULE_HEX )");
_builder.newLine();
final String expected = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("(");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("(\'abstract\' | \'annotation\' | \'class\' | \'(\' | RULE_ID | RULE_HEX )");
_builder_1.newLine();
final String testee = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void matchAllTokens01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("RULE_RICH_TEXT : \'\\\'\\\'\\\'\' RULE_IN_RICH_STRING* (\'\\\'\\\'\\\'\'|(\'\\\'\' \'\\\'\'?)? EOF);");
_builder.newLine();
final String testee = _builder.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test
public void matchAllTokens02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("RULE_RICH_TEXT_START : \'\\\'\\\'\\\'\' RULE_IN_RICH_STRING* (\'\\\'\' \'\\\'\'?)? \'\\u00AB\';");
_builder.newLine();
_builder.newLine();
_builder.append("RULE_RICH_TEXT_END : \'\\u00BB\' RULE_IN_RICH_STRING* (\'\\\'\\\'\\\'\'|(\'\\\'\' \'\\\'\'?)? EOF);");
_builder.newLine();
_builder.newLine();
_builder.append("RULE_RICH_TEXT_INBETWEEN : \'\\u00BB\' RULE_IN_RICH_STRING* (\'\\\'\' \'\\\'\'?)? \'\\u00AB\';");
_builder.newLine();
_builder.newLine();
_builder.append("RULE_COMMENT_RICH_TEXT_INBETWEEN : \'\\u00AB\\u00AB\' ~((\'\\n\'|\'\\r\'))* (\'\\r\'? \'\\n\' RULE_IN_RICH_STRING* (\'\\\'\' \'\\\'\'?)? \'\\u00AB\')?;");
_builder.newLine();
_builder.newLine();
_builder.append("RULE_COMMENT_RICH_TEXT_END : \'\\u00AB\\u00AB\' ~((\'\\n\'|\'\\r\'))* (\'\\r\'? \'\\n\' RULE_IN_RICH_STRING* (\'\\\'\\\'\\\'\'|(\'\\\'\' \'\\\'\'?)? EOF)|EOF);");
_builder.newLine();
final String testee = _builder.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, testee);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans ( ( hugo )");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans ( hugo )");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hans ( hugo ) )");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hans ( hugo )");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses03() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{ \'(\' ( \')\' }");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("{ \'(\' \')\' }");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test(expected = AssertionError.class)
public void mismatchOfParantheses04() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{ \'(\' \'( \')\' }");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("{ \'(\' \'(\' \')\' }");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void sLCommentIgnoring01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("// rule B");
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("B: \'B\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void sLCommentIgnoring01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("// rule B");
_builder_1.newLine();
_builder_1.append("B: \'B\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mismatchWithSLComment01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("// rule B");
_builder_1.newLine();
_builder_1.append("B: \'C\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 4);
}
@Test(expected = AssertionError.class)
public void mismatchWithSLComment01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("// rule B");
_builder_1.newLine();
_builder_1.append("B: \'C\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 4, 4);
}
@Test
public void mLCommentIgnoring01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* rule B");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("B: \'B\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mLCommentIgnoring01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("/*");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* rule B");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("*/");
_builder_1.newLine();
_builder_1.append("B: \'B\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compare(testee, expected);
}
@Test
public void mismatchWithMLComment01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("/*");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* rule B");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("*/");
_builder_1.newLine();
_builder_1.append("B: \'C\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 6);
}
@Test(expected = AssertionError.class)
public void mismatchWithMLComment01b() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("A: \'A\'");
_builder.newLine();
_builder.newLine();
_builder.append("B: \'B\'");
_builder.newLine();
final String testee = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("A: \'A\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("/*");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* rule B");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("*/");
_builder_1.newLine();
_builder_1.append("B: \'C\'");
_builder_1.newLine();
final String expected = _builder_1.toString();
this._antlrGrammarComparatorTestHelper.compareAndExpectMismatchInLines(testee, expected, 3, 5);
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -33,7 +33,6 @@ import org.eclipse.xtext.util.formallang.NfaUtil;
import org.eclipse.xtext.util.formallang.Pda;
import org.eclipse.xtext.util.formallang.PdaListFormatter;
import org.eclipse.xtext.util.formallang.PdaToDot;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@ -59,7 +58,7 @@ public class GrammarPDAProviderTest {
private ValidationTestHelper validator;
@Test
public void testUnassignedAction() {
public void testUnassignedAction() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Action};");
_builder.newLine();
@ -78,7 +77,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testAssignedAction() {
public void testAssignedAction() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Foo} {Action.feat=current};");
_builder.newLine();
@ -100,7 +99,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testAssignedTerminalRuleCall() {
public void testAssignedTerminalRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: name=ID;");
_builder.newLine();
@ -119,7 +118,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testAssignedEObjectRuleCall() {
public void testAssignedEObjectRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: call=Called;");
_builder.newLine();
@ -148,7 +147,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testAssignedDatatypeRuleCall() {
public void testAssignedDatatypeRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: call=Called;");
_builder.newLine();
@ -169,7 +168,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedCalledAction() {
public void testUnassignedCalledAction() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: D1 | D2;");
_builder.newLine();
@ -290,7 +289,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedFragmentRuleCall() {
public void testUnassignedFragmentRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: Called;");
_builder.newLine();
@ -317,7 +316,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedDatatypeRule() {
public void testUnassignedDatatypeRule() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: val=ID Called;");
_builder.newLine();
@ -341,7 +340,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedTerminalRule() {
public void testUnassignedTerminalRule() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: val=ID Called;");
_builder.newLine();
@ -365,7 +364,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedParserRuleCall() {
public void testUnassignedParserRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: Called;");
_builder.newLine();
@ -400,7 +399,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnassignedWildcardFragmentRuleCall() {
public void testUnassignedWildcardFragmentRuleCall() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: Called;");
_builder.newLine();
@ -427,7 +426,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testGroup() {
public void testGroup() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Rule} \'a\' \'b\' \'c\';");
_builder.newLine();
@ -455,7 +454,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testAlternative() {
public void testAlternative() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Rule} (\'a\' | \'b\' | \'c\');");
_builder.newLine();
@ -483,7 +482,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnorderedGroup() {
public void testUnorderedGroup() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Rule} (\'a\' & \'b\' & \'c\');");
_builder.newLine();
@ -511,7 +510,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testUnorderedGroup2() {
public void testUnorderedGroup2() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: {Rule} (\'a\' & \'b\'? & \'c\'* & \'d\'+);");
_builder.newLine();
@ -542,7 +541,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testTwoAssignedEObjectRuleCalls() {
public void testTwoAssignedEObjectRuleCalls() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Rule: foo1=Sub foo2=Sub; Sub: id=\'id\';");
_builder.newLine();
@ -572,7 +571,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testRecursion() {
public void testRecursion() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Recursion: val=ID | \'(\' Recursion \')\';");
_builder.newLine();
@ -603,7 +602,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testExpression1() {
public void testExpression1() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Exp: \'kw\' Addit; Addit returns Exp: Prim ({Add.left=current} \'+\' right=Prim)*; Prim returns Exp: {Val} val=ID;");
_builder.newLine();
@ -686,7 +685,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testActionAlternative() {
public void testActionAlternative() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Greeting: \'(\' Greeting \')\' {Foo.child=current} | val=ID;");
_builder.newLine();
@ -721,7 +720,7 @@ public class GrammarPDAProviderTest {
@Test
@Ignore
public void testFragmentWithAction() {
public void testFragmentWithAction() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("R: f1=ID F; fragment F returns R: {A.prev=current} f2=ID;");
_builder.newLine();
@ -753,7 +752,7 @@ public class GrammarPDAProviderTest {
@Test
@Ignore
public void testFragmentWithAction2() {
public void testFragmentWithAction2() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("R: \'kw1a\' f1=ID \'kw1b\' F; fragment F returns R: \'kw2a\' {A.prev=current} \'kw2b\' f2=ID \'kw2c\';");
_builder.newLine();
@ -784,7 +783,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testParameter1() {
public void testParameter1() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("M: \"kw1\" s=S<true> | \"kw2\" s=S<false>;");
_builder.newLine();
@ -830,7 +829,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testDoubleFragment() {
public void testDoubleFragment() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("R: F1 F2;");
_builder.newLine();
@ -868,7 +867,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testFragmentLoop() {
public void testFragmentLoop() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("R: F+;");
_builder.newLine();
@ -895,7 +894,7 @@ public class GrammarPDAProviderTest {
}
@Test
public void testParameterizedDoubleDelegation() {
public void testParameterizedDoubleDelegation() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("R: F<true> | F<false>;");
_builder.newLine();
@ -927,42 +926,38 @@ public class GrammarPDAProviderTest {
Assert.assertEquals(expected, actual);
}
private String toPda(final CharSequence rulesText) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.newLine();
_builder.append("generate GrammarPDAProviderTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarPDAProviderTestLanguage\"");
_builder.newLine();
_builder.newLine();
_builder.append(rulesText);
_builder.newLineIfNotEmpty();
final Grammar grammar = this.parser.parse(_builder);
this.validator.assertNoErrors(grammar);
final SerializationContextMap<Pda<ISerState, RuleCall>> pdas = this.pdaProvider.getGrammarPDAs(grammar);
final Consumer<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>> _function = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
this.assertNoLeakedGrammarElements(grammar, it.getValue());
};
pdas.values().forEach(_function);
final Function1<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>> _function_1 = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
return it.getContexts();
};
final Function1<ISerializationContext, String> _function_2 = (ISerializationContext it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(it);
_builder_1.append(":");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
String _listString = this.toListString(pdas.get(it));
_builder_1.append(_listString, "\t");
_builder_1.newLineIfNotEmpty();
return _builder_1.toString();
};
return IterableExtensions.join(ListExtensions.<ISerializationContext, String>map(IterableExtensions.<ISerializationContext>sort(Iterables.<ISerializationContext>concat(ListExtensions.<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>>map(pdas.values(), _function_1))), _function_2));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
private String toPda(final CharSequence rulesText) throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.newLine();
_builder.append("generate GrammarPDAProviderTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarPDAProviderTestLanguage\"");
_builder.newLine();
_builder.newLine();
_builder.append(rulesText);
_builder.newLineIfNotEmpty();
final Grammar grammar = this.parser.parse(_builder);
this.validator.assertNoErrors(grammar);
final SerializationContextMap<Pda<ISerState, RuleCall>> pdas = this.pdaProvider.getGrammarPDAs(grammar);
final Consumer<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>> _function = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
this.assertNoLeakedGrammarElements(grammar, it.getValue());
};
pdas.values().forEach(_function);
final Function1<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>> _function_1 = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
return it.getContexts();
};
final Function1<ISerializationContext, String> _function_2 = (ISerializationContext it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(it);
_builder_1.append(":");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
String _listString = this.toListString(pdas.get(it));
_builder_1.append(_listString, "\t");
_builder_1.newLineIfNotEmpty();
return _builder_1.toString();
};
return IterableExtensions.join(ListExtensions.<ISerializationContext, String>map(IterableExtensions.<ISerializationContext>sort(Iterables.<ISerializationContext>concat(ListExtensions.<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>>map(pdas.values(), _function_1))), _function_2));
}
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
@ -983,13 +978,9 @@ public class GrammarPDAProviderTest {
}
}
protected void toDot(final Pda<ISerState, RuleCall> pda, final String name) {
try {
final String test = (Thread.currentThread().getStackTrace()[6]).getMethodName();
new PdaToDot<Object, Object>().draw(pda, (((("dot2/" + test) + "_") + name) + ".pdf"), "-T pdf");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
protected void toDot(final Pda<ISerState, RuleCall> pda, final String name) throws Exception {
final String test = (Thread.currentThread().getStackTrace()[6]).getMethodName();
new PdaToDot<Object, Object>().draw(pda, (((("dot2/" + test) + "_") + name) + ".pdf"), "-T pdf");
}
private String toListString(final Pda<ISerState, RuleCall> pda) {

View file

@ -1,523 +0,0 @@
/**
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.serializer;
import com.google.inject.Inject;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.serializer.HiddenTokenSequencerTestLanguageInjectorProvider;
import org.eclipse.xtext.serializer.ISerializer;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Entity;
import org.eclipse.xtext.serializer.hiddentokensequencertest.HiddentokensequencertestFactory;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Stefan Oehme - Initial contribution and API
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424027
*/
@RunWith(XtextRunner.class)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider.class)
@SuppressWarnings("all")
public class SerializationAfterModelChangeTest {
@Inject
@Extension
private ParseHelper<Model> _parseHelper;
@Inject
@Extension
private ISerializer _iSerializer;
@Test
public void smokeTest() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("//before existing element");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo /* within existing element */ \"Bar\" /* after existing element*/");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//unrelated comment");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//before deleted element");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\" /* after deleted element */");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//between deleted elements");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//another deleted element");
_builder.newLine();
_builder.append("\t");
_builder.append("Blurb /* a comment within a deleted element */ \"Bla\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//before inserted element");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
final Procedure1<Entity> _function = (Entity it) -> {
it.setName("AAA");
it.setDescription("BBB");
};
final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
model.getDomainModel().getEntities().remove(1);
model.getDomainModel().getEntities().remove(1);
model.getDomainModel().getEntities().add(event);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//before existing element");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo /* within existing element */ \"Bar\" /* after existing element*/");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//unrelated comment");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//between deleted elements");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//before inserted element");
_builder_1.newLine();
_builder_1.append("AAA \"BBB\" end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
/**
* TODO does not work yet, because HiddenTokenSequencer
* always searches in one direction,
* but the order of the elements has changed here.
*/
@Test
@Ignore
public void testMoveElement() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("//comment between elements");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
final Entity head = IterableExtensions.<Entity>head(model.getDomainModel().getEntities());
model.getDomainModel().getEntities().move(1, head);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Baz \"Fizzle\"");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//comment between elements");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("end");
_builder_1.newLine();
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testWhiteSpaceOnly() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
final Procedure1<Entity> _function = (Entity it) -> {
it.setName("Baz");
it.setDescription("Fizzle");
};
final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
model.getDomainModel().getEntities().add(event);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("Baz \"Fizzle\" end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testCommentBeforeInsertedElement() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//comment before inserted element");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
final Procedure1<Entity> _function = (Entity it) -> {
it.setName("Baz");
it.setDescription("Fizzle");
};
final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
model.getDomainModel().getEntities().add(event);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//comment before inserted element");
_builder_1.newLine();
_builder_1.append("Baz \"Fizzle\" end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testAddElementAfterInlineComment() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"\t//inline comment before inserted element");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
final Procedure1<Entity> _function = (Entity it) -> {
it.setName("Baz");
it.setDescription("Fizzle");
};
final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
model.getDomainModel().getEntities().add(event);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"\t//inline comment before inserted element");
_builder_1.newLine();
_builder_1.append("Baz \"Fizzle\" end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testCommentOnRemovedElement() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\" //inline comment before deleted element");
_builder.newLine();
_builder.append("\t");
_builder.append("//comment on deleted element");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* another comment on the deleted element");
_builder.newLine();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
model.getDomainModel().getEntities().remove(1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\" //inline comment before deleted element");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testUnrelatedCommentBeforeRemovedElement() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("//unrelated comment before deleted element");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
model.getDomainModel().getEntities().remove(1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//unrelated comment before deleted element");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testRemoveElementAfterInlineComment() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\" //inline comment before deleted element");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
model.getDomainModel().getEntities().remove(1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\" //inline comment before deleted element");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testRemoveElementWithInlineComment() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("Baz \"Fizzle\" //inline comment after deleted element");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
model.getDomainModel().getEntities().remove(1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testRemoveElementInSameLine() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\" /* the foo */ Baz \"Fizzle\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
model.getDomainModel().getEntities().remove(1);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\" /* the foo */");
_builder_1.newLine();
_builder_1.append("end");
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void testAddElementBeforeCommentedElement() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
_builder.append("\t");
_builder.append("//the comment");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo \"Bar\"");
_builder.newLine();
_builder.append("end");
_builder.newLine();
final Model model = this._parseHelper.parse(_builder);
Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
final Procedure1<Entity> _function = (Entity it) -> {
it.setName("Baz");
it.setDescription("Fizzle");
};
final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
model.getDomainModel().getEntities().add(0, event);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entities Baz \"Fizzle\"");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("//the comment");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo \"Bar\"");
_builder_1.newLine();
_builder_1.append("end");
_builder_1.newLine();
this.assertSerializesTo(model, _builder_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
private void assertSerializesTo(final Model model, final CharSequence expectation) {
Assert.assertEquals(expectation.toString(), this._iSerializer.serialize(model));
}
}

View file

@ -1,96 +0,0 @@
/**
* Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.serializer;
import com.google.inject.Inject;
import java.util.concurrent.TimeUnit;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.serializer.HiddenTokenSequencerTestLanguageInjectorProvider;
import org.eclipse.xtext.serializer.ISerializer;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Entity;
import org.eclipse.xtext.serializer.hiddentokensequencertest.Model;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.CollectionExtensions;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
/**
* @author Stefan Oehme - Initial contribution and API
*/
@RunWith(XtextRunner.class)
@InjectWith(HiddenTokenSequencerTestLanguageInjectorProvider.class)
@SuppressWarnings("all")
public class SerializerPerformanceTest {
@Inject
@Extension
private ParseHelper<Model> _parseHelper;
@Inject
@Extension
private ISerializer _iSerializer;
@Rule
public final Timeout timeout = new Timeout(5000, TimeUnit.MILLISECONDS);
private static final int numberOfElements = 1000;
private static final int editEvery = 100;
private Model model;
@Before
public void setup() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entities");
_builder.newLine();
{
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, SerializerPerformanceTest.numberOfElements, true);
for(final Integer i : _doubleDotLessThan) {
_builder.append("\t");
_builder.append("//comment before element");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo /* comment between elements*/ \"Bar\" //comment after element ");
_builder.newLine();
}
}
_builder.append("end");
_builder.newLine();
this.model = this._parseHelper.parse(_builder);
final EList<Entity> entities = this.model.getDomainModel().getEntities();
final Function1<Integer, Boolean> _function = (Integer it) -> {
return Boolean.valueOf((((it).intValue() % SerializerPerformanceTest.editEvery) == 0));
};
final Function1<Integer, Entity> _function_1 = (Integer it) -> {
return entities.get((it).intValue());
};
final Iterable<Entity> removeUs = IterableExtensions.<Integer, Entity>map(IterableExtensions.<Integer>filter(new ExclusiveRange(0, SerializerPerformanceTest.numberOfElements, true), _function), _function_1);
CollectionExtensions.<Entity>removeAll(entities, removeUs);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
@Test
public void test() {
this._iSerializer.serialize(this.model);
}
}