@@ -55,6 +55,113 @@ public void testClickAtLineEnd() throws Exception {
5555 assertEquals ("you" , document .get (selection .getOffset (), selection .getLength ()), "Unexpected selection" );
5656 }
5757
58+ @ Test
59+ public void testClickJustPastIdentifierSelectsThatIdentifier () throws Exception {
60+ String content = "foo bar baz" ;
61+ IDocument document = new Document (content );
62+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
63+ // Click at offset 3: the space right after "foo".
64+ IRegion selection = strategy .findWord (document , 3 );
65+ assertNotNull (selection );
66+ assertEquals ("foo" , document .get (selection .getOffset (), selection .getLength ()));
67+ }
68+
69+ @ Test
70+ public void testClickAtIdentifierStartSelectsWholeIdentifier () throws Exception {
71+ String content = "foo __aaaa bar" ;
72+ IDocument document = new Document (content );
73+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
74+ // Click at offset 4: the first '_' starting "__aaaa".
75+ IRegion selection = strategy .findWord (document , 4 );
76+ assertNotNull (selection );
77+ assertEquals ("__aaaa" , document .get (selection .getOffset (), selection .getLength ()));
78+ }
79+
80+ @ Test
81+ public void testIdentifierAtLineStartAndEnd () throws Exception {
82+ String content = "_foo___\n bar_baz" ;
83+ IDocument document = new Document (content );
84+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
85+ // First line: every offset 0..7 should yield "_foo___".
86+ for (int offset = 0 ; offset <= 7 ; offset ++) {
87+ IRegion selection = strategy .findWord (document , offset );
88+ assertNotNull (selection , "no selection at offset " + offset );
89+ assertEquals ("_foo___" , document .get (selection .getOffset (), selection .getLength ()),
90+ "unexpected selection at offset " + offset );
91+ }
92+ // Second line.
93+ IRegion selection = strategy .findWord (document , 11 );
94+ assertNotNull (selection );
95+ assertEquals ("bar_baz" , document .get (selection .getOffset (), selection .getLength ()));
96+ }
97+
98+ @ Test
99+ public void testSingleLineDocument () throws Exception {
100+ String content = "abc" ;
101+ IDocument document = new Document (content );
102+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
103+ IRegion selection = strategy .findWord (document , 0 );
104+ assertNotNull (selection );
105+ assertEquals ("abc" , document .get (selection .getOffset (), selection .getLength ()));
106+ selection = strategy .findWord (document , document .getLength ());
107+ assertNotNull (selection );
108+ assertEquals ("abc" , document .get (selection .getOffset (), selection .getLength ()));
109+ }
110+
111+ @ Test
112+ public void testIdentifierSurroundedByPunctuation () throws Exception {
113+ String content = "(foo_bar);" ;
114+ IDocument document = new Document (content );
115+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
116+ // Click in the middle of the identifier.
117+ IRegion selection = strategy .findWord (document , 4 );
118+ assertNotNull (selection );
119+ assertEquals ("foo_bar" , document .get (selection .getOffset (), selection .getLength ()));
120+ }
121+
122+ @ Test
123+ public void testCjkWordSelection () throws Exception {
124+ // Japanese text without spaces. The word break iterator segments it into a
125+ // Hiragana run ("こんにちは") followed by a Kanji run
126+ // ("世界"). This segmentation is locale-independent, so double-click
127+ // selects the script run the click lands in rather than the whole line.
128+ String content = "こんにちは世界" ;
129+ IDocument document = new Document (content );
130+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
131+ // Click inside the Hiragana run.
132+ IRegion selection = strategy .findWord (document , 2 );
133+ assertNotNull (selection );
134+ assertEquals ("こんにちは" , document .get (selection .getOffset (), selection .getLength ()));
135+ // Click inside the Kanji run.
136+ selection = strategy .findWord (document , 6 );
137+ assertNotNull (selection );
138+ assertEquals ("世界" , document .get (selection .getOffset (), selection .getLength ()));
139+ }
140+
141+ @ Test
142+ public void testCjkTokenBetweenSpaces () throws Exception {
143+ String content = "foo 我是 bar" ;
144+ IDocument document = new Document (content );
145+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
146+ // Click inside the CJK token.
147+ IRegion selection = strategy .findWord (document , 5 );
148+ assertNotNull (selection );
149+ assertEquals ("我是" , document .get (selection .getOffset (), selection .getLength ()));
150+ }
151+
152+ @ Test
153+ public void testThaiTokenBetweenSpaces () throws Exception {
154+ // Dictionary-based segmentation of a contiguous Thai run only happens under a
155+ // Thai locale, so this test delimits the token with spaces to stay
156+ // locale-independent: double-click selects the whole Thai token.
157+ String content = "foo ไทย bar" ;
158+ IDocument document = new Document (content );
159+ TestSpecificDefaultTextDoubleClickStrategy strategy = new TestSpecificDefaultTextDoubleClickStrategy ();
160+ IRegion selection = strategy .findWord (document , 5 );
161+ assertNotNull (selection );
162+ assertEquals ("ไทย" , document .get (selection .getOffset (), selection .getLength ()));
163+ }
164+
58165 private static final class TestSpecificDefaultTextDoubleClickStrategy extends DefaultTextDoubleClickStrategy {
59166
60167 @ Override
0 commit comments