| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * This library contains an Expect class with static methods that can be used | 6 * This library contains an Expect class with static methods that can be used |
| 7 * for simple unit-tests. | 7 * for simple unit-tests. |
| 8 */ | 8 */ |
| 9 library expect; | 9 library expect; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * The slice will contain at least the substring from [start] to the lower of | 22 * The slice will contain at least the substring from [start] to the lower of |
| 23 * [end] and `start + length`. | 23 * [end] and `start + length`. |
| 24 * If the result is no more than `length - 10` characters long, | 24 * If the result is no more than `length - 10` characters long, |
| 25 * context may be added by extending the range of the slice, by decreasing | 25 * context may be added by extending the range of the slice, by decreasing |
| 26 * [start] and increasing [end], up to at most length characters. | 26 * [start] and increasing [end], up to at most length characters. |
| 27 * If the start or end of the slice are not matching the start or end of | 27 * If the start or end of the slice are not matching the start or end of |
| 28 * the string, ellipses are added before or after the slice. | 28 * the string, ellipses are added before or after the slice. |
| 29 * Control characters may be encoded as "\xhh" codes. | 29 * Control characters may be encoded as "\xhh" codes. |
| 30 */ | 30 */ |
| 31 static String _truncateString(String string, int start, int end, int length) { | 31 static String _truncateString(String string, int start, int end, int length) { |
| 32 print("$string: $start: $end: $length"); | |
| 33 if (end - start > length) { | 32 if (end - start > length) { |
| 34 end = start + length; | 33 end = start + length; |
| 35 } else if (end - start < length) { | 34 } else if (end - start < length) { |
| 36 int overflow = length - (end - start); | 35 int overflow = length - (end - start); |
| 37 if (overflow > 10) overflow = 10; | 36 if (overflow > 10) overflow = 10; |
| 38 // Add context. | 37 // Add context. |
| 39 start = start - ((overflow + 1) ~/ 2); | 38 start = start - ((overflow + 1) ~/ 2); |
| 40 end = end + (overflow ~/ 2); | 39 end = end + (overflow ~/ 2); |
| 41 if (start < 0) start = 0; | 40 if (start < 0) start = 0; |
| 42 if (end > string.length) end = string.length; | 41 if (end > string.length) end = string.length; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 * Find the difference between two strings. | 61 * Find the difference between two strings. |
| 63 * | 62 * |
| 64 * This finds the first point where two strings differ, and returns | 63 * This finds the first point where two strings differ, and returns |
| 65 * a text describing the difference. | 64 * a text describing the difference. |
| 66 * | 65 * |
| 67 * For small strings (length less than 20) nothing is done, and null is | 66 * For small strings (length less than 20) nothing is done, and null is |
| 68 * returned. Small strings can be compared visually, but for longer strings | 67 * returned. Small strings can be compared visually, but for longer strings |
| 69 * only a slice containing the first difference will be shown. | 68 * only a slice containing the first difference will be shown. |
| 70 */ | 69 */ |
| 71 static String _stringDifference(String expected, String actual) { | 70 static String _stringDifference(String expected, String actual) { |
| 72 print("digg: $expected, $actual"); | |
| 73 if (expected.length < 20 && actual.length < 20) return null; | 71 if (expected.length < 20 && actual.length < 20) return null; |
| 74 for (int i = 0; i < expected.length && i < actual.length; i++) { | 72 for (int i = 0; i < expected.length && i < actual.length; i++) { |
| 75 if (expected.codeUnitAt(i) != actual.codeUnitAt(i)) { | 73 if (expected.codeUnitAt(i) != actual.codeUnitAt(i)) { |
| 76 int start = i; | 74 int start = i; |
| 77 i++; | 75 i++; |
| 78 while (i < expected.length && i < actual.length) { | 76 while (i < expected.length && i < actual.length) { |
| 79 if (expected.codeUnitAt(i) == actual.codeUnitAt(i)) break; | 77 if (expected.codeUnitAt(i) == actual.codeUnitAt(i)) break; |
| 80 i++; | 78 i++; |
| 81 } | 79 } |
| 82 int end = i; | 80 int end = i; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 371 |
| 374 bool _identical(a, b) => identical(a, b); | 372 bool _identical(a, b) => identical(a, b); |
| 375 | 373 |
| 376 typedef bool _CheckExceptionFn(exception); | 374 typedef bool _CheckExceptionFn(exception); |
| 377 | 375 |
| 378 class ExpectException implements Exception { | 376 class ExpectException implements Exception { |
| 379 ExpectException(this.message); | 377 ExpectException(this.message); |
| 380 String toString() => message; | 378 String toString() => message; |
| 381 String message; | 379 String message; |
| 382 } | 380 } |
| OLD | NEW |