dart-sdk/tests/language/list_literal3_test.dart
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

60 lines
1.8 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.
// Check that arrays from const array literals are immutable.
import "package:expect/expect.dart";
class ListLiteral3Test {
static const List<String> canonicalJoke = const ["knock", "knock"];
static testMain() {
List<String> joke = const ["knock", "knock"];
// Elements of canonical lists are canonicalized.
Expect.identical(joke, canonicalJoke);
Expect.identical(joke[0], joke[1]);
Expect.identical(joke[0], canonicalJoke[0]);
// Lists from literals are immutable.
Expect.throws(() {
joke[0] = "sock";
}, (e) => e is UnsupportedError);
Expect.identical(joke[0], joke[1]);
// Make sure lists allocated at runtime are mutable and are
// not canonicalized.
List<String> lame_joke = ["knock", "knock"]; // Invokes operator new.
Expect.identical(joke[1], lame_joke[1]);
// Operator new creates a mutable list.
Expect.equals(false, identical(joke, lame_joke));
lame_joke[1] = "who";
Expect.identical("who", lame_joke[1]);
// Elements of canonical lists are canonicalized.
List<List<int>> a = const <List<int>>[
const [1, 2],
const [1, 2]
];
Expect.identical(a[0], a[1]);
Expect.identical(a[0][0], a[1][0]);
Expect.throws(() {
a[0][0] = 42;
}, (e) => e is UnsupportedError);
List<List<double>> b = const [
const [1.0, 2.0],
const [1.0, 2.0]
];
Expect.identical(b[0], b[1]);
Expect.equals(true, b[0][0] == 1.0);
Expect.identical(b[0][0], b[1][0]);
Expect.throws(() {
b[0][0] = 42.0;
}, (e) => e is UnsupportedError);
}
}
main() {
ListLiteral3Test.testMain();
}