Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: test/ignore_ascii_case_test.dart

Issue 2484163002: Fix bug in equalsIgnoreAsciiCase. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Tests case-ignoring compare and equality.
6
7 import "package:collection/collection.dart";
8 import "package:test/test.dart";
9
10 main() {
11 testEquality();
12 testCompareUpper();
13 testCompareLower();
14 }
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
15
16 void testEquality() {
17 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.
18 var strings = [];
19 upIf(String s, bool up) {
20 if (up) return s.toUpperCase();
21 return s;
22 }
23 for (int i = 0; i < 16; i++) {
24 var string =
25 upIf("a", i & 1 != 0) +
26 upIf("o", i & 2 != 0) +
27 upIf("p", i & 4 != 0) +
28 upIf("z", i & 8 != 0);
29 strings.add(string);
30 }
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
31 for (var s1 in strings) {
32 for (var s2 in strings) {
33 expect(equalsIgnoreAsciiCase(s1, s2), true);
34 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 :
35 }
36 }
37 var lcletters = "@`abcdefghijklmnopqrstuvwxyz[{åÅ";
38 var ucletters = "@`ABCDEFGHIJKLMNOPQRSTUVWXYZ[{åÅ";
nweiz 2016/11/10 21:44:44 "lowerCaseLetters" and "upperCaseLetters".
Lasse Reichstein Nielsen 2016/11/11 07:56:51 Done.
39 expect(equalsIgnoreAsciiCase(lcletters, ucletters), true);
40 for (int i = 0; i < lcletters.length; i++) {
41 for (int j = 0; i < lcletters.length; i++) {
42 expect(equalsIgnoreAsciiCase(lcletters[i], lcletters[j]), i == j);
43 expect(equalsIgnoreAsciiCase(ucletters[i], lcletters[j]), i == j);
44 expect(equalsIgnoreAsciiCase(lcletters[i], ucletters[j]), i == j);
45 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.
46 }
47 }
48 });
49 }
50
51 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.
52 var orderedStrings = [
53 "@zzz",
54 "aopz@{",
55 "aopzZ{",
56 "aopzz{", // z < [ due to upper-casing.
57 "Aopz[{",
58 "aoPz[{",
59 "aopz[{",
60 "AOPZ[{@",
61 "AOPZÅ",
62 "AOPZÕ", // Õ is between Å and å.
63 "AOPZå",
64 "b@@@@",
65 "bAa@@",
66 "baa@@",
67 "ba`@@",
68 ];
69 test("compareAsciiUpperCase", () {
70 for (int i = 0; i < orderedStrings.length; i++) {
71 var s1 = orderedStrings[i];
72 for (int j = 0; j < orderedStrings.length; j++) {
73 var s2 = orderedStrings[j];
74 expect(compareAsciiUpperCase(s1, s2).sign, (i - j).sign);
75 }
76 }
77 });
78 }
79
80 void testCompareLower() {
81 var orderedStrings = [
82 "@zzz",
83 "aopz@{",
84 "Aopz[{",
85 "aoPz[{",
86 "aopz[{",
87 "AOPZ[{@",
88 "aopzZ{",
89 "aopzz{", // z < [ due to upper-casing.
90 "AOPZÅ",
91 "AOPZÕ", // Õ is between Å and å.
92 "AOPZå",
93 "b@@@@",
94 "ba`@@",
95 "bAa@@",
96 "baa@@",
97 ];
98 test("compareAsciiLowerCase", () {
99 for (int i = 0; i < orderedStrings.length; i++) {
100 var s1 = orderedStrings[i];
101 for (int j = 0; j < orderedStrings.length; j++) {
102 var s2 = orderedStrings[j];
103 expect(compareAsciiLowerCase(s1, s2).sign, (i - j).sign);
104 }
105 }
106 });
107 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698