Files
sdk/tests/corelib/string_replace_test.dart
T
floitsch@google.com 5dc8107c53 Revert "Remove Expect from core library."
This reverts commit 19755.

Review URL: https://codereview.chromium.org//12743005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19756 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-09 03:19:07 +00:00

49 lines
1.6 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.
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();
}