12dbd2fd70
Review URL: https://codereview.chromium.org//12212016 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19755 260f80e4-7a28-3924-810f-c04153c831b5
51 lines
1.7 KiB
Dart
51 lines
1.7 KiB
Dart
// Copyright (c) 2011, 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";
|
|
|
|
class StringReplaceTest {
|
|
static testMain() {
|
|
Expect.equals(
|
|
"AtoBtoCDtoE", "AfromBtoCDtoE".replaceFirst("from", "to"));
|
|
|
|
// Test with the replaced string at the begining.
|
|
Expect.equals(
|
|
"toABtoCDtoE", "fromABtoCDtoE".replaceFirst("from", "to"));
|
|
|
|
// Test with the replaced string at the end.
|
|
Expect.equals(
|
|
"toABtoCDtoEto", "fromABtoCDtoEto".replaceFirst("from", "to"));
|
|
|
|
// Test when there are no occurence of the string to replace.
|
|
Expect.equals("ABC", "ABC".replaceFirst("from", "to"));
|
|
|
|
// Test when the string to change is the empty string.
|
|
Expect.equals("", "".replaceFirst("from", "to"));
|
|
|
|
// Test when the string to change is a substring of the string to
|
|
// replace.
|
|
Expect.equals("fro", "fro".replaceFirst("from", "to"));
|
|
|
|
// Test when the string to change is the replaced string.
|
|
Expect.equals("to", "from".replaceFirst("from", "to"));
|
|
|
|
// Test when the string to change is the replacement string.
|
|
Expect.equals("to", "to".replaceFirst("from", "to"));
|
|
|
|
// Test replacing by the empty string.
|
|
Expect.equals("", "from".replaceFirst("from", ""));
|
|
Expect.equals("AB", "AfromB".replaceFirst("from", ""));
|
|
|
|
// Test changing the empty string.
|
|
Expect.equals("to", "".replaceFirst("", "to"));
|
|
|
|
// Test replacing the empty string.
|
|
Expect.equals("toAtoBtoCto", "AtoBtoCto".replaceFirst("", "to"));
|
|
}
|
|
}
|
|
|
|
main() {
|
|
StringReplaceTest.testMain();
|
|
}
|