| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library jsTest; | |
| 6 | |
| 7 import 'dart:html'; | |
| 8 | |
| 9 import 'package:js/js.dart'; | |
| 10 | |
| 11 import 'package:unittest/unittest.dart'; | |
| 12 import 'package:unittest/html_individual_config.dart'; | |
| 13 import 'package:expect/expect.dart' show NoInline, AssumeDynamic; | |
| 14 | |
| 15 const _SCRIPT_TEXT = r""" | |
| 16 function Foo() {} | |
| 17 """; | |
| 18 | |
| 19 @JS() | |
| 20 class Foo { | |
| 21 external factory Foo(); | |
| 22 } | |
| 23 | |
| 24 class Bar {} | |
| 25 | |
| 26 _injectJs(String text) { | |
| 27 final script = new ScriptElement(); | |
| 28 script.type = 'text/javascript'; | |
| 29 script.innerHtml = text; | |
| 30 document.body.append(script); | |
| 31 } | |
| 32 | |
| 33 @NoInline() @AssumeDynamic() | |
| 34 confuse(x) => x; | |
| 35 | |
| 36 class Is<T> { | |
| 37 const Is(); | |
| 38 check(o) => o is T; | |
| 39 } | |
| 40 | |
| 41 main() { | |
| 42 _injectJs(_SCRIPT_TEXT); | |
| 43 useHtmlIndividualConfiguration(); | |
| 44 | |
| 45 new Is<Foo>().check(new Bar()); // Bar is instantiated by this code. | |
| 46 new Is<Foo>().check([]); | |
| 47 new Is<List>().check([]); | |
| 48 | |
| 49 group('static', () { | |
| 50 test('not-String', () { | |
| 51 Foo e = new Foo(); | |
| 52 expect(e is String, isFalse); | |
| 53 }); | |
| 54 | |
| 55 test('not-int', () { | |
| 56 Foo e = new Foo(); | |
| 57 expect(e is int, isFalse); | |
| 58 }); | |
| 59 | |
| 60 test('not-Null', () { | |
| 61 Foo e = new Foo(); | |
| 62 expect(e is Null, isFalse); | |
| 63 }); | |
| 64 | |
| 65 test('not-Bar', () { | |
| 66 Foo e = new Foo(); | |
| 67 expect(e is Bar, isFalse); | |
| 68 }); | |
| 69 | |
| 70 test('is-Foo', () { | |
| 71 Foo e = new Foo(); | |
| 72 expect(e is Foo, isTrue); | |
| 73 }); | |
| 74 | |
| 75 test('String-not-Foo', () { | |
| 76 String e = 'hello'; | |
| 77 expect(e is Foo, isFalse); | |
| 78 }); | |
| 79 }); | |
| 80 | |
| 81 group('dynamic', () { | |
| 82 test('not-String', () { | |
| 83 var e = confuse(new Foo()); | |
| 84 expect(e is String, isFalse); | |
| 85 }); | |
| 86 | |
| 87 test('not-int', () { | |
| 88 var e = confuse(new Foo()); | |
| 89 expect(e is int, isFalse); | |
| 90 }); | |
| 91 | |
| 92 test('not-Null', () { | |
| 93 var e = confuse(new Foo()); | |
| 94 expect(e is Null, isFalse); | |
| 95 }); | |
| 96 | |
| 97 test('not-Bar', () { | |
| 98 var e = confuse(new Foo()); | |
| 99 expect(e is Bar, isFalse); | |
| 100 }); | |
| 101 | |
| 102 test('is-Foo', () { | |
| 103 var e = confuse(new Foo()); | |
| 104 expect(e is Foo, isTrue); | |
| 105 }); | |
| 106 }); | |
| 107 | |
| 108 group('dynamic-String-not-Foo', () { | |
| 109 test('test', () { | |
| 110 var e = confuse('hello'); | |
| 111 expect(e is Foo, isFalse); | |
| 112 }); | |
| 113 }); | |
| 114 | |
| 115 group('dynamic-null-not-Foo', () { | |
| 116 test('test', () { | |
| 117 var e = confuse(null); | |
| 118 expect(e is Foo, isFalse); | |
| 119 }); | |
| 120 }); | |
| 121 | |
| 122 group('dynamic-type', () { | |
| 123 test('not-String', () { | |
| 124 var e = confuse(new Foo()); | |
| 125 expect(const Is<String>().check(e), isFalse); | |
| 126 }); | |
| 127 | |
| 128 test('not-int', () { | |
| 129 var e = confuse(new Foo()); | |
| 130 expect(const Is<int>().check(e), isFalse); | |
| 131 }); | |
| 132 | |
| 133 test('not-Null', () { | |
| 134 var e = confuse(new Foo()); | |
| 135 expect(const Is<Null>().check(e), isFalse); | |
| 136 }); | |
| 137 | |
| 138 test('not-Bar', () { | |
| 139 var e = confuse(new Foo()); | |
| 140 expect(const Is<Bar>().check(e), isFalse); | |
| 141 }); | |
| 142 | |
| 143 test('is-Foo', () { | |
| 144 var e = confuse(new Foo()); | |
| 145 expect(const Is<Foo>().check(e), isTrue); | |
| 146 }); | |
| 147 }); | |
| 148 | |
| 149 group('dynamic-String-not-dynamic-Foo', () { | |
| 150 test('test', () { | |
| 151 var e = confuse('hello'); | |
| 152 expect(const Is<Foo>().check(e), isFalse); | |
| 153 }); | |
| 154 }); | |
| 155 | |
| 156 group('dynamic-null-not-dynamic-Foo', () { | |
| 157 test('test', () { | |
| 158 var e = confuse(null); | |
| 159 expect(const Is<Foo>().check(e), isFalse); | |
| 160 }); | |
| 161 }); | |
| 162 | |
| 163 } | |
| OLD | NEW |