Skip to main content
summaryrefslogtreecommitdiffstats
blob: 94e9966b8faf7981d070e1641435074429c93e12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
		}
	}
}

Back to the top