Fix bug in equalsIgnoreAsciiCase.
Add tests.
R=floitsch@google.com, nweiz@google.com
Review URL: https://codereview.chromium.org//2484163002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8794fa7..2c398b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.12.1
+
+* Fix bug in `equalsIgnoreAsciiCase`.
+
## 1.12.0
* Add `CaseInsensitiveEquality`.
diff --git a/lib/src/comparators.dart b/lib/src/comparators.dart
index ca2b3c7..b0824a8 100644
--- a/lib/src/comparators.dart
+++ b/lib/src/comparators.dart
@@ -34,8 +34,8 @@
if (aChar ^ bChar != _asciiCaseBit) return false;
// If it's possible, then check if either character is actually an ASCII
// letter.
- int aCharUpperCase = aChar | _asciiCaseBit;
- if (_upperCaseA <= aCharUpperCase && aCharUpperCase <= _upperCaseZ) {
+ int aCharLowerCase = aChar | _asciiCaseBit;
+ if (_lowerCaseA <= aCharLowerCase && aCharLowerCase <= _lowerCaseZ) {
continue;
}
return false;
diff --git a/lib/src/equality.dart b/lib/src/equality.dart
index 39e4ad5..a901297 100644
--- a/lib/src/equality.dart
+++ b/lib/src/equality.dart
@@ -4,6 +4,8 @@
import "dart:collection";
+import "comparators.dart";
+
const int _HASH_MASK = 0x7fffffff;
/// A generic equality relation on objects.
diff --git a/pubspec.yaml b/pubspec.yaml
index ad3f111..36e3054 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: collection
-version: 1.12.0
+version: 1.12.1
author: Dart Team <misc@dartlang.org>
description: Collections and utilities functions and classes related to collections.
homepage: https://www.github.com/dart-lang/collection
diff --git a/test/ignore_ascii_case_test.dart b/test/ignore_ascii_case_test.dart
new file mode 100644
index 0000000..787f76f
--- /dev/null
+++ b/test/ignore_ascii_case_test.dart
@@ -0,0 +1,58 @@
+// 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() {
+ test("equality ignore ASCII case", () {
+ var strings = [
+ "0@`aopz[{",
+ "0@`aopz[{",
+ "0@`Aopz[{",
+ "0@`aOpz[{",
+ "0@`AOpz[{",
+ "0@`aoPz[{",
+ "0@`AoPz[{",
+ "0@`aOPz[{",
+ "0@`AOPz[{",
+ "0@`aopZ[{",
+ "0@`AopZ[{",
+ "0@`aOpZ[{",
+ "0@`AOpZ[{",
+ "0@`aoPZ[{",
+ "0@`AoPZ[{",
+ "0@`aOPZ[{",
+ "0@`AOPZ[{",
+ ];
+
+ for (var s1 in strings) {
+ for (var s2 in strings) {
+ var reason = "$s1 =?= $s2";
+ expect(equalsIgnoreAsciiCase(s1, s2), true, reason: reason);
+ expect(hashIgnoreAsciiCase(s1), hashIgnoreAsciiCase(s2),
+ reason: reason);
+ }
+ }
+
+ var upperCaseLetters = "@`abcdefghijklmnopqrstuvwxyz[{åÅ";
+ var lowerCaseLetters = "@`ABCDEFGHIJKLMNOPQRSTUVWXYZ[{åÅ";
+ expect(equalsIgnoreAsciiCase(upperCaseLetters, lowerCaseLetters), true);
+
+ testChars(char1, char2, areEqual) {
+ expect(equalsIgnoreAsciiCase(char1, char2), areEqual,
+ reason: "$char1 ${areEqual ? "=" : "!"}= $char2");
+ }
+ for (int i = 0; i < upperCaseLetters.length; i++) {
+ for (int j = 0; i < upperCaseLetters.length; i++) {
+ testChars(upperCaseLetters[i], upperCaseLetters[j], i == j);
+ testChars(lowerCaseLetters[i], upperCaseLetters[j], i == j);
+ testChars(upperCaseLetters[i], lowerCaseLetters[j], i == j);
+ testChars(lowerCaseLetters[i], lowerCaseLetters[j], i == j);
+ }
+ }
+ });
+}
\ No newline at end of file