| 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. | |
| 5 | |
| 6 | |
| 7 class WhatchamaCallIt { | |
| 8 WhatchamaCallIt() { } | |
| 9 | |
| 10 String foo() { | |
| 11 // Test $this and Field name is defined in subclass. | |
| 12 return "$this and $name"; | |
| 13 } | |
| 14 } | |
| 15 | |
| 16 class ThingamaBob extends WhatchamaCallIt { | |
| 17 ThingamaBob(String s) : super(), name = s { } | |
| 18 String name; | |
| 19 toString() => "Hansel"; | |
| 20 } | |
| 21 | |
| 22 class StringInterpolateTest { | |
| 23 | |
| 24 static final String A = "svin"; | |
| 25 static final String B = "hest"; | |
| 26 static final int N = 1 + 1; | |
| 27 static String Printers; | |
| 28 static String AAR_Printers; | |
| 29 | |
| 30 static testMain() { | |
| 31 Printers = "Printers: $A and $B"; | |
| 32 AAR_Printers = "AAR has $N $Printers."; | |
| 33 | |
| 34 var x = 1; | |
| 35 var s = "eins und \$x macht zwei."; | |
| 36 print(s); | |
| 37 Expect.equals(@"eins und $x macht zwei.", s); | |
| 38 | |
| 39 s = "eins und $x macht zwei."; | |
| 40 print(s); | |
| 41 Expect.equals(@"eins und 1 macht zwei.", s); | |
| 42 | |
| 43 print(AAR_Printers); | |
| 44 Expect.equals(@"AAR has 2 Printers: svin and hest.", AAR_Printers); | |
| 45 | |
| 46 var s$eins = "eins"; | |
| 47 var $1 = 1; | |
| 48 var zw = "zw"; | |
| 49 var ei = "ei"; | |
| 50 var zw$ei = "\"Martini, dry? Nai zwai.\""; | |
| 51 s = "${s$eins} und ${$1} macht $zw$ei."; | |
| 52 print(s); | |
| 53 Expect.equals(@"eins und 1 macht zwei.", s); | |
| 54 | |
| 55 var t = new ThingamaBob("Gretel"); | |
| 56 print(t.foo()); | |
| 57 Expect.equals(t.foo(), "Hansel and Gretel"); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 main() { | |
| 62 StringInterpolateTest.testMain(); | |
| 63 } | |
| OLD | NEW |