Files
sdk/tests/language/dynamic_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

64 lines
1.8 KiB
Dart

// Copyright (c) 2012, 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 the use of 'dynamic' in generic types.
import "package:expect/expect.dart";
abstract class Iface<K, V> {}
class M1<K, V> implements Iface<K, V> {}
class M2<K> implements Iface<K, dynamic> {}
class M3 implements Iface<String, dynamic> {}
typedef dynamic F1<T>(dynamic x, T y);
class HasFieldDynamic {
HasFieldDynamic() : dynamic = "dynamic" {}
var dynamic; // Field named dynamic is allowed.
}
class HasMethodDynamic {
dynamic() => "dynamic"; // Method named dynamic is allowed.
}
main() {
Expect.isTrue(dynamic is Type);
Expect.equals(dynamic, dynamic);
M1<dynamic, dynamic> m1 = new M1<dynamic, dynamic>();
Expect.isTrue(m1 is Iface<dynamic, num>);
Expect.isTrue(m1 is Iface<String, dynamic>);
Expect.isTrue(m1 is Iface<String, num>);
Expect.isTrue(m1 is Iface<num, String>);
M2<dynamic> m2 = new M2<dynamic>();
Expect.isTrue(m2 is Iface<dynamic, num>);
Expect.isTrue(m2 is Iface<String, dynamic>);
Expect.isTrue(m2 is Iface<String, num>);
Expect.isTrue(m2 is Iface<num, String>);
M3 m3 = new M3();
Expect.isTrue(m3 is Iface<dynamic, num>);
Expect.isTrue(m3 is Iface<String, dynamic>);
Expect.isTrue(m3 is Iface<String, num>);
Expect.isTrue(m3 is! Iface<num, String>);
F1<int> f1 = (String s, int i) => s[i];
Expect.isTrue(f1 is F1<int>);
HasFieldDynamic has_field = new HasFieldDynamic();
Expect.equals("dynamic", has_field.dynamic);
HasMethodDynamic has_method = new HasMethodDynamic();
Expect.equals("dynamic", has_method.dynamic());
{
int dynamic = 0; // Local variable named dynamic is allowed.
Expect.equals(0, dynamic);
}
}