| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.services.correction.strings; | 5 library test.services.correction.strings; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/correction/strings.dart'; | 7 import 'package:analysis_server/src/services/correction/strings.dart'; |
| 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 import 'package:unittest/unittest.dart' hide isEmpty; | 9 import 'package:unittest/unittest.dart' hide isEmpty; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 void test_compareStrings() { | 28 void test_compareStrings() { |
| 29 expect(compareStrings(null, null), 0); | 29 expect(compareStrings(null, null), 0); |
| 30 expect(compareStrings(null, 'b'), 1); | 30 expect(compareStrings(null, 'b'), 1); |
| 31 expect(compareStrings('a', null), -1); | 31 expect(compareStrings('a', null), -1); |
| 32 expect(compareStrings('a', 'b'), -1); | 32 expect(compareStrings('a', 'b'), -1); |
| 33 expect(compareStrings('b', 'a'), 1); | 33 expect(compareStrings('b', 'a'), 1); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void test_computeSimpleDiff() { |
| 37 assertDiff(String oldStr, String newStr) { |
| 38 SimpleDiff diff = computeSimpleDiff(oldStr, newStr); |
| 39 expect(diff.offset, isNonNegative); |
| 40 expect(diff.length, isNonNegative); |
| 41 String applied = oldStr.substring(0, diff.offset) + |
| 42 diff.replacement + |
| 43 oldStr.substring(diff.offset + diff.length); |
| 44 expect(applied, newStr); |
| 45 } |
| 46 assertDiff('', ''); |
| 47 assertDiff('', 'a'); |
| 48 assertDiff('abc', ''); |
| 49 assertDiff('abcd', 'acd'); |
| 50 assertDiff('a', 'b'); |
| 51 assertDiff('12345xyz', '12345abcxyz'); |
| 52 assertDiff('12345xyz', '12345xyzabc'); |
| 53 assertDiff('abbc', 'abbbc'); |
| 54 assertDiff('abbbbc', 'abbbbbbc'); |
| 55 } |
| 56 |
| 36 void test_countMatches() { | 57 void test_countMatches() { |
| 37 expect(countMatches(null, null), 0); | 58 expect(countMatches(null, null), 0); |
| 38 expect(countMatches('abc', null), 0); | 59 expect(countMatches('abc', null), 0); |
| 39 expect(countMatches(null, 'abc'), 0); | 60 expect(countMatches(null, 'abc'), 0); |
| 40 expect(countMatches('ababa', 'a'), 3); | 61 expect(countMatches('ababa', 'a'), 3); |
| 41 expect(countMatches('ababa', 'ab'), 2); | 62 expect(countMatches('ababa', 'ab'), 2); |
| 42 expect(countMatches('aaabaa', 'aa'), 2); | 63 expect(countMatches('aaabaa', 'aa'), 2); |
| 43 } | 64 } |
| 44 | 65 |
| 45 void test_findCommonOverlap() { | |
| 46 expect(findCommonOverlap('', 'abcd'), 0); | |
| 47 expect(findCommonOverlap('abc', 'abcd'), 3); | |
| 48 expect(findCommonOverlap('123456', 'abcd'), 0); | |
| 49 expect(findCommonOverlap('123456xxx', 'xxxabcd'), 3); | |
| 50 expect(findCommonOverlap('123456', '56'), 2); | |
| 51 expect(findCommonOverlap('56', '56789'), 2); | |
| 52 } | |
| 53 | |
| 54 void test_findCommonPrefix() { | 66 void test_findCommonPrefix() { |
| 55 expect(findCommonPrefix('abc', 'xyz'), 0); | 67 expect(findCommonPrefix('abc', 'xyz'), 0); |
| 56 expect(findCommonPrefix('1234abcdef', '1234xyz'), 4); | 68 expect(findCommonPrefix('1234abcdef', '1234xyz'), 4); |
| 57 expect(findCommonPrefix('123', '123xyz'), 3); | 69 expect(findCommonPrefix('123', '123xyz'), 3); |
| 58 } | 70 } |
| 59 | 71 |
| 60 void test_findCommonSuffix() { | 72 void test_findCommonSuffix() { |
| 61 expect(findCommonSuffix('abc', 'xyz'), 0); | 73 expect(findCommonSuffix('abc', 'xyz'), 0); |
| 62 expect(findCommonSuffix('abcdef1234', 'xyz1234'), 4); | 74 expect(findCommonSuffix('abcdef1234', 'xyz1234'), 4); |
| 63 expect(findCommonSuffix('123', 'xyz123'), 3); | 75 expect(findCommonSuffix('123', 'xyz123'), 3); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 expect(repeat('abc', 3), 'abcabcabc'); | 199 expect(repeat('abc', 3), 'abcabcabc'); |
| 188 } | 200 } |
| 189 | 201 |
| 190 void test_substringAfterLast() { | 202 void test_substringAfterLast() { |
| 191 expect(substringAfterLast('', '/'), ''); | 203 expect(substringAfterLast('', '/'), ''); |
| 192 expect(substringAfterLast('abc', ''), ''); | 204 expect(substringAfterLast('abc', ''), ''); |
| 193 expect(substringAfterLast('abc', 'd'), 'abc'); | 205 expect(substringAfterLast('abc', 'd'), 'abc'); |
| 194 expect(substringAfterLast('abcbde', 'b'), 'de'); | 206 expect(substringAfterLast('abcbde', 'b'), 'de'); |
| 195 } | 207 } |
| 196 } | 208 } |
| OLD | NEW |