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

Unified Diff: tests/html/js_type_test.dart

Issue 2133563002: Type test tests for js interop (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Avoid script injection 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/html/html.status ('k') | tests/html/js_type_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/js_type_test.dart
diff --git a/tests/html/js_type_test.dart b/tests/html/js_type_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c77519c5768cd58f14cb378886c1f6d76da24a82
--- /dev/null
+++ b/tests/html/js_type_test.dart
@@ -0,0 +1,151 @@
+// Copyright (c) 2016, 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.
+
+library jsTest;
+
+import 'dart:html';
+
+import 'package:js/js.dart';
+
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_individual_config.dart';
+import 'package:expect/expect.dart' show NoInline, AssumeDynamic;
+
+@JS()
+class Foo {
+ external factory Foo();
+}
+
+class Bar {}
+
+@NoInline() @AssumeDynamic()
+confuse(x) => x;
+
+class Is<T> {
+ const Is();
+ check(o) => o is T;
+}
+
+main() {
+ useHtmlIndividualConfiguration();
+
+ new Is<Foo>().check(new Bar()); // Bar is instantiated by this code.
+ new Is<Foo>().check([]);
+ new Is<List>().check([]);
+
+ group('static', () {
+ test('not-String', () {
+ Foo e = new Foo();
+ expect(e is String, isFalse);
+ });
+
+ test('not-int', () {
+ Foo e = new Foo();
+ expect(e is int, isFalse);
+ });
+
+ test('not-Null', () {
+ Foo e = new Foo();
+ expect(e is Null, isFalse);
+ });
+
+ test('not-Bar', () {
+ Foo e = new Foo();
+ expect(e is Bar, isFalse);
+ });
+
+ test('is-Foo', () {
+ Foo e = new Foo();
+ expect(e is Foo, isTrue);
+ });
+
+ test('String-not-Foo', () {
+ String e = 'hello';
+ expect(e is Foo, isFalse);
+ });
+ });
+
+ group('dynamic', () {
+ test('not-String', () {
+ var e = confuse(new Foo());
+ expect(e is String, isFalse);
+ });
+
+ test('not-int', () {
+ var e = confuse(new Foo());
+ expect(e is int, isFalse);
+ });
+
+ test('not-Null', () {
+ var e = confuse(new Foo());
+ expect(e is Null, isFalse);
+ });
+
+ test('not-Bar', () {
+ var e = confuse(new Foo());
+ expect(e is Bar, isFalse);
+ });
+
+ test('is-Foo', () {
+ var e = confuse(new Foo());
+ expect(e is Foo, isTrue);
+ });
+ });
+
+ group('dynamic-String-not-Foo', () {
+ test('test', () {
+ var e = confuse('hello');
+ expect(e is Foo, isFalse);
+ });
+ });
+
+ group('dynamic-null-not-Foo', () {
+ test('test', () {
+ var e = confuse(null);
+ expect(e is Foo, isFalse);
+ });
+ });
+
+ group('dynamic-type', () {
+ test('not-String', () {
+ var e = confuse(new Foo());
+ expect(const Is<String>().check(e), isFalse);
+ });
+
+ test('not-int', () {
+ var e = confuse(new Foo());
+ expect(const Is<int>().check(e), isFalse);
+ });
+
+ test('not-Null', () {
+ var e = confuse(new Foo());
+ expect(const Is<Null>().check(e), isFalse);
+ });
+
+ test('not-Bar', () {
+ var e = confuse(new Foo());
+ expect(const Is<Bar>().check(e), isFalse);
+ });
+
+ test('is-Foo', () {
+ var e = confuse(new Foo());
+ expect(const Is<Foo>().check(e), isTrue);
+ });
+ });
+
+ group('dynamic-String-not-dynamic-Foo', () {
+ test('test', () {
+ var e = confuse('hello');
+ expect(const Is<Foo>().check(e), isFalse);
+ });
+ });
+
+ group('dynamic-null-not-dynamic-Foo', () {
+ test('test', () {
+ var e = confuse(null);
+ expect(const Is<Foo>().check(e), isFalse);
+ });
+ });
+
+}
« no previous file with comments | « tests/html/html.status ('k') | tests/html/js_type_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698