OLD | NEW |
| (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 // Dart test program testing string interpolation of expressions. | |
5 | |
6 | |
7 class StringInterpolate2Test { | |
8 | |
9 static var F1; | |
10 | |
11 static void testMain() { | |
12 | |
13 F1 = "1 + 5 = ${1+5}"; | |
14 | |
15 Expect.equals("1 + 5 = 6", F1); | |
16 | |
17 var fib = [1, 1, 2, 3, 5, 8, 13, 21]; | |
18 | |
19 var i = 5; | |
20 var s = "${i}"; | |
21 Expect.equals("5", s); | |
22 | |
23 s = "fib(${i}) = ${fib[i]}"; | |
24 Expect.equals("fib(5) = 8", s); | |
25 | |
26 i = 5; | |
27 s = "$i squared is ${((x) => x*x)(i)}"; | |
28 Expect.equals("5 squared is 25", s); | |
29 | |
30 Expect.equals("8", "${fib.length}"); | |
31 // test single quote | |
32 Expect.equals("8", '${fib.length}'); | |
33 // test multi-line | |
34 Expect.equals("8", '${fib. | |
35 length}'); | |
36 | |
37 var map = { "red": 1, "green": 2, "blue": 3 }; | |
38 s = "green has value ${map["green"]}"; | |
39 Expect.equals("green has value 2", s); | |
40 | |
41 i = 0; | |
42 b() => "${++i}"; | |
43 s = "aaa ${"bbb ${b()} bbb"} aaa ${b()}"; | |
44 Expect.equals("aaa bbb 1 bbb aaa 2", s); | |
45 | |
46 // test multiple levels of nesting, including changing quotes and | |
47 // multiline string types | |
48 s = "a ${(){ return 'b ${(){ return """ | |
49 c""";}()}'; }()} d"; | |
50 Expect.equals("a b c d", s); | |
51 } | |
52 } | |
53 | |
54 main() { | |
55 StringInterpolate2Test.testMain(); | |
56 } | |
OLD | NEW |