anise 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,131 +0,0 @@
1
- require 'anise/annotation'
2
-
3
- include Anise::Annotation
4
-
5
- class Test_Annotation_Toplevel_0 < Test::Unit::TestCase
6
- class X
7
- attr :a
8
- ann :a, :class => Integer
9
- ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
10
-
11
- def initialize(a)
12
- @a = a
13
- end
14
-
15
- def validate
16
- instance_variables.each do |iv|
17
- if validator = self.class.ann(iv)[:valid]
18
- value = instance_variable_get(iv)
19
- unless validator.call(value)
20
- raise "Invalid value #{value} for #{iv}"
21
- end
22
- end
23
- end
24
- end
25
- end
26
-
27
- def test_annotation_class
28
- assert_equal(Integer, X.ann(:a, :class))
29
- end
30
-
31
- def test_annotation_validate
32
- x = X.new(1)
33
- assert_nothing_raised{ x.validate }
34
- end
35
-
36
- end
37
-
38
- class Test_Annotation_Toplevel_1 < Test::Unit::TestCase
39
- class X
40
- def x1 ; end
41
- ann :x1, :a=>1
42
- ann :x1, :b=>2
43
- end
44
-
45
- def test_1_01
46
- assert_equal( X.ann(:x1,:a), X.ann(:x1,:a) )
47
- assert_equal( X.ann(:x1,:a).object_id, X.ann(:x1,:a).object_id )
48
- end
49
- def test_1_02
50
- X.ann :x1, :a => 2
51
- assert_equal( 2, X.ann(:x1,:a) )
52
- end
53
- end
54
-
55
- class Test_Annotation_Toplevel_2 < Test::Unit::TestCase
56
- class X
57
- def x1 ; end
58
- ann :x1, :a=>1
59
- ann :x1, :b=>2
60
- end
61
- class Y < X ; end
62
-
63
- def test_2_01
64
- assert_equal( Y.ann(:x1,:a), Y.ann(:x1,:a) )
65
- assert_equal( Y.ann(:x1,:a).object_id, Y.ann(:x1,:a).object_id )
66
- end
67
- def test_2_02
68
- assert_equal( 1, Y.ann(:x1,:a) )
69
- assert_equal( 2, Y.ann(:x1,:b) )
70
- end
71
- def test_2_03
72
- Y.ann :x1,:a => 2
73
- assert_equal( 2, Y.ann(:x1,:a) )
74
- assert_equal( 2, Y.ann(:x1,:b) )
75
- end
76
- end
77
-
78
- class Test_Annotation_Toplevel_3 < Test::Unit::TestCase
79
- class X
80
- ann :foo, Integer
81
- end
82
- class Y < X
83
- ann :foo, String
84
- end
85
-
86
- def test_3_01
87
- assert_equal( Integer, X.ann(:foo, :class) )
88
- end
89
- def test_3_02
90
- assert_equal( String, Y.ann(:foo, :class) )
91
- end
92
- end
93
-
94
- class Test_Annotation_Toplevel_4 < Test::Unit::TestCase
95
- class X
96
- ann :foo, :doc => "hello"
97
- ann :foo, :bar => []
98
- end
99
- class Y < X
100
- ann :foo, :class => String, :doc => "bye"
101
- end
102
-
103
- def test_4_01
104
- assert_equal( "hello", X.ann(:foo,:doc) )
105
- end
106
- def test_4_02
107
- assert_equal( X.ann(:foo), { :doc => "hello", :bar => [] } )
108
- end
109
- def test_4_03
110
- X.ann(:foo,:bar) << "1"
111
- assert_equal( ["1"], X.ann(:foo,:bar) )
112
- end
113
- def test_4_04
114
- assert_equal( "bye", Y.ann(:foo,:doc) )
115
- end
116
- def test_4_05
117
- #assert_equal( nil, Y.ann(:foo,:bar) )
118
- assert_equal( ["1"], Y.ann(:foo,:bar) )
119
- end
120
- def test_4_06
121
- Y.ann(:foo, :doc => "cap")
122
- assert_equal( "cap", Y.ann(:foo, :doc) )
123
- end
124
- def test_4_07
125
- Y.ann!(:foo,:bar) << "2"
126
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
127
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
128
- assert_equal( ["1"], X.ann(:foo,:bar) )
129
- end
130
- end
131
-
@@ -1,26 +0,0 @@
1
- require 'anise/annotator'
2
-
3
- class Test_Annotator < Test::Unit::TestCase
4
-
5
- class X
6
- include Anise::Annotator
7
-
8
- annotator :req
9
-
10
- req 'r'
11
- def a ; "a"; end
12
-
13
- req 'x', 'y'
14
- attr :b
15
- end
16
-
17
- def test_annotated
18
- assert_equal( {:req=>'r'}, X.ann(:a) )
19
- end
20
-
21
- def test_annotated
22
- assert_equal( {:req=>['x','y']}, X.ann(:b) )
23
- end
24
-
25
- end
26
-
@@ -1,28 +0,0 @@
1
- require 'anise/annotator'
2
-
3
- include Anise::Annotator
4
-
5
- class Test_Annotator_Toplevel < Test::Unit::TestCase
6
-
7
- class X
8
- annotator :req
9
-
10
- req 'r'
11
- def a ; "a"; end
12
-
13
- req 's', 't'
14
- attr :b
15
- end
16
-
17
- def test_annotated
18
- assert_equal( {:req=>'r'}, X.ann(:a) )
19
- end
20
-
21
- def test_annotated
22
- assert_equal( {:req=>['s','t']}, X.ann(:b) )
23
- end
24
-
25
- end
26
-
27
- #annotator :req # THIS DOES NOT WORK :(
28
-
@@ -1,37 +0,0 @@
1
- require 'anise/attribute'
2
-
3
- class Test_Attribute < Test::Unit::TestCase
4
- class X
5
- include Anise::Attribute
6
- attr :q
7
- attr :a, :x => 1
8
- end
9
-
10
- def test_attr_a
11
- assert_equal( {:x=>1}, X.ann(:a) )
12
- end
13
- end
14
-
15
- class Test_Attribute_Using_Attr < Test::Unit::TestCase
16
- class A
17
- include Anise::Attribute
18
- attr :x, :cast=>"to_s"
19
- end
20
-
21
- def test_01
22
- assert_equal( "to_s", A.ann(:x,:cast) )
23
- end
24
- end
25
-
26
- class Test_Attribute_Using_Attr_Accessor < Test::Unit::TestCase
27
- class A
28
- include Anise::Attribute
29
- attr_accessor :x, :cast=>"to_s"
30
- end
31
-
32
- def test_01
33
- a = A.new
34
- assert_equal( [:x], A.instance_attributes - [:taguri] )
35
- end
36
- end
37
-
@@ -1,65 +0,0 @@
1
- #require 'anise/annotation'
2
- require 'anise/attribute'
3
-
4
- include Anise::Attribute
5
-
6
- class Test_Attribute_Toplevel < Test::Unit::TestCase
7
- class X
8
- attr :q
9
- attr :a, :x => 1
10
- end
11
-
12
- def test_attr_a
13
- assert_equal( {:x=>1}, X.ann(:a) )
14
- end
15
- end
16
-
17
- class Test_Attribute_Toplevel_Using_Attr < Test::Unit::TestCase
18
- class A
19
- attr :x, :cast=>"to_s"
20
- end
21
-
22
- def test_01
23
- assert_equal( "to_s", A.ann(:x,:cast) )
24
- end
25
- end
26
-
27
- class Test_Attribute_Toplevel_Using_Attr_Accessor < Test::Unit::TestCase
28
- class A
29
- attr_accessor :x, :cast=>"to_s"
30
- end
31
-
32
- def test_01
33
- a = A.new
34
- assert_equal( [:x], A.instance_attributes - [:taguri] ) # taguri is from YAML :(
35
- end
36
- end
37
-
38
-
39
- =begin
40
- require 'annotable/attributes'
41
- require 'test/unit'
42
-
43
- include Anise::Attributes
44
-
45
- $self = self
46
-
47
- attr :b, :y => 1
48
-
49
- class Test_Attribute_Toplevel < Test::Unit::TestCase
50
-
51
- attr :q
52
-
53
- attr :a, :x => 1
54
-
55
- def test_attr_a
56
- assert_equal( {:x=>1}, self.class.ann(:a) )
57
- end
58
-
59
- def test_attr_b
60
- assert_equal( {:y=>1}, $self.class.ann(:b) )
61
- end
62
-
63
- end
64
- =end
65
-