| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Test to ensure that StringBuffer and string interpolation behaves |
| 6 // the same and fail fast. |
| 7 |
| 8 class ToStringWrapper { |
| 9 final value; |
| 10 |
| 11 ToStringWrapper(this.value); |
| 12 |
| 13 toString() => value; |
| 14 } |
| 15 |
| 16 wrap(value) => new ToStringWrapper(value); |
| 17 |
| 18 main() { |
| 19 bool checkedMode = false; |
| 20 assert(checkedMode = true); |
| 21 interpolate(object) { |
| 22 var result; |
| 23 if (checkedMode && object != null) { |
| 24 try { |
| 25 result = '${wrap(object)}'; |
| 26 } on TypeError { |
| 27 return 'Error'; |
| 28 } |
| 29 } else { |
| 30 try { |
| 31 result = '${wrap(object)}'; |
| 32 } on ArgumentError { |
| 33 return 'Error'; |
| 34 } |
| 35 } |
| 36 Expect.isTrue(result is String); |
| 37 return 'Success'; |
| 38 } |
| 39 |
| 40 buffer(object) { |
| 41 var sb; |
| 42 if (checkedMode && object != null) { |
| 43 try { |
| 44 sb = new StringBuffer().add(wrap(object)); |
| 45 } on TypeError { |
| 46 return 'Error'; |
| 47 } |
| 48 } else { |
| 49 try { |
| 50 sb = new StringBuffer().add(wrap(object)); |
| 51 } on ArgumentError { |
| 52 return 'Error'; |
| 53 } |
| 54 Expect.isTrue(sb.toString() is String); |
| 55 } |
| 56 return 'Success'; |
| 57 } |
| 58 |
| 59 Expect.equals('Error', interpolate(null)); |
| 60 Expect.equals('Success', interpolate("")); |
| 61 Expect.equals('Success', interpolate("string")); |
| 62 Expect.equals('Error', interpolate([])); |
| 63 Expect.equals('Error', interpolate([1])); |
| 64 Expect.equals('Error', interpolate(new Object())); |
| 65 |
| 66 Expect.equals('Error', buffer(null)); |
| 67 Expect.equals('Success', buffer("")); |
| 68 Expect.equals('Success', buffer("string")); |
| 69 Expect.equals('Error', buffer([])); |
| 70 Expect.equals('Error', buffer([1])); |
| 71 Expect.equals('Error', buffer(new Object())); |
| 72 } |
| OLD | NEW |