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

Side by Side Diff: tests/language/string_interpolation_and_buffer.dart

Issue 1286823003: Fix issue 24043: do not trust the pattern. Enable a 'hidden' test. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: f Created 5 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | tests/language/string_interpolation_and_buffer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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()..write(wrap(object));
45 } on TypeError {
46 return 'Error';
47 }
48 } else {
49 try {
50 sb = new StringBuffer()..write(wrap(object));
51 } on ArgumentError {
52 return 'Error';
53 }
54 Expect.isTrue(sb.toString() is String);
55 }
56 return 'Success';
57 }
58
59 initBuffer(object) {
60 var sb;
61 if (checkedMode && object != null) {
62 try {
63 sb = new StringBuffer(wrap(object));
64 } on TypeError {
65 return 'Error';
66 }
67 } else {
68 try {
69 sb = new StringBuffer(wrap(object));
70 } on ArgumentError {
71 return 'Error';
72 }
73 Expect.isTrue(sb.toString() is String);
74 }
75 return 'Success';
76 }
77
78 Expect.equals('Error', interpolate(null));
79 Expect.equals('Success', interpolate(""));
80 Expect.equals('Success', interpolate("string"));
81 Expect.equals('Error', interpolate([]));
82 Expect.equals('Error', interpolate([1]));
83 Expect.equals('Error', interpolate(new Object()));
84
85 Expect.equals('Error', buffer(null));
86 Expect.equals('Success', buffer(""));
87 Expect.equals('Success', buffer("string"));
88 Expect.equals('Error', buffer([]));
89 Expect.equals('Error', buffer([1]));
90 Expect.equals('Error', buffer(new Object()));
91
92 Expect.equals('Error', initBuffer(null));
93 Expect.equals('Success', initBuffer(""));
94 Expect.equals('Success', initBuffer("string"));
95 Expect.equals('Error', initBuffer([]));
96 Expect.equals('Error', initBuffer([1]));
97 Expect.equals('Error', initBuffer(new Object()));
98 }
OLDNEW
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | tests/language/string_interpolation_and_buffer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698