OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, 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 @JS() | |
6 library js_function_getter_test; | |
7 | |
8 import 'dart:html'; | |
9 | |
10 import 'package:js/js.dart'; | |
11 import 'package:unittest/unittest.dart'; | |
12 import 'package:unittest/html_config.dart'; | |
13 import 'package:unittest/html_individual_config.dart'; | |
14 | |
15 _injectJs() { | |
16 document.body.append(new ScriptElement() | |
17 ..type = 'text/javascript' | |
18 ..innerHtml = r""" | |
19 var bar = { }; | |
20 | |
21 bar.instanceMember = function() { | |
22 if (this !== bar) { | |
23 throw 'Unexpected this!'; | |
24 } | |
25 return arguments.length; | |
26 }; | |
27 | |
28 bar.staticMember = function() { | |
29 return arguments.length * 2; | |
30 }; | |
31 | |
32 bar.dynamicStatic = function() { | |
33 return arguments.length; | |
34 }; | |
35 | |
36 bar.nonFunctionStatic = function() { | |
37 return arguments.length * 2; | |
38 }; | |
39 | |
40 bar.add = function(a, b) { | |
41 return a + b; | |
42 }; | |
43 | |
44 var foo = { 'bar' : bar }; | |
45 """); | |
46 } | |
47 | |
48 typedef int AddFn(int x, int y); | |
49 | |
50 @JS() | |
51 abstract class Bar { | |
52 external Function get staticMember; | |
53 external Function get instanceMember; | |
54 external AddFn get add; | |
55 external get dynamicStatic; | |
56 external num get nonFunctionStatic; | |
57 } | |
58 | |
59 @JS() | |
60 abstract class Foo { | |
61 external Bar get bar; | |
62 } | |
63 | |
64 @JS() | |
65 external Foo get foo; | |
66 | |
67 main() { | |
68 _injectJs(); | |
69 | |
70 useHtmlIndividualConfiguration(); | |
71 | |
72 group('call getter as function', () { | |
73 test('member function', () { | |
74 expect(foo.bar.instanceMember(), equals(0)); | |
75 expect(foo.bar.instanceMember(0), equals(1)); | |
76 expect(foo.bar.instanceMember(0,0), equals(2)); | |
77 expect(foo.bar.instanceMember(0,0,0,0,0,0), equals(6)); | |
78 var instanceMember = foo.bar.instanceMember; | |
79 expect(() => instanceMember(), throws); | |
80 expect(() => instanceMember(0), throws); | |
81 expect(() => instanceMember(0,0), throws); | |
82 expect(() => instanceMember(0,0,0,0,0,0), throws); | |
83 }); | |
84 | |
85 test('static function', () { | |
86 expect(foo.bar.staticMember(), equals(0)); | |
87 expect(foo.bar.staticMember(0), equals(2)); | |
88 expect(foo.bar.staticMember(0,0), equals(4)); | |
89 expect(foo.bar.staticMember(0,0,0,0,0,0), equals(12)); | |
90 var staticMember = foo.bar.staticMember; | |
91 expect(staticMember(), equals(0)); | |
92 expect(staticMember(0), equals(2)); | |
93 expect(staticMember(0,0), equals(4)); | |
94 expect(staticMember(0,0,0,0,0,0), equals(12)); | |
95 }); | |
96 | |
97 test('static dynamicStatic', () { | |
98 expect(foo.bar.dynamicStatic(), equals(0)); | |
99 expect(foo.bar.dynamicStatic(0), equals(1)); | |
100 expect(foo.bar.dynamicStatic(0,0), equals(2)); | |
101 expect(foo.bar.dynamicStatic(0,0,0,0,0,0), equals(6)); | |
102 var dynamicStatic = foo.bar.dynamicStatic; | |
103 expect(dynamicStatic(), equals(0)); | |
104 expect(dynamicStatic(0), equals(1)); | |
105 expect(dynamicStatic(0,0), equals(2)); | |
106 expect(dynamicStatic(0,0,0,0,0,0), equals(6)); | |
107 }); | |
108 | |
109 test('typedef function', () { | |
110 expect(foo.bar.add(4,5), equals(9)); | |
111 }); | |
112 }); | |
113 | |
114 // These tests only work with trust types enabled | |
Siggi Cherem (dart-lang)
2015/10/30 20:14:57
2 options:
- always run this test with TT
- split
| |
115 /* | |
116 group('trust types', () { | |
117 test('static nonFunctionStatic', () { | |
118 expect(() => foo.bar.nonFunctionStatic(), throws); | |
119 expect(() => foo.bar.nonFunctionStatic(0), throws); | |
120 expect(() => foo.bar.nonFunctionStatic(0,0), throws); | |
121 expect(() => foo.bar.nonFunctionStatic(0,0,0,0,0,0), throws); | |
122 }); | |
123 | |
124 test('typedef function', () { | |
125 expect(() => foo.bar.add(4), throws); | |
126 expect(() => foo.bar.add(4,5,10), throws); | |
127 }); | |
128 }); | |
129 */ | |
130 } | |
OLD | NEW |