2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.diff.comparison
18 class WordComparisonUtilTest : ComparisonUtilTestBase() {
19 fun testSimpleCases() {
22 ("- " - "- ").default()
28 ("- " - "- ").default()
34 ("-- " - "- ").default()
41 ("- -" - "- ").default()
48 ("- -" - "- ").default()
55 ("- " - "-- -").default()
62 (" -" - " --").default()
69 (" --" - " ").default()
75 ("-- " - " ").default()
81 (" - " - " - ").default()
86 ("X xyz1 Z" - "X xyz2 Z")
87 (" ---- " - " ---- ").default()
92 fun testPunctuation() {
95 ("- - -" - " ").default()
102 (" " - "- - -").default()
108 ("x ... z" - "y ... z")
109 ("- " - "- ").default()
114 ("x ... z" - "x ... y")
115 (" -" - " -").default()
120 ("x ,... z" - "x ... y")
121 (" - -" - " -").default()
126 ("x . , .. z" - "x ... y")
127 (" --- -" - " -").default()
128 (" - -" - " -").ignore()
133 ("x==y==z" - "x====z")
134 (" - " - " ").default()
139 ("x====z" - "x==t==z")
140 (" " - " - ").default()
145 fun testOldDiffBug() {
148 (" -- " - " ").default()
154 (" " - " -- ").default()
159 fun testWhitespaceOnlyChanges() {
162 (" -- " - " -- ").default()
169 (" -- " - " ---").default()
170 (" " - " -").ignore()
177 (" x _ y _ z " - "x z")
178 ("- ------ -" - " ").default()
180 (" - " - " ").ignore()
185 ("x z" - " x _ y _ z ")
186 (" " - "- ------ -").default()
188 (" " - " - ").ignore()
193 fun testFixedBugs() {
196 (" -" - " --- ").default()
197 (" " - " --- ").trim()
198 (" " - " - ").ignore()
204 (" -" - "---- -").default()
205 (" -" - " - -").trim()
206 (" -" - " - -").ignore()
212 (" -" - " ---").default()
214 (" " - " - ").ignore()
219 fun testInnerWhitespaces() {
221 ("<< x >>" - "<.<>.>")
222 (" --- " - " - - ").default()
223 (" - " - " - - ").ignore()
228 ("<< x >>" - "y<<x>>y")
229 (" - - " - "- -").default()
230 (" " - "- -").ignore()
235 ("x .. z" - "x y .. z")
236 (" " - " -- ").default() // TODO: looks wrong
237 (" " - " - ").ignore()
243 ("-- -" - " ---").default()
244 (" -" - " - ").trim()
249 (" x y x _ x z x " - "x x_x x")
250 ("- -- - - -- -" - " ").default()
251 (" -- -- " - " ").trim()
252 (" - - " - " ").ignore()
257 fun testAlgorithmSpecific() {
258 // prefer words over punctuation
261 ("--- " - " ---").default()
265 // prefer longer words sequences
268 ("-- " - " ").default()
269 ("- " - " ").ignore()
275 (" --" - " ").default()
276 (" -" - " ").ignore()
282 ("---- " - " ").default()
283 ("--- " - " ").ignore()
287 // prefer less modified 'sentences'
289 ("A.X A.Z" - "A.X A.Y A.Z")
290 (" " - " ---- ").default()
291 (" " - " --- ").ignore()
296 ("X.A Z.A" - "X.A Y.A Z.A")
297 (" " - " ---- ").default()
298 (" " - " --- ").ignore()
302 // prefer punctuation over whitespaces
305 (" ---" - "--- ").default()
310 fun `test legacy cases from ByWordTest`() {
312 ("abc def, 123" - "ab def, 12")
313 ("--- ---" - "-- --").default()
318 (" a[xy]+1" - ",a[]+1")
319 ("- -- " - "- ").default()
320 (" -- " - "- ").trim()
325 ("0987_ a.g();_" - "yyyy_")
326 ("------------- " - "---- ").default()
331 (" abc_2222_" - " x = abc_zzzz_")
332 //(" ---- " - "-- ---- ---- ").legacy()
333 (" ---- " - " ------ ---- ").default()
334 (" ---- " - " --- ---- ").trim()
339 (" if (eventMerger!=null && !dataSelection.getValueIsAdjusting()) {" -
340 " if (eventMerger!=null && (dataSelection==null || !dataSelection.getValueIsAdjusting())) {")
342 // " - ------------------------ - ").legacy()
344 " ------------------------ - ").default()
346 " ----------------------- - ").ignore()
351 ("messageInsertStatement = connection.prepareStatement(\"INSERT INTO AUDIT (AUDIT_TYPE_ID, STATUS, SERVER_ID, INSTANCE_ID, REQUEST_ID) VALUES (?, ?, ?, ?, ?)\");" -
352 "messageInsertStatement = connection.prepareStatement(\"INSERT INTO AUDIT (AUDIT_TYPE_ID, CREATION_TIMESTAMP, STATUS, SERVER_ID, INSTANCE_ID, REQUEST_ID) VALUES (?, ?, ?, ?, ?, ?)\");").plainSource()
354 // " . -------------------- --- . ").legacy()
356 " . -------------------- --- . ").default()
358 " . ------------------- --- . ").ignore()
363 ("f(a, b);" - "f(a,_ b);")
364 (" " - " -- ").default()
370 (" o.f(a)" - "o. f( b)")
371 ("- - " - " - -- ").default()
372 (" - " - " - -- ").trim()
373 (" - " - " - ").ignore()
379 (" --- " - "---").trim()
384 fun testEmptyRangePositions() {
387 (" - " - " ").default()
388 default(del(1, 1, 1))
394 (" - " - " ").default()
395 default(del(2, 2, 1))