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

Side by Side Diff: frog/tests/leg_only/string_interpolation_test.dart

Issue 10536169: Move frog/tests/{leg,leg_only,frog_native} to tests/compiler/. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « frog/tests/leg_only/string_escape_test.dart ('k') | frog/tests/leg_only/super_call_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) 2011, 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 that String interpolation works in the code generated by the leg
6 // compiler.
7
8
9 int ifun() => 37;
10 double dfun() => 2.71828;
11 bool bfun() => true;
12 String sfun() => "sfun";
13 void nfun() => null;
14
15
16 void testEscapes() {
17 // Test that escaping the '$' prevents string interpolation.
18 String x = "NOT HERE";
19 Expect.equals(@'a${x}', 'a\${x}');
20 Expect.equals(@'a$x', 'a\$x');
21 Expect.equals(@'a${x}', '''a\${x}''');
22 Expect.equals(@'a$x', '''a\$x''');
23 Expect.equals(@'a${x}', "a\${x}");
24 Expect.equals(@'a$x', "a\$x");
25 Expect.equals(@'a${x}', """a\${x}""");
26 Expect.equals(@'a$x', """a\$x""");
27 }
28
29
30 void testMultiLine() {
31 var a = "string";
32 var b = 42;
33 var c = 3.1415;
34 var d = false;
35 var n = null;
36
37 Expect.equals("string423.1415falsenull!", """$a$b$c$d$n!""");
38 Expect.equals("string423.1415falsenull!", '''$a$b$c$d$n!''');
39 Expect.equals("string423.1415falsenull!", """${a}${b}${c}${d}${n}!""");
40 Expect.equals("string423.1415falsenull!", '''${a}${b}${c}${d}${n}!''');
41
42 // Quotes as literals are included correctly..
43 Expect.equals("'42''42'", """'$b''$b'""");
44 Expect.equals('"42""42"', '''"$b""$b"''');
45
46 Expect.equals('"42""42" ', """"$b""$b" """);
47 Expect.equals("'42''42' ", ''''$b''$b' ''');
48
49 Expect.equals('""42""42" ', """""$b""$b" """);
50 Expect.equals("''42''42' ", '''''$b''$b' ''');
51
52 // Newlines at beginning of multiline strings are not included, but only
53 // if they are in the source.
54 Expect.equals("\n", """${''}
55 """);
56 Expect.equals("\r", """${''}
57 """);
58 Expect.equals("\r\n", """${''}
59 """);
60 Expect.equals("\n", """${'\n'}""");
61 Expect.equals("\r", """${'\r'}""");
62 Expect.equals("\r\n", """${'\r\n'}""");
63 }
64
65
66 void testSimple() {
67 var a = "string";
68 var b = 42;
69 var c = 3.1415;
70 var d = false;
71 var n = null;
72
73 // Both kinds of quotes and both kinds of $-escapes.
74 Expect.equals("string423.1415falsenull!", "$a$b$c$d$n!");
75 Expect.equals("string423.1415falsenull!", '$a$b$c$d$n!');
76 Expect.equals("string423.1415falsenull!", "${a}${b}${c}${d}${n}!");
77 Expect.equals("string423.1415falsenull!", '${a}${b}${c}${d}${n}!');
78
79 // Different types for first expression.
80 Expect.equals("!string423.1415falsenull", "!$a$b$c$d$n");
81 Expect.equals("null!string423.1415false", "$n!$a$b$c$d");
82 Expect.equals("falsenull!string423.1415", "$d$n!$a$b$c");
83 Expect.equals("3.1415falsenull!string42", "$c$d$n!$a$b");
84 Expect.equals("423.1415falsenull!string", "$b$c$d$n!$a");
85
86 // Function calls as expressions.
87 Expect.equals("sfun372.71828truenull",
88 "${sfun()}${ifun()}${dfun()}${bfun()}${nfun()}");
89 Expect.equals("nullsfun372.71828true",
90 "${nfun()}${sfun()}${ifun()}${dfun()}${bfun()}");
91 Expect.equals("truenullsfun372.71828",
92 "${bfun()}${nfun()}${sfun()}${ifun()}${dfun()}");
93 Expect.equals("2.71828truenullsfun37",
94 "${dfun()}${bfun()}${nfun()}${sfun()}${ifun()}");
95 Expect.equals("372.71828truenullsfun",
96 "${ifun()}${dfun()}${bfun()}${nfun()}${sfun()}");
97
98
99 // String contents around interpolated parts.
100 Expect.equals("stringstring", "$a$a");
101 Expect.equals("-stringstring", "-$a$a");
102 Expect.equals("string-string", "$a-$a");
103 Expect.equals("-string-string", "-$a-$a");
104 Expect.equals("stringstring-", "$a$a-");
105 Expect.equals("-stringstring-", "-$a$a-");
106 Expect.equals("string-string-", "$a-$a-");
107 Expect.equals("-string-string-", "-$a-$a-");
108
109 // Quotes as literals are included correctly..
110 Expect.equals("'42''42'", "'$b''$b'");
111 Expect.equals('"42""42"', '"$b""$b"');
112
113 // Nested string interpolation.
114 Expect.equals("string423.1415false", "${'${a}'}$b${'$c${d}'}");
115 // Quad-nested string interpolation.
116 Expect.equals("string423.1415false", "${'${a}${"${b}${'${c}${"$d"}'}"}'}");
117 // Lotsa-nested.
118 Expect.equals("42", "${'${"${'${"${'${"$b"}'}"}'}"}'}");
119 }
120
121
122 void main() {
123 testSimple();
124 testMultiLine();
125 testEscapes();
126 }
OLDNEW
« no previous file with comments | « frog/tests/leg_only/string_escape_test.dart ('k') | frog/tests/leg_only/super_call_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698