Files
sdk/tests/language/string_interpolate2_test.dart
T
Jacob Richman 2dcd56ef43 Format all tests.
There are far too many files here to review everyone carefully.
Spot checking most of the diffs look good as test code is generally written
with less care than application code so lots of ugly formatting get through.
If people notice files where the automated formatting bothers them feel free
to comment indicating file names and I'll move spaces within comments to make
the formatting cleaner and use comments to force block formatting as I have
done for other case where formatting looked bad.

BUG=
R=efortuna@google.com

Review-Url: https://codereview.chromium.org/2771453003 .
2017-04-17 14:53:02 -07:00

58 lines
1.4 KiB
Dart

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Dart test program testing string interpolation of expressions.
import "package:expect/expect.dart";
class StringInterpolate2Test {
static var F1;
static void testMain() {
F1 = "1 + 5 = ${1+5}";
Expect.equals("1 + 5 = 6", F1);
var fib = [1, 1, 2, 3, 5, 8, 13, 21];
var i = 5;
var s = "${i}";
Expect.equals("5", s);
s = "fib(${i}) = ${fib[i]}";
Expect.equals("fib(5) = 8", s);
i = 5;
s = "$i squared is ${((x) => x*x)(i)}";
Expect.equals("5 squared is 25", s);
Expect.equals("8", "${fib.length}");
// test single quote
Expect.equals("8", '${fib.length}');
// test multi-line
Expect.equals(
"8",
'${fib.
length}');
var map = {"red": 1, "green": 2, "blue": 3};
s = "green has value ${map["green"]}";
Expect.equals("green has value 2", s);
i = 0;
b() => "${++i}";
s = "aaa ${"bbb ${b()} bbb"} aaa ${b()}";
Expect.equals("aaa bbb 1 bbb aaa 2", s);
// test multiple levels of nesting, including changing quotes and
// multiline string types
s = "a ${(){ return 'b ${(){ return """
c""";}()}'; }()} d";
Expect.equals("a b c d", s);
}
}
main() {
StringInterpolate2Test.testMain();
}