1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ <!--<script src="misc.js" ></script>-->
5
+ < script src ="extend.min.js " > </ script >
6
+ </ head >
7
+ < body >
8
+
9
+ </ Body >
10
+ < script >
11
+ function WriteUnitTest ( success , text ) {
12
+ document . body . innerHTML += '<div style="color:' + ( success ?"#00BB00" :"#FF0000" ) + '">' + text + '</div>'
13
+ }
14
+
15
+ //UNIT TESTS!
16
+ //They are ugly but they work
17
+
18
+ Class . extend ( function myClass ( ) {
19
+ this . test = 2 ;
20
+ this . constructor = function ( ) {
21
+ this . myfunction ( "----" ) ;
22
+ }
23
+ this . myfunction = function ( passed ) {
24
+ return passed ;
25
+ }
26
+ this . wrapper = function ( passed ) {
27
+ return this . myfunction ( passed )
28
+ }
29
+ this . toptest = function ( passed ) {
30
+ return passed + "-"
31
+ }
32
+ } )
33
+
34
+ myClass . extend ( function myClass2 ( ) {
35
+ this . toptest = function ( passed ) {
36
+ return this . super . toptest ( passed ) + "*" ;
37
+ }
38
+ } )
39
+
40
+ myClass2 . extend ( function myClass3 ( ) {
41
+ this . myfunction = function ( passed ) {
42
+ return "123" + this . super . myfunction ( passed ) ;
43
+ }
44
+ this . superduper = function ( passed ) {
45
+ return this . super . myfunction ( passed ) ;
46
+ }
47
+ } )
48
+
49
+ myClass2 . extend ( function myClass4 ( ) {
50
+ this . test = 4 ;
51
+ this . myfunction = function ( passed ) {
52
+ return "1234" + this . super . myfunction ( passed ) ;
53
+ }
54
+ } )
55
+
56
+ myClass3 . extend ( function myClass5 ( ) {
57
+ } )
58
+
59
+ Class . extend ( function newClass ( ) {
60
+ this . constructor = function ( ) {
61
+ var that = this
62
+ setTimeout ( function ( ) { that . testMethod ( "[Instance newClass]" ) } , 1 )
63
+ }
64
+ this . testMethod = function ( compare ) {
65
+ WriteUnitTest ( this . toString ( ) == compare , "Testing that scope is reset for global scope execution of class methods for " + compare )
66
+ }
67
+ } )
68
+
69
+ newClass . extend ( function newClass2 ( ) {
70
+ this . constructor = function ( ) {
71
+ var that = this
72
+ setTimeout ( function ( ) { that . testMethod ( "[Instance newClass2]" ) } , 1 )
73
+ }
74
+ } )
75
+
76
+ var didExecute = false
77
+ Class . extend ( function PrototypeTestClass ( ) {
78
+ this . constructor = function ( value ) {
79
+ didExecute = value
80
+ }
81
+ } )
82
+ PrototypeTestClass . extend ( function PrototypeTestClass2 ( ) {
83
+ } )
84
+ PrototypeTestClass2 . extend ( function PrototypeTestClass3 ( ) {
85
+ this . constructor = function ( ) {
86
+ this . super ( "Success" )
87
+ }
88
+ } )
89
+
90
+
91
+ Class . extend ( function RootClass ( ) {
92
+ this . test = function ( ) {
93
+ return "--" + this . inner ( )
94
+ }
95
+ this . inner = function ( ) {
96
+ return "ERROR"
97
+ }
98
+ } )
99
+ RootClass . extend ( function MidClass ( ) {
100
+ this . test = function ( ) {
101
+ return "||" + this . super . test ( ) ;
102
+ }
103
+ this . inner = function ( ) {
104
+ return "ERROR"
105
+ }
106
+ } )
107
+ MidClass . extend ( function ChildClass ( ) {
108
+ this . inner = function ( ) {
109
+ return "**"
110
+ }
111
+ } )
112
+
113
+
114
+
115
+ new newClass ( )
116
+ new newClass2 ( )
117
+ WriteUnitTest ( myClass . toString ( ) == "[Class myClass]" , "Testing myClass toString" )
118
+ WriteUnitTest ( myClass3 . toString ( ) == "[Class myClass3]" , "Testing myClass3 toString" )
119
+ WriteUnitTest ( new myClass ( ) . toString ( ) == "[Instance myClass]" , "Testing instance of myClass toString" )
120
+ WriteUnitTest ( new myClass2 ( ) . toString ( ) == "[Instance myClass2]" , "Testing instance of myClass toString lvl 2" )
121
+ WriteUnitTest ( new myClass3 ( ) . toString ( ) == "[Instance myClass3]" , "Testing instance of myClass toString lvl 3" )
122
+ WriteUnitTest ( new myClass ( ) != new myClass ( ) , "Testing that two instances of same object is not the same" )
123
+ WriteUnitTest ( new myClass ( ) . myfunction ( "test" ) == "test" , "Testing that we can call a sub method" )
124
+ WriteUnitTest ( new myClass2 ( ) . myfunction ( "test" ) == "test" , "Testing that level 1 inherited value is correctly inherited" )
125
+ WriteUnitTest ( new myClass3 ( ) . myfunction ( "test" ) == "123test" , "Testing that level 2 inherited value is correctly inherited" )
126
+ WriteUnitTest ( new myClass4 ( ) . myfunction ( "test" ) == "1234test" , "Testing that level 3 inherited value is correctly inherited" )
127
+ WriteUnitTest ( new myClass3 ( ) instanceof myClass3 , "Testing instance of same class" )
128
+ WriteUnitTest ( new myClass3 ( ) instanceof myClass2 , "Testing instance of sub class lvl 1" )
129
+ WriteUnitTest ( new myClass3 ( ) instanceof myClass , "Testing instance of sub class lvl 2" )
130
+ WriteUnitTest ( new myClass4 ( ) instanceof myClass4 , "Testing instance of sub class level 3" )
131
+ WriteUnitTest ( ! ( new myClass3 ( ) instanceof myClass4 ) , "Testing that classes do not inherit incorrectly" )
132
+ WriteUnitTest ( new myClass ( ) . test == 2 , "Testing that simple values work" )
133
+ WriteUnitTest ( new myClass3 ( ) . test == 2 , "Testing that simple values are inherited" )
134
+ WriteUnitTest ( new myClass4 ( ) . test == 4 , "Testing that simple values can be overloaded" )
135
+ WriteUnitTest ( new myClass3 ( ) . superduper ( "test" ) == "test" , "Testing that Super referance is correctly maintained" )
136
+ WriteUnitTest ( new myClass3 ( ) . wrapper ( "test" ) == "123test" , "Testing that secound level internal method calls works" )
137
+ WriteUnitTest ( new myClass4 ( ) . wrapper ( "test" ) == "1234test" , "Testing that third level internal method calls works" )
138
+ WriteUnitTest ( new myClass5 ( ) . toptest ( "" ) == "-*" , "Validate if inherited methods does not clone incorrectly" )
139
+ new PrototypeTestClass3 ( )
140
+ WriteUnitTest ( didExecute == "Success" , "Testing if we can call constructor via non existing constructor overwrite" ) //*/
141
+ WriteUnitTest ( new ChildClass ( ) . test ( ) == "||--**" , "Secound validation for complex scopes" )
142
+
143
+
144
+ </ script >
145
+ </ html >
0 commit comments