anise 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +59 -38
- data/.yardopts +7 -0
- data/DEMO.md +242 -0
- data/{HISTORY.rdoc → HISTORY.md} +28 -7
- data/LICENSE.txt +27 -0
- data/README.md +129 -0
- data/demo/01_annotations.md +81 -0
- data/demo/03_attributes.md +14 -0
- data/demo/04_methods.md +50 -0
- data/demo/05_variables.md +45 -0
- data/{qed → demo}/applique/ae.rb +0 -0
- data/demo/applique/anise.rb +1 -0
- data/{qed/toplevel/01_annotations.qed → demo/toplevel/01_annotations.md} +5 -9
- data/demo/toplevel/03_attributes.md +20 -0
- data/lib/anise.rb +28 -45
- data/lib/anise.yml +59 -38
- data/lib/anise/annotations.rb +132 -0
- data/lib/anise/annotations/store.rb +136 -0
- data/lib/anise/annotative.rb +7 -0
- data/lib/anise/annotative/attributes.rb +147 -0
- data/lib/anise/annotative/methods.rb +131 -0
- data/lib/anise/annotative/variables.rb +99 -0
- data/lib/anise/{module.rb → core_ext.rb} +30 -0
- data/lib/anise/universal.rb +6 -0
- data/lib/anise/version.rb +17 -0
- data/test/case_annotations.rb +173 -0
- data/test/case_attributes.rb +46 -0
- data/test/case_combined_usage.rb +341 -0
- data/test/case_methods.rb +36 -0
- data/test/case_variables.rb +22 -0
- data/test/helper.rb +2 -0
- metadata +99 -98
- data/APACHE2.txt +0 -204
- data/COPYING.rdoc +0 -17
- data/README.rdoc +0 -107
- data/lib/anise/annotation.rb +0 -175
- data/lib/anise/annotator.rb +0 -82
- data/lib/anise/attribute.rb +0 -138
- data/qed/01_annotations.qed +0 -26
- data/qed/02_annotation_added.rdoc +0 -60
- data/qed/03_attributes.rdoc +0 -16
- data/qed/04_annotator.rdoc +0 -49
- data/qed/toplevel/03_attributes.rdoc +0 -20
- data/test/suite.rb +0 -8
- data/test/test_anise.rb +0 -193
- data/test/test_anise_toplevel.rb +0 -194
- data/test/test_annotations.rb +0 -136
- data/test/test_annotations_module.rb +0 -132
- data/test/test_annotations_toplevel.rb +0 -131
- data/test/test_annotator.rb +0 -26
- data/test/test_annotator_toplevel.rb +0 -28
- data/test/test_attribute.rb +0 -37
- data/test/test_attribute_toplevel.rb +0 -65
@@ -0,0 +1,46 @@
|
|
1
|
+
testcase Anise::Annotative::Attributes do
|
2
|
+
|
3
|
+
context "general" do
|
4
|
+
|
5
|
+
cX = Class.new do
|
6
|
+
extend Anise::Annotative::Attributes
|
7
|
+
attr :q
|
8
|
+
attr :a, :x => 1
|
9
|
+
end
|
10
|
+
|
11
|
+
test "attr :a" do
|
12
|
+
cX.ann(:a) == {:x=>1}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "attr" do
|
18
|
+
|
19
|
+
cA = Class.new do
|
20
|
+
extend Anise::Annotative::Attributes
|
21
|
+
attr :x, :cast=>"to_s"
|
22
|
+
end
|
23
|
+
|
24
|
+
test do
|
25
|
+
cA.ann(:x,:cast) == "to_s"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "attr_accessor" do
|
31
|
+
|
32
|
+
cA = Class.new do
|
33
|
+
extend Anise::Annotative::Attributes
|
34
|
+
attr_accessor :x, :cast=>"to_s"
|
35
|
+
end
|
36
|
+
|
37
|
+
test do
|
38
|
+
a = cA.new
|
39
|
+
r = cA.instance_attributes - [:taguri]
|
40
|
+
r == [:x]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,341 @@
|
|
1
|
+
# The intent of this testcase is test the variant annotaiton modules
|
2
|
+
# in conjunction, to make sure they can all be used together without
|
3
|
+
# conflict.
|
4
|
+
#
|
5
|
+
# All good intentions aside these cases need some *love*, as they are
|
6
|
+
# really just other cases thrown together and not really thought out
|
7
|
+
# as such. Still, something is better than nothing.
|
8
|
+
|
9
|
+
testcase "Combined Usage" do
|
10
|
+
|
11
|
+
context "simple co-existence of annotated methods and attributes" do
|
12
|
+
|
13
|
+
cX = Class.new do
|
14
|
+
extend Anise::Annotative::Methods
|
15
|
+
extend Anise::Annotative::Attributes
|
16
|
+
end
|
17
|
+
|
18
|
+
test "initialize" do
|
19
|
+
cX.new
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "method annotations work" do
|
25
|
+
|
26
|
+
cX = Class.new do
|
27
|
+
extend Anise::Annotative::Methods
|
28
|
+
extend Anise::Annotative::Attributes
|
29
|
+
|
30
|
+
method_annotator :doc
|
31
|
+
|
32
|
+
doc "a-okay captain"
|
33
|
+
def x; end
|
34
|
+
end
|
35
|
+
|
36
|
+
test "doc is defined for method" do
|
37
|
+
cX.ann(:x,:doc) == "a-okay captain"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "attribute annotations work" do
|
43
|
+
|
44
|
+
cX = Class.new do
|
45
|
+
extend Anise::Annotative::Methods
|
46
|
+
extend Anise::Annotative::Attributes
|
47
|
+
|
48
|
+
attr :x, :doc => "still okay"
|
49
|
+
end
|
50
|
+
|
51
|
+
test "annotation defined for attribute" do
|
52
|
+
cX.ann(:x,:doc) == "still okay"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "both method and attribute annotations work" do
|
58
|
+
|
59
|
+
cX = Class.new do
|
60
|
+
extend Anise::Annotative::Methods
|
61
|
+
extend Anise::Annotative::Attributes
|
62
|
+
|
63
|
+
method_annotator :doc
|
64
|
+
|
65
|
+
attr :x, :doc => "still okay"
|
66
|
+
|
67
|
+
doc "sure does"
|
68
|
+
def y; end
|
69
|
+
end
|
70
|
+
|
71
|
+
test "annotation defined for attribute" do
|
72
|
+
cX.ann(:x,:doc) == "still okay"
|
73
|
+
end
|
74
|
+
|
75
|
+
test "doc is defined for method" do
|
76
|
+
cX.ann(:y,:doc) == "sure does"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "using an annotation for attribute validation" do
|
82
|
+
|
83
|
+
cX = Class.new do
|
84
|
+
extend Anise::Annotations
|
85
|
+
extend Anise::Annotative::Methods
|
86
|
+
extend Anise::Annotative::Attributes
|
87
|
+
|
88
|
+
attr :a
|
89
|
+
|
90
|
+
ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
|
91
|
+
ann :a, :class => Integer
|
92
|
+
|
93
|
+
def initialize(a)
|
94
|
+
@a = a
|
95
|
+
end
|
96
|
+
|
97
|
+
def validate
|
98
|
+
instance_variables.each do |iv|
|
99
|
+
if validator = self.class.ann(iv)[:valid]
|
100
|
+
value = instance_variable_get(iv)
|
101
|
+
unless validator.call(value)
|
102
|
+
raise "Invalid value #{value} for #{iv}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
test "class" do
|
110
|
+
cX.ann(:a, :class) == Integer
|
111
|
+
end
|
112
|
+
|
113
|
+
test "validate" do
|
114
|
+
x = cX.new(1)
|
115
|
+
x.validate
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
context "2" do
|
121
|
+
|
122
|
+
cX = Class.new do
|
123
|
+
extend Anise::Annotations
|
124
|
+
extend Anise::Annotative::Methods
|
125
|
+
extend Anise::Annotative::Attributes
|
126
|
+
|
127
|
+
def x1 ; end
|
128
|
+
|
129
|
+
#annotator :ann
|
130
|
+
ann :x1, :a=>1
|
131
|
+
ann :x1, :b=>2
|
132
|
+
end
|
133
|
+
|
134
|
+
test "01" do
|
135
|
+
cX.ann(:x1,:a) == cX.ann(:x1,:a)
|
136
|
+
end
|
137
|
+
|
138
|
+
test "02" do
|
139
|
+
cX.ann(:x1,:a).object_id == cX.ann(:x1,:a).object_id
|
140
|
+
end
|
141
|
+
|
142
|
+
test "03" do
|
143
|
+
cX.ann :x1, :a => 2
|
144
|
+
cX.ann(:x1,:a) == 2
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
context "3" do
|
150
|
+
|
151
|
+
cX = Class.new do
|
152
|
+
extend Anise::Annotations
|
153
|
+
extend Anise::Annotative::Methods
|
154
|
+
extend Anise::Annotative::Attributes
|
155
|
+
|
156
|
+
def x1 ; end
|
157
|
+
|
158
|
+
#annotator :ann
|
159
|
+
ann :x1, :a=>1
|
160
|
+
ann :x1, :b=>2
|
161
|
+
end
|
162
|
+
|
163
|
+
cY = Class.new(cX)
|
164
|
+
|
165
|
+
test "01" do
|
166
|
+
cY.ann(:x1,:a) == cY.ann(:x1,:a)
|
167
|
+
end
|
168
|
+
|
169
|
+
test "02" do
|
170
|
+
cY.ann(:x1,:a).object_id == cY.ann(:x1,:a).object_id
|
171
|
+
end
|
172
|
+
|
173
|
+
test "03" do
|
174
|
+
cY.ann(:x1,:a) == 1
|
175
|
+
end
|
176
|
+
|
177
|
+
test "04" do
|
178
|
+
cY.ann(:x1,:b) == 2
|
179
|
+
end
|
180
|
+
|
181
|
+
test "05" do
|
182
|
+
cY.ann :x1,:a => 2
|
183
|
+
cY.ann(:x1,:a) == 2 &&
|
184
|
+
cY.ann(:x1,:b) == 2
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
context "4" do
|
190
|
+
|
191
|
+
cX = Class.new do
|
192
|
+
extend Anise::Annotations
|
193
|
+
extend Anise::Annotative::Methods
|
194
|
+
extend Anise::Annotative::Attributes
|
195
|
+
|
196
|
+
#annotator :ann
|
197
|
+
ann :foo, Integer
|
198
|
+
end
|
199
|
+
|
200
|
+
cY = Class.new(cX) do
|
201
|
+
ann :foo, String
|
202
|
+
end
|
203
|
+
|
204
|
+
test "01" do
|
205
|
+
cX.ann(:foo, :class) == Integer
|
206
|
+
end
|
207
|
+
|
208
|
+
test "02" do
|
209
|
+
cY.ann(:foo, :class) == String
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
context "5" do
|
215
|
+
|
216
|
+
cX = Class.new do
|
217
|
+
extend Anise::Annotations
|
218
|
+
extend Anise::Annotative::Methods
|
219
|
+
extend Anise::Annotative::Attributes
|
220
|
+
|
221
|
+
#annotator :ann
|
222
|
+
ann :foo, :doc => "hello"
|
223
|
+
ann :foo, :bar => []
|
224
|
+
end
|
225
|
+
|
226
|
+
cY = Class.new(cX) do
|
227
|
+
ann :foo, :class => String, :doc => "bye"
|
228
|
+
end
|
229
|
+
|
230
|
+
test "01" do
|
231
|
+
cX.ann(:foo,:doc) == "hello"
|
232
|
+
end
|
233
|
+
|
234
|
+
test "02" do
|
235
|
+
cX.ann(:foo) == {:doc=>"hello", :bar=>[]}
|
236
|
+
end
|
237
|
+
|
238
|
+
test "03" do
|
239
|
+
cX.ann(:foo,:bar) << "1"
|
240
|
+
cX.ann(:foo,:bar) == ["1"]
|
241
|
+
end
|
242
|
+
|
243
|
+
test "04" do
|
244
|
+
cY.ann(:foo,:doc) == "bye"
|
245
|
+
end
|
246
|
+
|
247
|
+
test "05" do
|
248
|
+
#cY.ann(:foo,:bar) == nil
|
249
|
+
cY.ann(:foo,:bar) == ["1"]
|
250
|
+
end
|
251
|
+
|
252
|
+
test "06" do
|
253
|
+
cY.ann(:foo, :doc => "cap")
|
254
|
+
cY.ann(:foo, :doc) == "cap"
|
255
|
+
end
|
256
|
+
|
257
|
+
test "07" do
|
258
|
+
cY.ann!(:foo,:bar) << "2"
|
259
|
+
cY.ann(:foo,:bar) == ["1", "2"] &&
|
260
|
+
cX.ann(:foo,:bar) == ["1"]
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
context "6" do
|
266
|
+
|
267
|
+
cX = Class.new do
|
268
|
+
extend Anise::Annotations
|
269
|
+
extend Anise::Annotative::Methods
|
270
|
+
extend Anise::Annotative::Attributes
|
271
|
+
|
272
|
+
method_annotator :req
|
273
|
+
|
274
|
+
req 'r'
|
275
|
+
def a ; "a"; end
|
276
|
+
|
277
|
+
req 's', 't'
|
278
|
+
attr :b
|
279
|
+
end
|
280
|
+
|
281
|
+
test "annotated" do
|
282
|
+
cX.ann(:a) == {:req=>'r'}
|
283
|
+
end
|
284
|
+
|
285
|
+
test "annotated" do
|
286
|
+
cX.ann(:b) == {:req=>['s','t']}
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
context "attribute" do
|
292
|
+
|
293
|
+
cX = Class.new do
|
294
|
+
extend Anise::Annotations
|
295
|
+
extend Anise::Annotative::Methods
|
296
|
+
extend Anise::Annotative::Attributes
|
297
|
+
|
298
|
+
attr :q
|
299
|
+
attr :a, :x => 1
|
300
|
+
end
|
301
|
+
|
302
|
+
test "a" do
|
303
|
+
cX.ann(:a) == {:x=>1}
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
context "attribute using attr" do
|
309
|
+
|
310
|
+
cA = Class.new do
|
311
|
+
extend Anise::Annotations
|
312
|
+
extend Anise::Annotative::Methods
|
313
|
+
extend Anise::Annotative::Attributes
|
314
|
+
|
315
|
+
attr :x, :cast=>"to_s"
|
316
|
+
end
|
317
|
+
|
318
|
+
test "cast" do
|
319
|
+
cA.ann(:x,:cast) == "to_s"
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
context "attribute using attr_accessor" do
|
325
|
+
|
326
|
+
cA = Class.new do
|
327
|
+
extend Anise::Annotations
|
328
|
+
extend Anise::Annotative::Methods
|
329
|
+
extend Anise::Annotative::Attributes
|
330
|
+
|
331
|
+
attr_accessor :x, :cast=>"to_s"
|
332
|
+
end
|
333
|
+
|
334
|
+
test "instance_attributes" do
|
335
|
+
iv = cA.instance_attributes - [:taguri]
|
336
|
+
iv == [:x]
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
testcase Anise::Annotative::Methods do
|
2
|
+
|
3
|
+
cX = Class.new do
|
4
|
+
extend Anise::Annotative::Methods
|
5
|
+
|
6
|
+
def self.req(val)
|
7
|
+
method_annotation(:req=>val)
|
8
|
+
end
|
9
|
+
|
10
|
+
req 'r'
|
11
|
+
def a ; "a"; end
|
12
|
+
|
13
|
+
req ['x', 'y']
|
14
|
+
attr :b
|
15
|
+
end
|
16
|
+
|
17
|
+
test do |a, h|
|
18
|
+
h.each do |k, r|
|
19
|
+
cX.ann(a, k).assert == r
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ok :a, :req => 'r'
|
24
|
+
ok :b, :req => ['x','y']
|
25
|
+
|
26
|
+
test do |h|
|
27
|
+
h.each do |a, r|
|
28
|
+
cX.ann(a).assert == r
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ok :a => {:req=>'r'}
|
33
|
+
ok :b => {:req=>['x','y']}
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
testcase Anise::Annotative::Variables do
|
2
|
+
|
3
|
+
context "general" do
|
4
|
+
|
5
|
+
cX = Class.new do
|
6
|
+
extend Anise::Annotative::Variables
|
7
|
+
|
8
|
+
@doc = "See what I mean?"
|
9
|
+
@returns = NilClass
|
10
|
+
|
11
|
+
def see
|
12
|
+
puts "Yes, I see!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test do
|
17
|
+
cX.ann(:see, :@doc) == "See what I mean?"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/helper.rb
ADDED