Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: tests/html/js_typed_interop_type_test.dart

Issue 2124443002: Add type test for jsinterop types. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cleanup Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/jsinterop/world_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/js_typed_interop_type_test.dart
diff --git a/tests/html/js_typed_interop_type_test.dart b/tests/html/js_typed_interop_type_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b8ba7d220d58d74e4d87962edabca0c7c7ab2d39
--- /dev/null
+++ b/tests/html/js_typed_interop_type_test.dart
@@ -0,0 +1,157 @@
+import 'dart:html';
+import 'package:js/js.dart';
+import 'package:expect/expect.dart';
+
+@JS()
+class A {
+ get foo;
+
+ external A(var foo);
+}
+
+@JS()
+class B {
+ get foo;
+
+ external B(var foo);
+}
+
+@JS()
+@anonymous
+class C {
+ final foo;
+
+ external factory C({foo});
+}
+
+@JS()
+@anonymous
+class D {
+ final foo;
+
+ external factory D({foo});
+}
+
+class E {
+ final foo;
+
+ E(this.foo);
+}
+
+class F {
+ final foo;
+
+ F(this.foo);
+}
+
+@NoInline()
+testA(A o) {
+ return o.foo;
+}
+
+
+@NoInline()
+testB(B o) {
+ return o.foo;
+}
+
+
+@NoInline()
+testC(C o) {
+ return o.foo;
+}
+
+
+@NoInline()
+testD(D o) {
+ return o.foo;
+}
+
+@NoInline()
+testE(E o) {
+ return o.foo;
+}
+
+@NoInline()
+testF(F o) {
+ return o.foo;
+}
+
+
+_injectJs() {
+ document.body.append(new ScriptElement()
+ ..type = 'text/javascript'
+ ..innerHtml = r"""
+function A(foo) {
+ this.foo = foo;
+}
+
+function B(foo) {
+ this.foo = foo;
+}
+""");
+}
+
+void expectValueOrTypeError(f(), value) {
+ try {
+ String i = 0; // Test for checked mode.
+ Expect.equals(f(), value);
+ } on TypeError catch (error) {
+ Expect.throws(f, (ex) => ex is TypeError);
+ }
+}
+
+main() {
+ _injectJs();
+
+ var a = new A(1);
+ var b = new B(2);
+ var c = new C(foo: 3);
+ var d = new D(foo: 4);
+ var e = new E(5);
+ var f = new F(6);
+
+ Expect.equals(testA(a), 1);
+ Expect.equals(testA(b), 2);
+ Expect.equals(testA(c), 3);
+ Expect.equals(testA(d), 4);
+ expectValueOrTypeError(() => testA(e), 5);
+ expectValueOrTypeError(() => testA(f), 6);
+
+ Expect.equals(testB(a), 1);
+ Expect.equals(testB(b), 2);
+ Expect.equals(testB(c), 3);
+ Expect.equals(testB(d), 4);
+ expectValueOrTypeError(() => testB(e), 5);
+ expectValueOrTypeError(() => testB(f), 6);
+
+ Expect.equals(testC(a), 1);
+ Expect.equals(testC(b), 2);
+ Expect.equals(testC(c), 3);
+ Expect.equals(testC(d), 4);
+ expectValueOrTypeError(() => testC(e), 5);
+ expectValueOrTypeError(() => testC(f), 6);
+
+ Expect.equals(testD(a), 1);
+ Expect.equals(testD(b), 2);
+ Expect.equals(testD(c), 3);
+ Expect.equals(testD(d), 4);
+ expectValueOrTypeError(() => testD(e), 5);
+ expectValueOrTypeError(() => testD(f), 6);
+
+ expectValueOrTypeError(() => testE(a), 1);
+ expectValueOrTypeError(() => testE(b), 2);
+ expectValueOrTypeError(() => testE(c), 3);
+ expectValueOrTypeError(() => testE(d), 4);
+ Expect.equals(testE(e), 5);
+ expectValueOrTypeError(() => testE(f), 6);
+
+ expectValueOrTypeError(() => testF(a), 1);
+ expectValueOrTypeError(() => testF(b), 2);
+ expectValueOrTypeError(() => testF(c), 3);
+ expectValueOrTypeError(() => testF(d), 4);
+ expectValueOrTypeError(() => testF(e), 5);
+ Expect.equals(testF(f), 6);
+}
+
+
« no previous file with comments | « tests/compiler/dart2js/jsinterop/world_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698