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

Unified Diff: tests/corelib/string_slice_test.dart

Issue 13874008: Remove String.slice. Too much overlap with String.substring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add VM changes. Created 7 years, 8 months 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 | « sdk/lib/core/string.dart ('k') | tools/dom/docs/lib/docs.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/string_slice_test.dart
diff --git a/tests/corelib/string_slice_test.dart b/tests/corelib/string_slice_test.dart
deleted file mode 100644
index b003a427ca2b3ce826d14124e7be5112a5ec0085..0000000000000000000000000000000000000000
--- a/tests/corelib/string_slice_test.dart
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2012, 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:expect/expect.dart";
-
-// Short string.
-var s = "0123456789";
-// Long string.
-var l = "$s$s$s$s$s$s$s$s$s$s";
-// Very long string.
-var v = "$l$l$l$l$l$l$l$l$l$l";
-
-
-testSliceSuccess() {
- // Test different ways to get the same slice from a string.
- testSlice(String string, int start, int end) {
- int length = string.length;
- String expect = string.substring(start, end);
- Expect.equals(expect, string.slice(start, end), "#${length}[$start:$end]");
- if (start < length) {
- // If start == length, there is no negative representation of the position.
- Expect.equals(expect, string.slice(start - length, end),
- "#${length}[${start - length}:$end]");
- }
- if (end < length) {
- Expect.equals(expect, string.slice(start, end - length),
- "#${length}[$start:${end - length}]");
- Expect.equals(expect, string.slice(start - length, end - length),
- "#${length}[${start-length}:${end-length}]");
- } else {
- Expect.equals(expect, string.slice(start),
- "#${length}[$start]");
- if (start < length) {
- Expect.equals(expect, string.slice(start - length),
- "#${length}[${start-length}]");
- if (start == 0) {
- Expect.equals(string, string.slice(), "#$length[:]");
- }
- }
- }
- }
-
- testSliceCombinations(String string) {
- int length = string.length;
- List<int> positions = [0, 1, string.length >> 1, length - 1, length];
- for (int i = 0; i < positions.length; i++) {
- for (int j = i; j < positions.length; j++) {
- testSlice(string, positions[i], positions[j]);
- }
- }
- }
-
- testSliceCombinations(s);
- testSliceCombinations(l);
- testSliceCombinations(v);
-}
-
-testSliceError() {
- function expectRangeError(void thunk()) {
- Expect.throws(thunk, (e) => e is RangeError);
- };
- function expectArgumentError(void thunk()) {
- Expect.throws(thunk, (e) => e is ArgumentError);
- };
- function badType(void thunk()) {
- bool checkedMode = false;
- assert(checkedMode = true);
- Expect.throws(thunk,
- (e) => checkedMode ? e is TypeError : e is ArgumentError);
- }
-
- // Invalid start:
- expectRangeError(() => s.slice(11));
- expectRangeError(() => s.slice(-11));
- // Invalid end:
- expectRangeError(() => s.slice(0, 11));
- expectRangeError(() => s.slice(0, -11));
- // Non-int:
- badType(() => s.slice(1.5));
- badType(() => s.slice(0, 1.5));
- badType(() => s.slice("1"));
- badType(() => s.slice(0, "1"));
- // Bad order:
- expectArgumentError(() => s.slice(5, 4));
- expectArgumentError(() => s.slice(-5, 4));
- expectArgumentError(() => s.slice(5, -6));
- expectArgumentError(() => s.slice(-5, -6));
-}
-
-
-main() {
- testSliceSuccess();
- testSliceError();
-}
« no previous file with comments | « sdk/lib/core/string.dart ('k') | tools/dom/docs/lib/docs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698