Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2018-07-06 08:56:24 -0400
committerHenrik Rentz-Reichert2018-07-06 11:53:18 -0400
commite93813322f3616c94f86f41e2a36aef0e46f9285 (patch)
tree5612ee093f7790c47a53e21bd1ddf293b0cea27b /tests
parent450ecd35bff741f7ba4568c53a80b80b618b5312 (diff)
downloadorg.eclipse.etrice-e93813322f3616c94f86f41e2a36aef0e46f9285.tar.gz
org.eclipse.etrice-e93813322f3616c94f86f41e2a36aef0e46f9285.tar.xz
org.eclipse.etrice-e93813322f3616c94f86f41e2a36aef0e46f9285.zip
Bug 536769 - [room.ui] Use new DC tools for content assist
proposal provider based on DCTools (incomplete and not used yet) - no tests yet - not active yet in RoomProposalProvider.java Change-Id: Icd74d023029e229519b067844e001254fca4d5cc
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestConstants.xtend2
-rw-r--r--tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCNodeAtOffset.xtend104
-rw-r--r--tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCParser.xtend8
-rw-r--r--tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCScanner.xtend4
4 files changed, 111 insertions, 7 deletions
diff --git a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestConstants.xtend b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestConstants.xtend
index 8a38916a8..34894c598 100644
--- a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestConstants.xtend
+++ b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestConstants.xtend
@@ -32,7 +32,7 @@ interface TestConstants {
static val TEST_MEMBER_ACCESS = "field.member"
static val TEST_ARRAY_MEMBER_ACCESS = "field[1+2].member"
static val TEST_ARRAY_MEMBER_ACCESS_AND_CALL = TEST_ARRAY_MEMBER_ACCESS + ".op()"
- static val TEST_SPACY_ARRAY_MEMBER_ACCESS_AND_CALL = "field [ 1 + 2 ]\n\t. member . op ( )"
+ static val TEST_SPACIOUS_ARRAY_MEMBER_ACCESS_AND_CALL = "field [ 1 + 2 ]\n\t. member . op ( )"
static val TEST_CODE = "DC var = new DC(); port.message(var);"
static val TEST_CODE1 = "field.member1.member2[3].operation(x+4)"
static val TEST_CODE2 = '''
diff --git a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCNodeAtOffset.xtend b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCNodeAtOffset.xtend
new file mode 100644
index 000000000..6b52257c5
--- /dev/null
+++ b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCNodeAtOffset.xtend
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.dctools.tests
+
+import org.eclipse.etrice.dctools.fsm.ast.DCParser
+import org.junit.Before
+import org.eclipse.etrice.dctools.fsm.ast.DCLanguage
+import static org.eclipse.etrice.dctools.tests.TestConstants.*
+import org.junit.Test
+import org.eclipse.etrice.dctools.fsm.ast.DCNodeAtOffset
+import static org.junit.Assert.*
+import static org.hamcrest.CoreMatchers.*
+import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstOtherNode
+import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstIdentifierNode
+import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstBracketNode
+
+class TestDCNodeAtOffset {
+
+ DCParser parser
+
+ @Before
+ def void createParser() {
+ parser = new DCParser(DCLanguage.C_LANGUAGE)
+ }
+
+ @Test
+ def void testString() {
+ val ast = parser.parse(TEST_STRING)
+ val result = DCNodeAtOffset.find(ast, 3)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstOtherNode)
+ assertThat(result.text, is(TEST_STRING))
+ }
+
+ @Test
+ def void testMemberAccess() {
+ val ast = parser.parse(TEST_MEMBER_ACCESS)
+ var result = DCNodeAtOffset.find(ast, 8)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstIdentifierNode)
+ assertThat(result.text, is("member"))
+
+ result = DCNodeAtOffset.find(ast, 4)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstIdentifierNode)
+ assertThat(result.text, is("field"))
+ }
+
+ @Test
+ def void testArrayMemberAccess() {
+ val ast = parser.parse(TEST_ARRAY_MEMBER_ACCESS)
+ var result = DCNodeAtOffset.find(ast, 14)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstIdentifierNode)
+ assertThat(result.text, is("member"))
+
+ result = DCNodeAtOffset.find(ast, 4)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstIdentifierNode)
+ assertThat(result.text, is("field"))
+
+ result = DCNodeAtOffset.find(ast, 7)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstOtherNode)
+ assertThat(result.text, is("+"))
+ }
+
+ @Test
+ def void testCode() {
+ val ast = parser.parse(TEST_CODE)
+ var result = DCNodeAtOffset.find(ast, 16)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstBracketNode)
+ if (result instanceof DCAstBracketNode) {
+ assertThat(result.text, is("()"))
+ assertThat(result.begin, is(15))
+ assertThat(result.end, is(16))
+ assertThat(result.posClose, is(16))
+ }
+ }
+
+ @Test
+ def void testCode2() {
+ val ast = parser.parse(TEST_CODE2)
+
+ // note: because line breaks differ on UNIX and Windows we can't use a constant offset here
+ val pos = TEST_CODE2.indexOf("456")+2
+
+ var result = DCNodeAtOffset.find(ast, pos)
+ assertNotNull(result)
+ assertTrue(result instanceof DCAstOtherNode)
+ assertThat(result.text, is("456"))
+ }
+}
diff --git a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCParser.xtend b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCParser.xtend
index df0e392ab..b9e944961 100644
--- a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCParser.xtend
+++ b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCParser.xtend
@@ -149,7 +149,7 @@ class TestDCParser {
// it is an identifier node
node = node.children.get(0)
assertTrue(node instanceof DCAstIdentifierNode)
- assertThat((node as DCAstIdentifierNode).identifier, is(TEST_IDENTIFIER))
+ assertThat((node as DCAstIdentifierNode).id, is(TEST_IDENTIFIER))
prettyPrint("testIdentifier", TEST_IDENTIFIER, result, 1, 3)
}
@@ -257,11 +257,11 @@ class TestDCParser {
}
@Test
- def void testSpacyArrayMemberAccessAndCall() {
- val result = parser.parse(TEST_SPACY_ARRAY_MEMBER_ACCESS_AND_CALL)
+ def void testSpaciousArrayMemberAccessAndCall() {
+ val result = parser.parse(TEST_SPACIOUS_ARRAY_MEMBER_ACCESS_AND_CALL)
assertNotNull(result)
- prettyPrint("testSpacyArrayMemberAccessAndCall", TEST_SPACY_ARRAY_MEMBER_ACCESS_AND_CALL, result, 23, 27)
+ prettyPrint("testSpacyArrayMemberAccessAndCall", TEST_SPACIOUS_ARRAY_MEMBER_ACCESS_AND_CALL, result, 23, 27)
}
@Test
diff --git a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCScanner.xtend b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCScanner.xtend
index 8f164b578..f28da318b 100644
--- a/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCScanner.xtend
+++ b/tests/org.eclipse.etrice.dctools.tests/src/org/eclipse/etrice/dctools/tests/TestDCScanner.xtend
@@ -166,8 +166,8 @@ class TestDCScanner {
}
@Test
- def void testSpacyArrayMemberAccessAndCall() {
- val tokens = scanner.scan(TEST_SPACY_ARRAY_MEMBER_ACCESS_AND_CALL)
+ def void testSpaciousArrayMemberAccessAndCall() {
+ val tokens = scanner.scan(TEST_SPACIOUS_ARRAY_MEMBER_ACCESS_AND_CALL)
assertThat(tokens.size, is(23))
var pos = 0

Back to the top