Skip to content

Commit d3d561b

Browse files
committed
Merge pull request #386 from mattjphillips/add_tests_for_bases
Add tests for bases: methods, properties, indexers. Including generation skipping.
2 parents 0e3f288 + 66bf380 commit d3d561b

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed

tests/ScriptTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public void TestTypeSystem() {
2222
RunTest("/TypeSystem.htm");
2323
}
2424

25+
[TestMethod]
26+
public void TestBases() {
27+
RunTest("/Bases.htm");
28+
}
29+
2530
#region Loader Tests
2631
[TestMethod]
2732
public void TestLoader() {

tests/TestSite/Bases.htm

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Bases</title>
5+
<link rel="stylesheet" href="QUnit/QUnit.css" type="text/css" />
6+
<script type="text/javascript" src="QUnit/QUnit.js"></script>
7+
<script type="text/javascript" src="QUnit/QUnitExt.js"></script>
8+
</head>
9+
<body>
10+
<h1 id="qunit-header">Test Results</h1>
11+
<h2 id="qunit-banner"></h2>
12+
<h2 id="qunit-userAgent"></h2>
13+
<ol id="qunit-tests"></ol>
14+
<br />
15+
<textarea id="qunit-log" rows="10" cols="100"></textarea>
16+
</body>
17+
18+
<script type="text/javascript" src="Scripts/ssloader.min.js"></script>
19+
<script type="text/script" data-name="ss" data-src="Scripts/ss.min.js"></script>
20+
<script type="text/script" data-name="oop" data-src="Scripts/OOP.js"></script>
21+
22+
<script type="text/script">
23+
define(['ss', 'oop'], function(ss, oop) {
24+
module('OOP');
25+
26+
test('bases', function() {
27+
var output1 = oop.TestCase.runTest(new oop.C1());
28+
QUnit.equal(output1, "A-PC1,A-MC1,A-99IC1,X+PC1-PC1,Y+88IC1-99IC1", "Code path through base classes problem (C1)");
29+
30+
var output2 = oop.TestCase.runTest(new oop.C2());
31+
QUnit.equal(output2, "A-PC1-PC2,A-MC1-MC2,A-99IC1-99IC2,X+PC2+PC1-PC1-PC2,Y+88IC2+88IC1-99IC1-99IC2", "Code path through base classes problem (C2)");
32+
33+
var output3 = oop.TestCase.runTest(new oop.C3());
34+
QUnit.equal(output3, "A-PC1-PC2-PC3,A-MC1-MC2-MC3,A-99IC1-99IC2-99IC3,X+PC3+PC2+PC1-PC1-PC2-PC3,Y+88IC3+88IC2+88IC1-99IC1-99IC2-99IC3", "Code path through base classes problem (C3)");
35+
36+
// A C4 should act just like a C3 as it has no overrides
37+
var output4 = oop.TestCase.runTest(new oop.C4());
38+
QUnit.equal(output4, "A-PC1-PC2-PC3,A-MC1-MC2-MC3,A-99IC1-99IC2-99IC3,X+PC3+PC2+PC1-PC1-PC2-PC3,Y+88IC3+88IC2+88IC1-99IC1-99IC2-99IC3", "Code path through base classes problem (C4)");
39+
40+
var output5 = oop.TestCase.runTest(new oop.C5());
41+
QUnit.equal(output5, "A-PC1-PC2-PC3-PC5,A-MC1-MC2-MC3-MC5,A-99IC1-99IC2-99IC3-99IC5,X+PC5+PC3+PC2+PC1-PC1-PC2-PC3-PC5,Y+88IC5+88IC3+88IC2+88IC1-99IC1-99IC2-99IC3-99IC5", "Code path through base classes problem (C5)");
42+
});
43+
});
44+
</script>
45+
</html>

tests/TestSite/Code/OOP.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,140 @@ public interface IObject {
121121
public class Zoo {
122122
}
123123
}
124+
125+
126+
namespace Test.Bases {
127+
128+
// A series of classes with different combinations of overrides at different
129+
// levels in the class hierarchy. Tests issues #379, #384 as applied to properties,
130+
// methods, and index operators.
131+
132+
public class C1 {
133+
private string _valueA = "A";
134+
135+
public virtual string PropertyA {
136+
get {
137+
return _valueA + "-PC1";
138+
}
139+
set {
140+
_valueA = value + "+PC1";
141+
}
142+
}
143+
144+
public virtual string MethodA() {
145+
return _valueA + "-MC1";
146+
}
147+
148+
public virtual string this[int key] {
149+
get {
150+
return _valueA + "-" + key.ToString() + "IC1";
151+
}
152+
set {
153+
_valueA = value + "+" + key.ToString() + "IC1";
154+
}
155+
}
156+
}
157+
158+
public class C2 : C1 {
159+
public override string PropertyA {
160+
get {
161+
return base.PropertyA + "-PC2";
162+
}
163+
set {
164+
base.PropertyA = value + "+PC2";
165+
}
166+
}
167+
168+
public override string MethodA() {
169+
return base.MethodA() + "-MC2";
170+
}
171+
172+
public override string this[int key] {
173+
get {
174+
return base[key] + "-" + key.ToString() + "IC2";
175+
}
176+
set {
177+
base[key] = value + "+" + key.ToString() + "IC2";
178+
}
179+
}
180+
}
181+
182+
public class C3 : C2 {
183+
public override string PropertyA {
184+
get {
185+
return base.PropertyA + "-PC3";
186+
}
187+
set {
188+
base.PropertyA = value + "+PC3";
189+
}
190+
}
191+
192+
public override string MethodA() {
193+
return base.MethodA() + "-MC3";
194+
}
195+
196+
public override string this[int key] {
197+
get {
198+
return base[key] + "-" + key.ToString() + "IC3";
199+
}
200+
set {
201+
base[key] = value + "+" + key.ToString() + "IC3";
202+
}
203+
}
204+
}
205+
206+
public class C4 : C3 {
207+
// intentionally skip this generation of overrides
208+
}
209+
210+
public class C5 : C4 {
211+
public override string PropertyA {
212+
get {
213+
return base.PropertyA + "-PC5";
214+
}
215+
set {
216+
base.PropertyA = value + "+PC5";
217+
}
218+
}
219+
220+
public override string MethodA() {
221+
return base.MethodA() + "-MC5";
222+
}
223+
224+
public override string this[int key] {
225+
get {
226+
return base[key] + "-" + key.ToString() + "IC5";
227+
}
228+
set {
229+
base[key] = value + "+" + key.ToString() + "IC5";
230+
}
231+
}
232+
}
233+
234+
public class TestCase {
235+
236+
public static string RunTest(C1 x) {
237+
string output = "";
238+
string delim = ",";
239+
240+
// Test getter, method, and index (should accumulate outward through bases)
241+
output = x.PropertyA
242+
+ delim + x.MethodA()
243+
+ delim + x[99];
244+
245+
// Test property setter (should accumulate inward and outward through bases)
246+
247+
x.PropertyA = "X";
248+
output += delim + x.PropertyA;
249+
250+
// Test index setter (should accumulate inward and outward through bases)
251+
252+
x[88] = "Y";
253+
output += delim + x[99];
254+
255+
return output;
256+
}
257+
258+
}
259+
260+
}

0 commit comments

Comments
 (0)