Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Ratz2020-05-21 13:59:58 +0000
committerAlexander Kurtakov2020-05-26 09:15:48 +0000
commitc1c0584eb16f514a3d589e3639afe2ff5443583a (patch)
treefd5a594060d236bdaca3b7073eeb51e0f95555c6
parent211edf5b44906abd0499473dce60f359ee030729 (diff)
downloadeclipse.platform.text-c1c0584eb16f514a3d589e3639afe2ff5443583a.tar.gz
eclipse.platform.text-c1c0584eb16f514a3d589e3639afe2ff5443583a.tar.xz
eclipse.platform.text-c1c0584eb16f514a3d589e3639afe2ff5443583a.zip
Add initial set of tests regarding underscore handling in typical programming language kind of words. Change-Id: I25eb171c0bcf7af1a02b0aa70b0965d7fc2cd39d
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultTextDoubleClickStrategyTest.java51
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java2
2 files changed, 53 insertions, 0 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultTextDoubleClickStrategyTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultTextDoubleClickStrategyTest.java
new file mode 100644
index 000000000..94e9966b8
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultTextDoubleClickStrategyTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2020 SAP SE and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * SAP SE - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class DefaultTextDoubleClickStrategyTest {
+
+ @Test
+ public void testUnderscoreHandling() throws Exception {
+ String content= "foo_bar foo__bar foo_1 foo1_bar foo_bar__baz___1 __aaaa a_aa___a _asdf_ _____1";
+ IDocument document= new Document(content);
+ TestSpecificDefaultTextDoubleClickStrategy doubleClickStrategy= new TestSpecificDefaultTextDoubleClickStrategy();
+
+ for (String word : content.split(" ")) {
+ int offsetWordStart= content.indexOf(word);
+ for (int offset= offsetWordStart; offset < offsetWordStart + word.length(); offset++) {
+ IRegion selection= doubleClickStrategy.findWord(document, offset);
+ String actualWord= document.get(selection.getOffset(), selection.getLength());
+
+ assertEquals(word, actualWord);
+ }
+ }
+ }
+
+ private static final class TestSpecificDefaultTextDoubleClickStrategy extends DefaultTextDoubleClickStrategy {
+
+ @Override
+ public IRegion findWord(IDocument document, int offset) { // make visible
+ return super.findWord(document, offset);
+ }
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
index 08104d53c..05f39a73d 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
@@ -71,6 +71,8 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
CodeMiningProjectionViewerTest.class,
TabsToSpacesConverterTest.class,
+
+ DefaultTextDoubleClickStrategyTest.class,
})
public class JFaceTextTestSuite {
// see @SuiteClasses

Back to the top