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

Unified Diff: packages/collection/test/comparators_test.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/collection/pubspec.yaml ('k') | packages/collection/test/wrapper_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/collection/test/comparators_test.dart
diff --git a/packages/collection/test/comparators_test.dart b/packages/collection/test/comparators_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4acdc2c18716c05f9ecd5f0a972e8b94a58cf4a8
--- /dev/null
+++ b/packages/collection/test/comparators_test.dart
@@ -0,0 +1,119 @@
+// Copyright (c) 2015, 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.
+
+import "package:collection/collection.dart";
+import "package:test/test.dart";
+
+void main() {
+ List<String> strings = [
+ "",
+ "\x00",
+ " ",
+ "+",
+ "/",
+ "0",
+ "00",
+ "000",
+ "001",
+ "01",
+ "011",
+ "1",
+ "100",
+ "11",
+ "110",
+ "9",
+ ":",
+ "=",
+ "@",
+ "A",
+ "A0",
+ "A000A",
+ "A001A",
+ "A00A",
+ "A01A",
+ "A0A",
+ "A1A",
+ "AA",
+ "AAB",
+ "AB",
+ "Z",
+ "[",
+ "_",
+ "`",
+ "a",
+ "a0",
+ "a000a",
+ "a001a",
+ "a00a",
+ "a01a",
+ "a0a",
+ "a1a",
+ "aa",
+ "aab",
+ "ab",
+ "z",
+ "{",
+ "~"
+ ];
+
+ sortedBy(compare) => strings.toList()..shuffle()..sort(compare);
+
+ test("String.compareTo", () {
+ expect(sortedBy(null), strings);
+ });
+ test("compareAsciiLowerCase", () {
+ expect(sortedBy(compareAsciiLowerCase),
+ sortedBy((a, b) {
+ int delta = a.toLowerCase().compareTo(b.toLowerCase());
+ if (delta != 0) return delta;
+ if (a == b) return 0;
+ return a.compareTo(b);
+ }));
+ });
+ test("compareAsciiUpperCase", () {
+ expect(sortedBy(compareAsciiUpperCase),
+ sortedBy((a, b) {
+ int delta = a.toUpperCase().compareTo(b.toUpperCase());
+ if (delta != 0) return delta;
+ if (a == b) return 0;
+ return a.compareTo(b);
+ }));
+ });
+
+ // Replace any digit sequence by ("0", value, length) as char codes.
+ // This will sort alphabetically (by charcode) the way digits sort
+ // numerically, and the leading 0 means it sorts like a digit
+ // compared to non-digits.
+ replaceNumbers(string) => string.replaceAllMapped(new RegExp(r"\d+"), (m) {
+ var digits = m[0];
+ return new String.fromCharCodes([0x30, int.parse(digits), digits.length]);
+ });
+
+ test("compareNatural", () {
+ expect(sortedBy(compareNatural),
+ sortedBy((a, b) => replaceNumbers(a).compareTo(replaceNumbers(b))));
+ });
+
+ test("compareAsciiLowerCaseNatural", () {
+ expect(sortedBy(compareAsciiLowerCaseNatural),
+ sortedBy((a, b) {
+ int delta = replaceNumbers(a.toLowerCase()).compareTo(
+ replaceNumbers(b.toLowerCase()));
+ if (delta != 0) return delta;
+ if (a == b) return 0;
+ return a.compareTo(b);
+ }));
+ });
+
+ test("compareAsciiUpperCaseNatural", () {
+ expect(sortedBy(compareAsciiUpperCaseNatural),
+ sortedBy((a, b) {
+ int delta = replaceNumbers(a.toUpperCase()).compareTo(
+ replaceNumbers(b.toUpperCase()));
+ if (delta != 0) return delta;
+ if (a == b) return 0;
+ return a.compareTo(b);
+ }));
+ });
+}
« no previous file with comments | « packages/collection/pubspec.yaml ('k') | packages/collection/test/wrapper_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698