-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
161 lines (130 loc) · 3.86 KB
/
test.js
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
var scope;
if(typeof(exports) != "undefined"){
scope = exports;
var Zet = require("./zet");
var logger = require('./zetlog4node');
Zet.profile({
scope : scope, //needed for getClass
logger : logger
});
}else{
scope = window;
}
scope.Person = Zet.declare({
defineBody : function(that){
that._counter = 'zet_' + new Date().getTime();
var n = '';
Zet.public({
construct : function(n){
Zet.log('superClass.construct');
name = n;
},
getName : function(){
return name;
},
setName : function(n){
Zet.log('Person.setName',n);
name = n;
},
toString : function(){
return that._counter;
}
});
}
});
scope.User = Zet.declare( null , {
superclass : Zet.getClass('Person'),
defineBody : function(that){
var nickname = '';
var setNickname = function(nname){
nickname = nname;
}
Zet.public({
construct : function(firstName){
Zet.log('User.construct', firstName);
that.inherited([firstName])
},
setFirstName : function(name){
Zet.log('User.setFirstName');
that.setName(name +'_');
},
getFirstName : function(){
return that.getName();
},
getNickName : function(){
return nickname;
},
setNickName : function(nname){
setNickname(nname);
}
});
}
});
Zet.setClass('testUser',function(){
var u = Zet.getClass('User')('Maks'); //testing constructor inheritance facility
var name = u.getName();
if(name != 'Maks'){
Zet.log('User.test : Name is incorrect');
}
u.setFirstName('Maqz'); //testing calling direct super functions
var firstName = u.getName();
if(firstName != 'Maqz_'){
Zet.log('User.test : Firstname is ' + firstName + ' but not Maqz_');
}
u.setNickName('SomeNickName'); //testing private scoping
var nickname = u.getNickName();
if(nickname != 'SomeNickName'){
Zet.log('User.test : Nickname is ' + nickname + ' but not SomeNickName');
}
});
Zet.declare( 'module.Programmer' , {
superclass : Zet.getClass('User'),
defineBody : function(that){
Zet.public({
construct : function(name, nickname){
Zet.log('Programmer.construct');
that.inherited(arguments);
that.setNickName(nickname);
},
setName : function(name){
that.inherited([name + '-']);
},
});
}
});
Zet.setClass('testProgrammer', function(){
//testing namespace and scope
if(!Zet.getClass('module.Programmer')){
Zet.error('Programmer.test : Scope module does not exist');
return;
}
if(typeof(exports) != "undefined"){
if(!exports.module.Programmer){
Zet.error('Programmer.test : Class module.Programmer does not exist');
return;
}
}else{
if(!module.Programmer){
Zet.error('Programmer.test : Class module.Programmer does not exist');
return;
}
}
var p = Zet.getClass('module.Programmer')('Maqz');
// testing instanceOf
if(!(p.instanceOf(Zet.getClass('User')))){
Zet.error('Programmer.test : Instance of is broken');
}
if(!(p.instanceOf(Zet.getClass('Person')))){
Zet.error('Programmer.test : Instance of is broken for Person');
}
var name = p.getName(); // testing method from the top superclass
var name2 = p.getFirstName(); //testing method from User superclass
if((name != 'Maqz') || (name != name2)){
Zet.error('Programmer.test : Name is wrong ');
}
p.setName('Hello');
Zet.error('Programmer.test : Name is ' + p.getName());
if(p._counter != p.toString()){
Zet.log('Shit.test');
}
});