Chromium Code Reviews| Index: test/ignore_ascii_case_test.dart |
| diff --git a/test/ignore_ascii_case_test.dart b/test/ignore_ascii_case_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cbb92463757467378a1120dc045491904f7034a |
| --- /dev/null |
| +++ b/test/ignore_ascii_case_test.dart |
| @@ -0,0 +1,107 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/// Tests case-ignoring compare and equality. |
| + |
| +import "package:collection/collection.dart"; |
| +import "package:test/test.dart"; |
| + |
| +main() { |
| + testEquality(); |
| + testCompareUpper(); |
| + testCompareLower(); |
| +} |
|
nweiz
2016/11/10 21:44:44
Please just include the tests inline in main(). Th
Lasse Reichstein Nielsen
2016/11/11 07:56:51
I originally had more tests in each, but I guess t
|
| + |
| +void testEquality() { |
| + test("equality", () { |
|
nweiz
2016/11/10 21:44:44
I'd find this test a lot easier to read with some
Lasse Reichstein Nielsen
2016/11/11 07:56:51
Done.
|
| + var strings = []; |
| + upIf(String s, bool up) { |
| + if (up) return s.toUpperCase(); |
| + return s; |
| + } |
| + for (int i = 0; i < 16; i++) { |
| + var string = |
| + upIf("a", i & 1 != 0) + |
| + upIf("o", i & 2 != 0) + |
| + upIf("p", i & 4 != 0) + |
| + upIf("z", i & 8 != 0); |
| + strings.add(string); |
| + } |
|
nweiz
2016/11/10 21:44:44
Can you add a comment describing what's going on h
Lasse Reichstein Nielsen
2016/11/11 07:56:51
Including the literal strings. It's only 16 of the
|
| + for (var s1 in strings) { |
| + for (var s2 in strings) { |
| + expect(equalsIgnoreAsciiCase(s1, s2), true); |
| + expect(hashIgnoreAsciiCase(s1), hashIgnoreAsciiCase(s2)); |
|
nweiz
2016/11/10 21:44:44
Any failures here are going to be really difficult
Lasse Reichstein Nielsen
2016/11/11 07:56:51
Oooh, there's a "reason" parameter. Good to know :
|
| + } |
| + } |
| + var lcletters = "@`abcdefghijklmnopqrstuvwxyz[{åÅ"; |
| + var ucletters = "@`ABCDEFGHIJKLMNOPQRSTUVWXYZ[{åÅ"; |
|
nweiz
2016/11/10 21:44:44
"lowerCaseLetters" and "upperCaseLetters".
Lasse Reichstein Nielsen
2016/11/11 07:56:51
Done.
|
| + expect(equalsIgnoreAsciiCase(lcletters, ucletters), true); |
| + for (int i = 0; i < lcletters.length; i++) { |
| + for (int j = 0; i < lcletters.length; i++) { |
| + expect(equalsIgnoreAsciiCase(lcletters[i], lcletters[j]), i == j); |
| + expect(equalsIgnoreAsciiCase(ucletters[i], lcletters[j]), i == j); |
| + expect(equalsIgnoreAsciiCase(lcletters[i], ucletters[j]), i == j); |
| + expect(equalsIgnoreAsciiCase(ucletters[i], ucletters[j]), i == j); |
|
nweiz
2016/11/10 21:44:44
Any failures here are going to be really difficult
Lasse Reichstein Nielsen
2016/11/11 07:56:51
Done.
|
| + } |
| + } |
| + }); |
| +} |
| + |
| +void testCompareUpper() { |
|
nweiz
2016/11/10 21:44:44
Aren't these tests redundant with the comparison t
Lasse Reichstein Nielsen
2016/11/11 07:56:51
True, removed.
|
| + var orderedStrings = [ |
| + "@zzz", |
| + "aopz@{", |
| + "aopzZ{", |
| + "aopzz{", // z < [ due to upper-casing. |
| + "Aopz[{", |
| + "aoPz[{", |
| + "aopz[{", |
| + "AOPZ[{@", |
| + "AOPZÅ", |
| + "AOPZÕ", // Õ is between Å and å. |
| + "AOPZå", |
| + "b@@@@", |
| + "bAa@@", |
| + "baa@@", |
| + "ba`@@", |
| + ]; |
| + test("compareAsciiUpperCase", () { |
| + for (int i = 0; i < orderedStrings.length; i++) { |
| + var s1 = orderedStrings[i]; |
| + for (int j = 0; j < orderedStrings.length; j++) { |
| + var s2 = orderedStrings[j]; |
| + expect(compareAsciiUpperCase(s1, s2).sign, (i - j).sign); |
| + } |
| + } |
| + }); |
| +} |
| + |
| +void testCompareLower() { |
| + var orderedStrings = [ |
| + "@zzz", |
| + "aopz@{", |
| + "Aopz[{", |
| + "aoPz[{", |
| + "aopz[{", |
| + "AOPZ[{@", |
| + "aopzZ{", |
| + "aopzz{", // z < [ due to upper-casing. |
| + "AOPZÅ", |
| + "AOPZÕ", // Õ is between Å and å. |
| + "AOPZå", |
| + "b@@@@", |
| + "ba`@@", |
| + "bAa@@", |
| + "baa@@", |
| + ]; |
| + test("compareAsciiLowerCase", () { |
| + for (int i = 0; i < orderedStrings.length; i++) { |
| + var s1 = orderedStrings[i]; |
| + for (int j = 0; j < orderedStrings.length; j++) { |
| + var s2 = orderedStrings[j]; |
| + expect(compareAsciiLowerCase(s1, s2).sign, (i - j).sign); |
| + } |
| + } |
| + }); |
| +} |