| Index: dart/tests/language/string_interpolation_and_buffer.dart
|
| diff --git a/dart/tests/language/string_interpolation_and_buffer.dart b/dart/tests/language/string_interpolation_and_buffer.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2e25375a5e8ea4ce3a32ff363580ba0acdbbe669
|
| --- /dev/null
|
| +++ b/dart/tests/language/string_interpolation_and_buffer.dart
|
| @@ -0,0 +1,72 @@
|
| +// 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.
|
| +
|
| +// Test to ensure that StringBuffer and string interpolation behaves
|
| +// the same and fail fast.
|
| +
|
| +class ToStringWrapper {
|
| + final value;
|
| +
|
| + ToStringWrapper(this.value);
|
| +
|
| + toString() => value;
|
| +}
|
| +
|
| +wrap(value) => new ToStringWrapper(value);
|
| +
|
| +main() {
|
| + bool checkedMode = false;
|
| + assert(checkedMode = true);
|
| + interpolate(object) {
|
| + var result;
|
| + if (checkedMode && object != null) {
|
| + try {
|
| + result = '${wrap(object)}';
|
| + } on TypeError {
|
| + return 'Error';
|
| + }
|
| + } else {
|
| + try {
|
| + result = '${wrap(object)}';
|
| + } on ArgumentError {
|
| + return 'Error';
|
| + }
|
| + }
|
| + Expect.isTrue(result is String);
|
| + return 'Success';
|
| + }
|
| +
|
| + buffer(object) {
|
| + var sb;
|
| + if (checkedMode && object != null) {
|
| + try {
|
| + sb = new StringBuffer().add(wrap(object));
|
| + } on TypeError {
|
| + return 'Error';
|
| + }
|
| + } else {
|
| + try {
|
| + sb = new StringBuffer().add(wrap(object));
|
| + } on ArgumentError {
|
| + return 'Error';
|
| + }
|
| + Expect.isTrue(sb.toString() is String);
|
| + }
|
| + return 'Success';
|
| + }
|
| +
|
| + Expect.equals('Error', interpolate(null));
|
| + Expect.equals('Success', interpolate(""));
|
| + Expect.equals('Success', interpolate("string"));
|
| + Expect.equals('Error', interpolate([]));
|
| + Expect.equals('Error', interpolate([1]));
|
| + Expect.equals('Error', interpolate(new Object()));
|
| +
|
| + Expect.equals('Error', buffer(null));
|
| + Expect.equals('Success', buffer(""));
|
| + Expect.equals('Success', buffer("string"));
|
| + Expect.equals('Error', buffer([]));
|
| + Expect.equals('Error', buffer([1]));
|
| + Expect.equals('Error', buffer(new Object()));
|
| +}
|
|
|