Fix bug in Expect package's string compare.

Review URL: https://codereview.chromium.org//15745024

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23455 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
lrn@google.com 2013-05-31 07:56:20 +00:00
parent 974e0c62b5
commit 969a5f27b8

View file

@ -29,6 +29,7 @@ class Expect {
* Control characters may be encoded as "\xhh" codes.
*/
static String _truncateString(String string, int start, int end, int length) {
print("$string: $start: $end: $length");
if (end - start > length) {
end = start + length;
} else if (end - start < length) {
@ -68,6 +69,7 @@ class Expect {
* only a slice containing the first difference will be shown.
*/
static String _stringDifference(String expected, String actual) {
print("digg: $expected, $actual");
if (expected.length < 20 && actual.length < 20) return null;
for (int i = 0; i < expected.length && i < actual.length; i++) {
if (expected.codeUnitAt(i) != actual.codeUnitAt(i)) {
@ -75,6 +77,7 @@ class Expect {
i++;
while (i < expected.length && i < actual.length) {
if (expected.codeUnitAt(i) == actual.codeUnitAt(i)) break;
i++;
}
int end = i;
var truncExpected = _truncateString(expected, start, end, 20);
@ -92,7 +95,6 @@ class Expect {
static void equals(var expected, var actual, [String reason = null]) {
if (expected == actual) return;
String msg = _getMessage(reason);
stringSpecialCase:
if (expected is String && actual is String) {
String stringDifference = _stringDifference(expected, actual);
if (stringDifference != null) {