dart-sdk/tests/dartdevc/const_test.dart
Nicholas Shahan 1332cf8c41 [ddc] Migrate tests in dartdevc suite
Change-Id: I2a35de7f79b8d768cdd0144b3bf5de87fa929942
Issue: https://github.com/dart-lang/sdk/issues/42107
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154301
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2020-07-15 00:16:03 +00:00

31 lines
856 B
Dart

// Copyright (c) 2019, 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.
import "package:expect/expect.dart";
import 'dart:_foreign_helper' show JS;
import 'dart:_runtime' as dart;
void main() {
dynamic data = JS('', '[1, 2, 3, 4]');
Expect.isFalse(data is List<int>);
var list = dart.constList(data, dart.unwrapType(int));
Expect.isTrue(list is List<int>);
Expect.throws(() {
list[0] = 0;
});
var set = dart.constSet<int>(data);
Expect.isTrue(set is Set<int>);
Expect.isTrue(set.contains(3));
Expect.throws(() => set.clear());
var map = dart.constMap<int, int>(data);
Expect.isTrue(map is Map<int, int>);
Expect.equals(map[1], 2);
Expect.throws(() {
map[1] = 42;
});
}