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