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

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

Issue 1425823004: Make dart2js accept constant null values in string interpolations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Also test int/bool.fromEnvironment returning null. Created 5 years, 1 month 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 | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | no next file » | 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) 2015, 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 import "package:expect/expect.dart";
6
7 // Regression test for issue #24839 - http://dartbug.com/24839
8
9 const u1 = null;
10 const int u2 = null;
11 const List u3 = null;
12 const u4 = const String.fromEnvironment("XXXXX");
13 const u5 = const int.fromEnvironment("XXXXX");
14 const u6 = const bool.fromEnvironment("XXXXX", defaultValue: null);
15 const n1 = 42;
16 const n2 = 3.1415;
17 const int n3 = 37;
18 const double n4 = 4.6692;
19 const num n5 = b3 ? 1 : 2.71828;
20 const n6 = const int.fromEnvironment("XXXXX", defaultValue: 87);
21 const s1 = "s1";
22 const String s2 = "s2";
23 const String s3 = "$s1$s2";
24 const s4 = const String.fromEnvironment("XXXXX", defaultValue: "s4");
25 const b1 = true;
26 const b2 = false;
27 const b3 = b1 && (b2 || !b1);
28 const b4 = const bool.fromEnvironment("XXXXX", defaultValue: true);
29
30 // Individually
31 const su1 = "$u1";
32 const su2 = "$u2";
33 const su3 = "$u3";
34 const su4 = "$u4";
35 const su5 = "$u5";
36 const su6 = "$u6";
37 const sn1 = "$n1";
38 const sn2 = "$n2";
39 const sn3 = "$n3";
40 const sn4 = "$n4";
41 const sn5 = "$n5";
42 const sn6 = "$n6";
43 const ss1 = "$s1";
44 const ss2 = "$s2";
45 const ss3 = "$s3";
46 const ss4 = "$s4";
47 const sb1 = "$b1";
48 const sb2 = "$b2";
49 const sb3 = "$b3";
50 const sb4 = "$b4";
51
52 // Constant variables in interpolation.
53 const interpolation1 =
54 "$u1 $u2 $u3 $u4 $u5 $u6 $n1 $n2 $n3 $n4 $n5 $n6 $s1 $s2 $s3 $s4 $b1 $b2 $b3 $ b4";
55 // Constant expressions in interpolation.
56 // (Single string, the linebreak to fit this into 80 chars is inside an
57 // interpolation, which is allowed, even for single-line strings).
58 const interpolation2 =
59 "${u1} ${u2} ${u3} ${u4} ${u5} ${u6} ${n1} ${n2} ${n3} ${n4} ${n5} ${n6} ${
60 s1} ${s2} ${s3} ${s4} ${b1} ${b2} ${b3} ${b4}";
61 // Adjacent string literals are combined.
62 const interpolation3 =
63 "$u1 $u2 $u3 $u4 $u5 " '$u6 $n1 $n2 $n3 $n4 '
64 """$n5 $n6 $s1 $s2 $s3 """ '''$s4 $b1 $b2 $b3 $b4''';
65 // Nested interpolations.
66 const interpolation4 =
67 "${"$u1 $u2 $u3 $u4 $u5 " '$u6 $n1 $n2 $n3 $n4'} ${
68 """$n5 $n6 $s1 $s2 $s3 """ '''$s4 $b1 $b2 $b3 $b4'''}";
69
70 main() {
71 Expect.equals(u1.toString(), su1);
72 Expect.equals(u2.toString(), su2);
73 Expect.equals(u3.toString(), su3);
74 Expect.equals(u4.toString(), su4);
75 Expect.equals(u5.toString(), su5);
76 Expect.equals(u6.toString(), su6);
77 Expect.equals(n1.toString(), sn1);
78 Expect.equals(n2.toString(), sn2);
79 Expect.equals(n3.toString(), sn3);
80 Expect.equals(n4.toString(), sn4);
81 Expect.equals(n5.toString(), sn5);
82 Expect.equals(n6.toString(), sn6);
83 Expect.equals(s1.toString(), ss1);
84 Expect.equals(s2.toString(), ss2);
85 Expect.equals(s3.toString(), ss3);
86 Expect.equals(s4.toString(), ss4);
87 Expect.equals(b1.toString(), sb1);
88 Expect.equals(b2.toString(), sb2);
89 Expect.equals(b3.toString(), sb3);
90 Expect.equals(b4.toString(), sb4);
91 var expect = "null null null null null null 42 3.1415 37 4.6692 2.71828 87 "
92 "s1 s2 s1s2 s4 true false false true";
93 Expect.equals(expect, interpolation1);
94 Expect.equals(expect, interpolation2);
95 Expect.equals(expect, interpolation3);
96 Expect.equals(expect, interpolation4);
97 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698