-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestclass.sh
executable file
·162 lines (137 loc) · 3.31 KB
/
testclass.sh
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
#!/bin/bash
source static/oop.lib.sh
DEBUG=1
class Car
public Car
public set
public Drive
public Stop
public Check
public getColor
public testpvt
inst var color "red"
inst var motion
Car::Car() {
motion="Stop"
}
Car::set() { :; }
Car::Drive() { motion="Go"; }
Car::Stop() { motion="Stop"; }
Car::Check() { println "$motion"; }
Car::getColor() { println "$color"; }
Car::testpvt() { Car::pvtFunc; }
Car::pvtFunc() { println "private function of $(getColor) car"; }
class Garage
public park
public unpark
public size
public car
inst Array bay
Garage::Garage() { :; }
Garage::park() {
debug 5 "Parking $value"
bay+=($value)
}
Garage::remove() {
bay[$value]=''
}
Garage::size() {
debug 5 "Finding size"
print $((${#bay[@]} - 1))
}
Garage::car() {
debug 5 "Finding car at bay $value"
print "${bay[$value]}"
}
class Cat
public Cat
public set
public Drive
public Stop
public Check
public getColor
public setVoice
public speak
public ondestroy
inst var color "black"
inst var motion
inst var voice "MEOW"
Cat::Cat() {
motion="Sleeping"
}
Cat::setVoice() { voice=$value; }
Cat::speak() { println "==$voice=="; }
Cat::set() { :; }
Cat::Drive() { motion="Run"; }
Cat::Stop() { motion="Sleep"; }
Cat::Check() { println "$motion"; }
Cat::getColor() { println "$color"; }
Cat::ondestroy() { println "RWORW!!"; }
import Cat
import Car
debug 1 "Imported %s %s" "Cat" "Car"
new Car limo color: black
new Cat whiskers color: orange
new Car jag color: black
new Cat blackie
println
println "Blackie is a $(blackie.getColor) $(typeof blackie)"
println "Whiskers is a $(whiskers.getColor) $(typeof whiskers)"
println "He says $(whiskers.speak)"
whiskers.setVoice "Hisss!!!"
println "And sometimes $(whiskers.speak)"
println "Jag is a $(jag.getColor) $(typeof jag)"
jag.set color: blue
println "But I just painted the $(typeof jag) $(jag.getColor)"
println "Private ... $(jag.testpvt)"
println Testing complex arguments...
jag.set color: "light blue"
println The jag\'s color is now $(jag.getColor)
colorname="a pretty aweful shade of crap"
jag.set color: $colorname
println The jag is now $(jag.getColor)
class Kitten
subclass Cat
inst var size
new Kitten junior
if kindof Cat junior; then
println "Junior is a type of CAT!"
else
println "Junior is NOT A CAT"
fi
if kindof Car junior; then
println "Junior is form of Car"
else
println "Junior is NOT A CAR"
fi
println "Can he speak?"
if implements speak junior; then
junior.speak
fi
println "Asserts ..."
assert 'kindof Cat junior'
println "junior is a $(typeof junior)"
println "He says $(junior.speak)"
println "He is $(junior.getColor)"
println "whiskers is a $(typeof whiskers)"
assert 'implements ondestroy whiskers'
destroy whiskers
println "Puttings cars in garage"
new Garage workshop
new Garage repairshop
workshop.park limo
repairshop.park jag
repairshop.park limo
new Car fiero color:blue
repairshop.park fiero
workshop.park jag
println "There are $(workshop.size) cars in the workshop"
println "The first car is $(workshop.car 1)"
println "The second car is $(workshop.car 2)"
println "The repairshop has $(repairshop.size) cars"
println "First: $(repairshop.car 1) Second: $(repairshop.car 2) Third: $(repairshop.car 3)"
#assert 'implements ondestroy whiskers'
println "whiskers is a $(typeof whiskers)"
assert '[ 5 -gt 3 ]'
assert '[ 3 -gt 5 ]'
# declare -F | grep "Cat::"