| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Test to ensure that StringBuffer and string interpolation behaves | 5 // Test to ensure that StringBuffer and string interpolation behaves |
| 6 // the same and fail fast. | 6 // the same and fail fast. |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 class ToStringWrapper { | 10 class ToStringWrapper { |
| 11 final value; | 11 final value; |
| 12 | 12 |
| 13 ToStringWrapper(this.value); | 13 ToStringWrapper(this.value); |
| 14 | 14 |
| 15 toString() => value; | 15 toString() => value; |
| 16 } | 16 } |
| 17 | 17 |
| 18 wrap(value) => new ToStringWrapper(value); | 18 wrap(value) => new ToStringWrapper(value); |
| 19 | 19 |
| 20 final bool checkedMode = computeCheckedMode(); | 20 final bool checkedMode = computeCheckedMode(); |
| 21 bool computeCheckedMode() { | 21 bool computeCheckedMode() { |
| 22 try { | 22 try { |
| 23 int x = "foo"; | 23 var i = 42; |
| 24 } on Error { | 24 String s = i; |
| 25 } on TypeError catch (e) { |
| 25 return true; | 26 return true; |
| 26 } | 27 } |
| 27 return false; | 28 return false; |
| 28 } | 29 } |
| 29 | 30 |
| 30 main() { | 31 main() { |
| 31 interpolate(object) { | 32 interpolate(object) { |
| 32 var result; | 33 var result; |
| 33 if (checkedMode && object != null) { | 34 if (checkedMode && object != null) { |
| 34 try { | 35 try { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 Expect.equals('Error', buffer([1])); | 106 Expect.equals('Error', buffer([1])); |
| 106 Expect.equals('Error', buffer(new Object())); | 107 Expect.equals('Error', buffer(new Object())); |
| 107 | 108 |
| 108 Expect.equals('Error', initBuffer(null)); | 109 Expect.equals('Error', initBuffer(null)); |
| 109 Expect.equals('Success', initBuffer("")); | 110 Expect.equals('Success', initBuffer("")); |
| 110 Expect.equals('Success', initBuffer("string")); | 111 Expect.equals('Success', initBuffer("string")); |
| 111 Expect.equals('Error', initBuffer([])); | 112 Expect.equals('Error', initBuffer([])); |
| 112 Expect.equals('Error', initBuffer([1])); | 113 Expect.equals('Error', initBuffer([1])); |
| 113 Expect.equals('Error', initBuffer(new Object())); | 114 Expect.equals('Error', initBuffer(new Object())); |
| 114 } | 115 } |
| OLD | NEW |