Chromium Code Reviews| 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..a02b48011d88621b9ee32b0ac1a9c28774b8f358 |
| --- /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 'GOOD'; |
|
Lasse Reichstein Nielsen
2012/12/20 23:21:57
Use 'Success', matching 'Error'. Or 'Good'/'Bad'.
ahe
2012/12/21 11:23:38
Done.
|
| + } |
| + |
| + 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 'GOOD'; |
| + } |
| + |
| + Expect.equals('Error', interpolate(null)); |
| + Expect.equals('GOOD', interpolate("")); |
| + Expect.equals('GOOD', interpolate("string")); |
| + Expect.equals('Error', interpolate([])); |
| + Expect.equals('Error', interpolate([1])); |
| + Expect.equals('Error', interpolate(new Object())); |
| + |
| + Expect.equals('Error', buffer(null)); |
| + Expect.equals('GOOD', buffer("")); |
| + Expect.equals('GOOD', buffer("string")); |
| + Expect.equals('Error', buffer([])); |
| + Expect.equals('Error', buffer([1])); |
| + Expect.equals('Error', buffer(new Object())); |
| +} |