| 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 | |
| 5 // Tests for string interpolation | |
| 6 class StringInterpolationTest { | |
| 7 | |
| 8 StringInterpolationTest() {} | |
| 9 | |
| 10 static final int i = 1; | |
| 11 static final String a = "<hi>"; | |
| 12 | |
| 13 int j; | |
| 14 int k; | |
| 15 | |
| 16 static testMain(bool alwaysFalse) { | |
| 17 var test = new StringInterpolationTest(); | |
| 18 test.j = 3; | |
| 19 test.k = 5; | |
| 20 | |
| 21 // simple string | |
| 22 Expect.equals(" hi ", " hi "); | |
| 23 | |
| 24 var c1 = '1'; | |
| 25 var c2 = '2'; | |
| 26 var c3 = '3'; | |
| 27 var c4 = '4'; | |
| 28 // no chars before/after/between embedded expressions | |
| 29 Expect.equals(" 1", " ${c1}"); | |
| 30 Expect.equals("1 ", "${c1} "); | |
| 31 Expect.equals("1", "${c1}"); | |
| 32 Expect.equals("12", "${c1}${c2}"); | |
| 33 Expect.equals("12 34", "${c1}${c2} ${c3}${c4}"); | |
| 34 | |
| 35 // embedding static fields | |
| 36 Expect.equals(" hi 1 ", " hi ${i} "); | |
| 37 Expect.equals(" hi <hi> ", " hi ${a} "); | |
| 38 | |
| 39 // embedding method parameters | |
| 40 Expect.equals("param = 9", test.embedParams(9)); | |
| 41 | |
| 42 // embedding a class field | |
| 43 Expect.equals("j = 3", test.embedSingleField()); | |
| 44 | |
| 45 // embedding more than one (non-constant) expression | |
| 46 Expect.equals(" hi 1 <hi>", " hi ${i} ${a}"); | |
| 47 Expect.equals("j = 3; k = 5", test.embedMultipleFields()); | |
| 48 | |
| 49 // escaping $ - doesn't start the embedded expression | |
| 50 Expect.equals("\$", "escaped \${3+2}"[12]); | |
| 51 Expect.equals("{", "escaped \${3+2}"[13]); | |
| 52 Expect.equals("3", "escaped \${3+2}"[14]); | |
| 53 Expect.equals("+", "escaped \${3+2}"[15]); | |
| 54 Expect.equals("2", "escaped \${3+2}"[16]); | |
| 55 Expect.equals("}", "escaped \${3+2}"[17]); | |
| 56 | |
| 57 if (alwaysFalse) { | |
| 58 "${i.toHorse()}"; /// 01: static type warning | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 String embedParams(int z) { | |
| 63 return "param = ${z}"; | |
| 64 } | |
| 65 | |
| 66 String embedSingleField() { | |
| 67 return "j = ${j}"; | |
| 68 } | |
| 69 | |
| 70 String embedMultipleFields() { | |
| 71 return "j = ${j}; k = ${k}"; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 main() { | |
| 76 StringInterpolationTest.testMain(false); | |
| 77 } | |
| OLD | NEW |