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

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: Rebased and addressed review comments 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
« no previous file with comments | « dart/sdk/lib/core/string_buffer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()));
+}
« no previous file with comments | « 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