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

Unified Diff: dart/tests/language/string_interpolation_and_buffer.dart

Issue 11618037: Make StringBuffer and interpolation behave the same. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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
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()));
+}
« dart/sdk/lib/core/string_buffer.dart ('K') | « dart/sdk/lib/core/string_buffer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698