1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
if(!dojo._hasResource["tests._base.declare"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["tests._base.declare"] = true;
dojo.provide("tests._base.declare");
tests.register("tests._base.declare",
[
function smokeTest(t){
dojo.declare("tests._base.declare.tmp");
var tmp = new tests._base.declare.tmp();
dojo.declare("testsFoo");
var tmp = new testsFoo();
},
function smokeTest2(t){
dojo.declare("tests._base.declare.foo", null, {
foo: "thonk"
});
var tmp = new tests._base.declare.foo();
t.is("thonk", tmp.foo);
dojo.declare("testsFoo2", null, {
foo: "thonk"
});
var tmp2 = new testsFoo2();
t.is("thonk", tmp2.foo);
},
function smokeTestWithCtor(t){
dojo.declare("tests._base.declare.fooBar", null, {
constructor: function(){
this.foo = "blah";
},
foo: "thonk"
});
var tmp = new tests._base.declare.fooBar();
t.is("blah", tmp.foo);
},
function smokeTestCompactArgs(t){
dojo.declare("tests._base.declare.fooBar2", null, {
foo: "thonk"
});
var tmp = new tests._base.declare.fooBar2();
t.is("thonk", tmp.foo);
},
function subclass(t){
dojo.declare("tests._base.declare.tmp3", null, {
foo: "thonk"
});
dojo.declare("tests._base.declare.tmp4", tests._base.declare.tmp3);
var tmp = new tests._base.declare.tmp4();
t.is("thonk", tmp.foo);
},
function subclassWithCtor(t){
dojo.declare("tests._base.declare.tmp5", null, {
constructor: function(){
this.foo = "blah";
},
foo: "thonk"
});
dojo.declare("tests._base.declare.tmp6", tests._base.declare.tmp5);
var tmp = new tests._base.declare.tmp6();
t.is("blah", tmp.foo);
},
function mixinSubclass(t){
dojo.declare("tests._base.declare.tmp7", null, {
foo: "thonk"
});
dojo.declare("tests._base.declare.tmp8", null, {
constructor: function(){
this.foo = "blah";
}
});
var tmp = new tests._base.declare.tmp8();
t.is("blah", tmp.foo);
dojo.declare("tests._base.declare.tmp9",
[
tests._base.declare.tmp7, // prototypal
tests._base.declare.tmp8 // mixin
]);
var tmp2 = new tests._base.declare.tmp9();
t.is("blah", tmp2.foo);
},
function superclassRef(t){
dojo.declare("tests._base.declare.tmp10", null, {
foo: "thonk"
});
dojo.declare("tests._base.declare.tmp11", tests._base.declare.tmp10, {
constructor: function(){
this.foo = "blah";
}
});
var tmp = new tests._base.declare.tmp11();
t.is("blah", tmp.foo);
t.is("thonk", tests._base.declare.tmp11.superclass.foo);
},
function inheritedCall(t){
var foo = "xyzzy";
dojo.declare("tests._base.declare.tmp12", null, {
foo: "thonk",
bar: function(arg1, arg2){
if(arg1){
this.foo = arg1;
}
if(arg2){
foo = arg2;
}
}
});
dojo.declare("tests._base.declare.tmp13", tests._base.declare.tmp12, {
constructor: function(){
this.foo = "blah";
}
});
var tmp = new tests._base.declare.tmp13();
t.is("blah", tmp.foo);
t.is("xyzzy", foo);
tmp.bar("zot");
t.is("zot", tmp.foo);
t.is("xyzzy", foo);
tmp.bar("trousers", "squiggle");
t.is("trousers", tmp.foo);
t.is("squiggle", foo);
},
function inheritedExplicitCall(t){
var foo = "xyzzy";
dojo.declare("tests._base.declare.tmp14", null, {
foo: "thonk",
bar: function(arg1, arg2){
if(arg1){
this.foo = arg1;
}
if(arg2){
foo = arg2;
}
}
});
dojo.declare("tests._base.declare.tmp15", tests._base.declare.tmp14, {
constructor: function(){
this.foo = "blah";
},
bar: function(arg1, arg2){
this.inherited("bar", arguments, [arg2, arg1]);
},
baz: function(arg1, arg2){
tests._base.declare.tmp15.superclass.bar.apply(this, arguments);
}
});
var tmp = new tests._base.declare.tmp15();
t.is("blah", tmp.foo);
t.is("xyzzy", foo);
tmp.baz("zot");
t.is("zot", tmp.foo);
t.is("xyzzy", foo);
tmp.bar("trousers", "squiggle");
t.is("squiggle", tmp.foo);
t.is("trousers", foo);
},
function inheritedMixinCalls(t){
dojo.declare("tests._base.declare.tmp16", null, {
foo: "",
bar: function(){
this.foo += "tmp16";
}
});
dojo.declare("tests._base.declare.mixin16", null, {
bar: function(){
this.inherited(arguments);
this.foo += ".mixin16";
}
});
dojo.declare("tests._base.declare.mixin17", tests._base.declare.mixin16, {
bar: function(){
this.inherited(arguments);
this.foo += ".mixin17";
}
});
dojo.declare("tests._base.declare.tmp17", [tests._base.declare.tmp16, tests._base.declare.mixin17], {
bar: function(){
this.inherited(arguments);
this.foo += ".tmp17";
}
});
var tmp = new tests._base.declare.tmp17();
tmp.bar();
t.is("tmp16.mixin16.mixin17.tmp17", tmp.foo);
},
function mixinPreamble(t){
var passed = false;
dojo.declare("tests._base.declare.tmp16");
new tests._base.declare.tmp16({ preamble: function(){ passed = true; } });
t.t(passed);
}
// FIXME: there are still some permutations to test like:
// - ctor arguments
// - multi-level inheritance + L/R conflict checks
]
);
}
|