cauterize 0.0.1.pre1 → 0.0.1.pre5
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.
- data/.gitignore +5 -0
- data/.rspec +1 -1
- data/Gemfile +1 -1
- data/README.md +0 -2
- data/Rakefile +19 -3
- data/bin/cauterize +14 -6
- data/example/Cauterize +22 -10
- data/example/build.sh +15 -2
- data/lib/cauterize/base_type.rb +2 -5
- data/lib/cauterize/builders.rb +1 -3
- data/lib/cauterize/builders/c/buildable.rb +3 -2
- data/lib/cauterize/builders/c/builtin.rb +46 -0
- data/lib/cauterize/builders/c/enumeration.rb +23 -2
- data/lib/cauterize/builders/c/fixed_array.rb +16 -7
- data/lib/cauterize/builders/c/group.rb +32 -3
- data/lib/cauterize/builders/c/scalar.rb +5 -0
- data/lib/cauterize/builders/c/variable_array.rb +1 -1
- data/lib/cauterize/builders/cs/buildable.rb +59 -0
- data/lib/cauterize/builders/cs/builtin.rb +23 -0
- data/lib/cauterize/builders/cs/composite.rb +21 -0
- data/lib/cauterize/builders/cs/csarray.rb +32 -0
- data/lib/cauterize/builders/cs/enumeration.rb +21 -0
- data/lib/cauterize/builders/cs/fixed_array.rb +25 -0
- data/lib/cauterize/builders/cs/group.rb +33 -0
- data/lib/cauterize/builders/cs/scalar.rb +10 -0
- data/lib/cauterize/builders/cs/variable_array.rb +34 -0
- data/lib/cauterize/builtin.rb +52 -0
- data/lib/cauterize/c_builder.rb +15 -1
- data/lib/cauterize/cauterize.rb +44 -13
- data/lib/cauterize/composite.rb +3 -3
- data/lib/cauterize/cs_builder.rb +53 -0
- data/lib/cauterize/enumeration.rb +20 -3
- data/lib/cauterize/fixed_array.rb +3 -3
- data/lib/cauterize/formatter.rb +7 -3
- data/lib/cauterize/group.rb +5 -8
- data/lib/cauterize/scalar.rb +16 -7
- data/lib/cauterize/variable_array.rb +6 -6
- data/lib/cauterize/version.rb +1 -1
- data/spec/base_type_spec.rb +133 -125
- data/spec/builders/c/buildable_spec.rb +18 -18
- data/spec/builders/c/builtin_spec.rb +22 -0
- data/spec/builders/c/composite_spec.rb +37 -33
- data/spec/builders/c/enumeration_spec.rb +84 -21
- data/spec/builders/c/fixed_array_spec.rb +6 -6
- data/spec/builders/c/group_spec.rb +97 -90
- data/spec/builders/c/scalar_spec.rb +24 -6
- data/spec/builders/c/variable_array_spec.rb +37 -37
- data/spec/builders/cs/buildable_spec.rb +8 -0
- data/spec/builders/cs/composite_spec.rb +32 -0
- data/spec/builders/cs/enumeration_spec.rb +33 -0
- data/spec/builders/cs/fixed_array_spec.rb +40 -0
- data/spec/builders/cs/group_spec.rb +56 -0
- data/spec/builders/cs/scalar_spec.rb +7 -0
- data/spec/builders/cs/variable_array_spec.rb +46 -0
- data/spec/builders_spec.rb +38 -38
- data/spec/builtin_spec.rb +46 -0
- data/spec/c_builder_spec.rb +116 -102
- data/spec/cauterize_spec.rb +8 -1
- data/spec/composite_spec.rb +52 -48
- data/spec/cs_builder_spec.rb +113 -0
- data/spec/enumeration_spec.rb +55 -16
- data/spec/fixed_array_spec.rb +7 -9
- data/spec/group_spec.rb +81 -76
- data/spec/scalar_spec.rb +20 -10
- data/spec/spec_helper.rb +103 -94
- data/spec/support/shared_examples_for_c_buildables.rb +68 -64
- data/spec/variable_array_spec.rb +12 -17
- data/{c → support/c}/src/cauterize.c +8 -7
- data/support/c/src/cauterize.h +59 -0
- data/{c → support/c}/src/cauterize_debug.h +0 -0
- data/support/c/src/cauterize_util.h +49 -0
- data/{c → support/c}/test/greatest.h +0 -0
- data/{c → support/c}/test/test.c +0 -0
- data/support/cs/src/CauterizeCompositeFormatter.cs +34 -0
- data/support/cs/src/CauterizeContainerFormatter.cs +18 -0
- data/support/cs/src/CauterizeEnumFormatter.cs +67 -0
- data/support/cs/src/CauterizeException.cs +15 -0
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +39 -0
- data/support/cs/src/CauterizeFormatter.cs +40 -0
- data/support/cs/src/CauterizeGroupFormatter.cs +46 -0
- data/support/cs/src/CauterizePrimitiveFormatter.cs +33 -0
- data/support/cs/src/CauterizeTypeFormatterFactory.cs +39 -0
- data/support/cs/src/CauterizeTypes.cs +107 -0
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +49 -0
- data/support/cs/src/ICauterizeTypeFormatter.cs +12 -0
- data/support/cs/src/OrderAttribute.cs +50 -0
- data/support/cs/src/PrimitiveSupport.cs +134 -0
- data/support/cs/src/SerializedRepresentationAttribute.cs +24 -0
- data/support/cs/test/CauterizeCompositeFormatterTest.cs +59 -0
- data/support/cs/test/CauterizeEnumFormatterTest.cs +110 -0
- data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +91 -0
- data/support/cs/test/CauterizeFormatterTest.cs +40 -0
- data/support/cs/test/CauterizeGroupFormatterTest.cs +147 -0
- data/support/cs/test/CauterizeIntegrationTest.cs +129 -0
- data/support/cs/test/CauterizePrimitiveFormatterTest.cs +98 -0
- data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +73 -0
- data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +130 -0
- data/support/cs/test/OrderAttributeTest.cs +39 -0
- data/support/cs/test/SerializedRepresentationAttributeTest.cs +39 -0
- metadata +68 -10
- data/c/src/cauterize.h +0 -46
- data/c/src/cauterize_util.h +0 -7
data/spec/enumeration_spec.rb
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
describe EnumerationValue do
|
1
|
+
module Cauterize
|
2
|
+
describe Cauterize::EnumerationValue do
|
5
3
|
describe :initialize do
|
6
4
|
it "creates an EnumerationValue" do
|
7
|
-
e = EnumerationValue.new(:foo, 1)
|
5
|
+
e = Cauterize::EnumerationValue.new(:foo, 1)
|
8
6
|
e.name.should == :foo
|
9
7
|
e.value.should == 1
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
|
-
describe Enumeration do
|
12
|
+
describe Cauterize::Enumeration do
|
15
13
|
describe :initialize do
|
16
14
|
it "creates a new enumeration with the right name" do
|
17
|
-
Enumeration.new(:foo).name.should == :foo
|
15
|
+
Cauterize::Enumeration.new(:foo).name.should == :foo
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
describe :value do
|
22
20
|
it "adds a new value to the enumeration" do
|
23
|
-
enum = enumeration(:foo) do |e|
|
21
|
+
enum = Cauterize.enumeration(:foo) do |e|
|
24
22
|
e.value :a
|
25
23
|
e.value :b
|
26
24
|
e.value :c
|
@@ -34,7 +32,7 @@ describe Cauterize do
|
|
34
32
|
end
|
35
33
|
|
36
34
|
it "accepts a fixed value" do
|
37
|
-
enum = enumeration(:foo) do |e|
|
35
|
+
enum = Cauterize.enumeration(:foo) do |e|
|
38
36
|
e.value :a, 10
|
39
37
|
e.value :b, 20
|
40
38
|
e.value :c
|
@@ -47,7 +45,7 @@ describe Cauterize do
|
|
47
45
|
|
48
46
|
it "allows out-of-order values" do
|
49
47
|
lambda {
|
50
|
-
enumeration(:foo) do |e|
|
48
|
+
Cauterize.enumeration(:foo) do |e|
|
51
49
|
e.value :a, 10
|
52
50
|
e.value :b, 9
|
53
51
|
end
|
@@ -56,7 +54,7 @@ describe Cauterize do
|
|
56
54
|
|
57
55
|
it "doesn't allow duplicate ids" do
|
58
56
|
lambda {
|
59
|
-
enumeration(:foo) do |e|
|
57
|
+
Cauterize.enumeration(:foo) do |e|
|
60
58
|
e.value :a, 1
|
61
59
|
e.value :b, 1
|
62
60
|
end
|
@@ -64,7 +62,7 @@ describe Cauterize do
|
|
64
62
|
end
|
65
63
|
|
66
64
|
it "doesn't allow accidentally identical ids" do
|
67
|
-
en = enumeration(:foo) do |e|
|
65
|
+
en = Cauterize.enumeration(:foo) do |e|
|
68
66
|
e.value :a, 10
|
69
67
|
e.value :b, 9
|
70
68
|
e.value :c
|
@@ -75,30 +73,71 @@ describe Cauterize do
|
|
75
73
|
|
76
74
|
it "errors on duplicate names" do
|
77
75
|
lambda {
|
78
|
-
enumeration(:foo) do |e|
|
76
|
+
Cauterize.enumeration(:foo) do |e|
|
79
77
|
e.value :a
|
80
78
|
e.value :a
|
81
79
|
end
|
82
80
|
}.should raise_error /duplicate name/
|
83
81
|
end
|
84
82
|
end
|
83
|
+
|
84
|
+
describe :representation do
|
85
|
+
it "chooses int8 when appropriate" do
|
86
|
+
Cauterize.enumeration(:a) do |t|
|
87
|
+
t.value :a, -128
|
88
|
+
end.representation.name.should == :int8
|
89
|
+
Cauterize.enumeration(:b) do |t|
|
90
|
+
t.value :a, 127
|
91
|
+
end.representation.name.should == :int8
|
92
|
+
end
|
93
|
+
|
94
|
+
it "chooses int16 when appropriate" do
|
95
|
+
Cauterize.enumeration(:a) do |t|
|
96
|
+
t.value :a, -32768
|
97
|
+
end.representation.name.should == :int16
|
98
|
+
Cauterize.enumeration(:b) do |t|
|
99
|
+
t.value :a, 32767
|
100
|
+
end.representation.name.should == :int16
|
101
|
+
Cauterize.enumeration(:c) do |t|
|
102
|
+
t.value :a, 300
|
103
|
+
end.representation.name.should == :int16
|
104
|
+
end
|
105
|
+
|
106
|
+
it "chooses int32 when appropriate" do
|
107
|
+
Cauterize.enumeration(:a) do |t|
|
108
|
+
t.value :a, -2147483648
|
109
|
+
end.representation.name.should == :int32
|
110
|
+
Cauterize.enumeration(:b) do |t|
|
111
|
+
t.value :a, 2147483647
|
112
|
+
end.representation.name.should == :int32
|
113
|
+
end
|
114
|
+
|
115
|
+
it "chooses int64 when appropriate" do
|
116
|
+
Cauterize.enumeration(:a) do |t|
|
117
|
+
t.value :a, -9223372036854775808
|
118
|
+
end.representation.name.should == :int64
|
119
|
+
Cauterize.enumeration(:b) do |t|
|
120
|
+
t.value :a, 9223372036854775807
|
121
|
+
end.representation.name.should == :int64
|
122
|
+
end
|
123
|
+
end
|
85
124
|
end
|
86
125
|
|
87
126
|
describe :enumeration do
|
88
127
|
it { creates_a_named_object(:enumeration, Enumeration) }
|
89
128
|
it { retrieves_obj_with_identical_name(:enumeration) }
|
90
129
|
it { yields_the_object(:enumeration) }
|
91
|
-
it { adds_object_to_hash(:enumeration,
|
130
|
+
it { adds_object_to_hash(:enumeration, Cauterize.enumerations) }
|
92
131
|
end
|
93
132
|
|
94
133
|
describe :enumeration! do
|
95
134
|
it { creates_a_named_object(:enumeration!, Enumeration) }
|
96
135
|
it { raises_exception_with_identical_name(:enumeration!) }
|
97
136
|
it { yields_the_object(:enumeration!) }
|
98
|
-
it { adds_object_to_hash(:enumeration!,
|
137
|
+
it { adds_object_to_hash(:enumeration!, Cauterize.enumerations) }
|
99
138
|
end
|
100
139
|
|
101
140
|
describe :enumerations do
|
102
|
-
it { is_hash_of_created_objs(:enumeration,
|
141
|
+
it { is_hash_of_created_objs(:enumeration, Cauterize.enumerations) }
|
103
142
|
end
|
104
143
|
end
|
data/spec/fixed_array_spec.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
2
|
-
before { reset_for_test }
|
3
|
-
|
1
|
+
module Cauterize
|
4
2
|
describe :fixed_array do
|
5
3
|
it { creates_a_named_object(:fixed_array, FixedArray) }
|
6
4
|
it { retrieves_obj_with_identical_name(:fixed_array) }
|
7
5
|
it { yields_the_object(:fixed_array) }
|
8
|
-
it { adds_object_to_hash(:fixed_array,
|
6
|
+
it { adds_object_to_hash(:fixed_array, Cauterize.fixed_arrays) }
|
9
7
|
end
|
10
8
|
|
11
9
|
describe :fixed_array! do
|
12
10
|
it { creates_a_named_object(:fixed_array!, FixedArray) }
|
13
11
|
it { raises_exception_with_identical_name(:variable_array!) }
|
14
12
|
it { yields_the_object(:fixed_array!) }
|
15
|
-
it { adds_object_to_hash(:fixed_array!,
|
13
|
+
it { adds_object_to_hash(:fixed_array!, Cauterize.fixed_arrays) }
|
16
14
|
end
|
17
15
|
|
18
16
|
describe FixedArray do
|
19
|
-
before { @a = fixed_array(:foo) }
|
17
|
+
before { @a = Cauterize.fixed_array(:foo) }
|
20
18
|
|
21
19
|
describe :initialize do
|
22
20
|
it "Creates a fixed array." do
|
@@ -27,21 +25,21 @@ describe Cauterize do
|
|
27
25
|
|
28
26
|
describe :array_type do
|
29
27
|
it "Defines the type of the FixedArray." do
|
30
|
-
scalar(:uint32_t)
|
28
|
+
Cauterize.scalar(:uint32_t)
|
31
29
|
@a.array_type :uint32_t
|
32
30
|
@a.instance_variable_get(:@array_type).name.should == :uint32_t
|
33
31
|
end
|
34
32
|
|
35
33
|
it "raises an error if type doesn't exist" do
|
36
34
|
lambda {
|
37
|
-
fixed_array(:fa) do |f|
|
35
|
+
Cauterize.fixed_array(:fa) do |f|
|
38
36
|
f.array_type :lol
|
39
37
|
end
|
40
38
|
}.should raise_error /lol does not correspond/
|
41
39
|
end
|
42
40
|
|
43
41
|
it "is the defined type if no argument is passed" do
|
44
|
-
s = scalar(:uint32_t)
|
42
|
+
s = Cauterize.scalar(:uint32_t)
|
45
43
|
@a.array_type :uint32_t
|
46
44
|
@a.array_type.should be s
|
47
45
|
end
|
data/spec/group_spec.rb
CHANGED
@@ -1,103 +1,108 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it { adds_object_to_hash(:group, :groups) }
|
9
|
-
end
|
10
|
-
|
11
|
-
describe :group! do
|
12
|
-
it { creates_a_named_object(:group!, Group) }
|
13
|
-
it { raises_exception_with_identical_name(:group!) }
|
14
|
-
it { yields_the_object(:group!) }
|
15
|
-
it { adds_object_to_hash(:group!, :groups) }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe :groups do
|
19
|
-
it "is all the defined groups" do
|
20
|
-
group(:a)
|
21
|
-
group(:b)
|
22
|
-
groups.values.map(&:name).should == [:a, :b]
|
1
|
+
module Cauterize
|
2
|
+
describe Cauterize do
|
3
|
+
describe :group do
|
4
|
+
it { creates_a_named_object(:group, Group) }
|
5
|
+
it { retrieves_obj_with_identical_name(:group) }
|
6
|
+
it { yields_the_object(:group) }
|
7
|
+
it { adds_object_to_hash(:group, Cauterize.groups) }
|
23
8
|
end
|
24
|
-
end
|
25
9
|
|
26
|
-
|
27
|
-
|
28
|
-
it
|
29
|
-
|
30
|
-
|
31
|
-
f.name.should == :name
|
32
|
-
f.type.should be t
|
33
|
-
end
|
10
|
+
describe :group! do
|
11
|
+
it { creates_a_named_object(:group!, Group) }
|
12
|
+
it { raises_exception_with_identical_name(:group!) }
|
13
|
+
it { yields_the_object(:group!) }
|
14
|
+
it { adds_object_to_hash(:group!, Cauterize.groups) }
|
34
15
|
end
|
35
|
-
end
|
36
16
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Group.new(:foo).name == :foo
|
41
|
-
end
|
17
|
+
describe :groups do
|
18
|
+
it { is_hash_of_created_objs(:group, Cauterize.groups) }
|
19
|
+
end
|
42
20
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
21
|
+
describe GroupField do
|
22
|
+
describe :initialize do
|
23
|
+
it "creats a GroupField" do
|
24
|
+
t = Cauterize.scalar(:type)
|
25
|
+
f = GroupField.new(:name, :type)
|
26
|
+
f.name.should == :name
|
27
|
+
f.type.should be t
|
28
|
+
end
|
47
29
|
end
|
48
30
|
end
|
49
31
|
|
50
|
-
describe
|
51
|
-
|
52
|
-
a
|
53
|
-
|
54
|
-
grp = group(:foo) do |g|
|
55
|
-
g.field(:a, :aaa)
|
56
|
-
g.field(:b, :bbb)
|
32
|
+
describe Group do
|
33
|
+
describe :initialize do
|
34
|
+
it "makes a new Group" do
|
35
|
+
Group.new(:foo).name == :foo
|
57
36
|
end
|
58
37
|
|
59
|
-
|
38
|
+
it "creates the tag enum" do
|
39
|
+
e = Group.new(:foo).tag_enum
|
40
|
+
e.name.should == :group_foo_type
|
41
|
+
e.values == {}
|
42
|
+
end
|
60
43
|
end
|
61
44
|
|
62
|
-
|
63
|
-
a
|
64
|
-
|
65
|
-
|
66
|
-
|
45
|
+
describe :field do
|
46
|
+
it "adds a field to the Group" do
|
47
|
+
a = Cauterize.scalar(:aaa)
|
48
|
+
b = Cauterize.scalar(:bbb)
|
49
|
+
grp = Cauterize.group(:foo) do |g|
|
67
50
|
g.field(:a, :aaa)
|
51
|
+
g.field(:b, :bbb)
|
68
52
|
end
|
69
|
-
}.should raise_error /Field name a already used/
|
70
|
-
end
|
71
53
|
|
72
|
-
|
73
|
-
|
74
|
-
|
54
|
+
grp.fields.values.map(&:name).should == [:a, :b]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "errors on duplicate field names" do
|
58
|
+
a = Cauterize.scalar(:aaa)
|
59
|
+
lambda {
|
60
|
+
grp = Cauterize.group(:foo) do |g|
|
61
|
+
g.field(:a, :aaa)
|
62
|
+
g.field(:a, :aaa)
|
63
|
+
end
|
64
|
+
}.should raise_error /Field name a already used/
|
65
|
+
end
|
66
|
+
|
67
|
+
it "errors on non-existant types" do
|
68
|
+
lambda {
|
69
|
+
grp = Cauterize.group(:foo) do |g|
|
70
|
+
g.field(:a, :aaa)
|
71
|
+
end
|
72
|
+
}.should raise_error /name aaa does not correspond to a type/
|
73
|
+
end
|
74
|
+
|
75
|
+
it "adds a new value to the enum for each field" do
|
76
|
+
a = Cauterize.scalar(:aaa)
|
77
|
+
b = Cauterize.scalar(:bbb)
|
78
|
+
grp = Cauterize.group(:foo) do |g|
|
75
79
|
g.field(:a, :aaa)
|
80
|
+
g.field(:b, :bbb)
|
76
81
|
end
|
77
|
-
}.should raise_error /name aaa does not correspond to a type/
|
78
|
-
end
|
79
82
|
|
80
|
-
|
81
|
-
a = scalar(:aaa)
|
82
|
-
b = scalar(:bbb)
|
83
|
-
grp = group(:foo) do |g|
|
84
|
-
g.field(:a, :aaa)
|
85
|
-
g.field(:b, :bbb)
|
83
|
+
grp.tag_enum.values.keys.should =~ [:GROUP_FOO_TYPE_A, :GROUP_FOO_TYPE_B]
|
86
84
|
end
|
87
85
|
|
88
|
-
|
86
|
+
it "allows nil types" do
|
87
|
+
grp = Cauterize.group(:empty) do |g|
|
88
|
+
g.field(:a)
|
89
|
+
g.field(:b)
|
90
|
+
end
|
91
|
+
|
92
|
+
grp.tag_enum.values.keys.should =~ [:GROUP_EMPTY_TYPE_A, :GROUP_EMPTY_TYPE_B]
|
93
|
+
end
|
89
94
|
end
|
90
|
-
end
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
describe ".tag_enum" do
|
97
|
+
it "is the enumeration used for the type tag" do
|
98
|
+
Group.new(:foo).tag_enum.class.should be Cauterize::Enumeration
|
99
|
+
end
|
95
100
|
end
|
96
|
-
end
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
|
102
|
+
describe "enum_sym" do
|
103
|
+
it "returns the enumeration symbol for a field name" do
|
104
|
+
Cauterize.group(:foo).enum_sym(:a_field).should == :GROUP_FOO_TYPE_A_FIELD
|
105
|
+
end
|
101
106
|
end
|
102
107
|
end
|
103
108
|
end
|
data/spec/scalar_spec.rb
CHANGED
@@ -1,36 +1,46 @@
|
|
1
|
-
|
2
|
-
before do
|
3
|
-
reset_for_test
|
4
|
-
flush_scalars
|
5
|
-
end
|
6
|
-
|
1
|
+
module Cauterize
|
7
2
|
describe Scalar do
|
8
3
|
describe :initialize do
|
9
4
|
it "creates an scalar" do
|
10
|
-
scalar(:foo).name.should == :foo
|
5
|
+
Cauterize.scalar(:foo).name.should == :foo
|
11
6
|
end
|
12
7
|
end
|
13
8
|
|
14
9
|
describe :id do
|
15
10
|
it { has_a_unique_id_for_each_instance(Scalar) }
|
16
11
|
end
|
12
|
+
|
13
|
+
describe :type_name do
|
14
|
+
it "specifies the builtin type to alias" do
|
15
|
+
s = Cauterize.scalar(:foo) do |t|
|
16
|
+
t.type_name(:int8)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises an exception when a non-builtin is specified" do
|
21
|
+
dummy = Cauterize.scalar(:dummy)
|
22
|
+
s = Cauterize.scalar(:foo) do |t|
|
23
|
+
t.type_name(:int32)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
29
|
describe :scalar do
|
20
30
|
it { creates_a_named_object(:scalar, Scalar) }
|
21
31
|
it { retrieves_obj_with_identical_name(:scalar) }
|
22
32
|
it { yields_the_object(:scalar) }
|
23
|
-
it { adds_object_to_hash(:scalar,
|
33
|
+
it { adds_object_to_hash(:scalar, Cauterize.scalars) }
|
24
34
|
end
|
25
35
|
|
26
36
|
describe :scalar! do
|
27
37
|
it { creates_a_named_object(:scalar!, Scalar) }
|
28
38
|
it { raises_exception_with_identical_name(:scalar!) }
|
29
39
|
it { yields_the_object(:scalar!) }
|
30
|
-
it { adds_object_to_hash(:scalar!,
|
40
|
+
it { adds_object_to_hash(:scalar!, Cauterize.scalars) }
|
31
41
|
end
|
32
42
|
|
33
43
|
describe :scalars do
|
34
|
-
it { is_hash_of_created_objs(:scalar,
|
44
|
+
it { is_hash_of_created_objs(:scalar, Cauterize.scalars) }
|
35
45
|
end
|
36
46
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,100 +16,109 @@ end
|
|
16
16
|
|
17
17
|
###
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
module Cauterize
|
20
|
+
module CauterizeHelpers
|
21
|
+
def reset_for_test
|
22
|
+
BaseType.class_variable_set(:@@next_id, {})
|
23
|
+
BaseType.class_variable_set(:@@instances, {})
|
24
|
+
|
25
|
+
Cauterize.module_exec do
|
26
|
+
@builtins = {}
|
27
|
+
@scalars = {}
|
28
|
+
@composites = {}
|
29
|
+
@enumerations = {}
|
30
|
+
@fixed_ararys = {}
|
31
|
+
@variable_arrays = {}
|
32
|
+
@groups = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
Cauterize.create_builtins
|
36
|
+
end
|
37
|
+
|
38
|
+
def is_tagged_as(cls, tag)
|
39
|
+
cls.new(:foo).tag.should == tag
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_a_unique_id_for_each_instance(cls)
|
43
|
+
cls.new(:foo).id.should == 0
|
44
|
+
cls.new(:bar).id.should == 1
|
45
|
+
cls.new(:baz).id.should == 2
|
46
|
+
end
|
47
|
+
|
48
|
+
def creates_a_named_object(fn_sym, obj)
|
49
|
+
fn = Cauterize.method(fn_sym)
|
50
|
+
a = fn.call(:foo)
|
51
|
+
a.class.should == obj
|
52
|
+
a.name.should == :foo
|
53
|
+
end
|
54
|
+
|
55
|
+
def retrieves_obj_with_identical_name(fn_sym)
|
56
|
+
fn = Cauterize.method(fn_sym)
|
57
|
+
a = fn.call(:foo)
|
58
|
+
b = fn.call(:foo)
|
59
|
+
a.should be b
|
60
|
+
end
|
61
|
+
|
62
|
+
def raises_exception_with_identical_name(fn_sym)
|
63
|
+
fn = Cauterize.method(fn_sym)
|
64
|
+
fn.call(:foo)
|
65
|
+
lambda { fn.call(:foo) }.should raise_error
|
66
|
+
end
|
67
|
+
|
68
|
+
def yields_the_object(fn_sym)
|
69
|
+
fn = Cauterize.method(fn_sym)
|
70
|
+
called = false
|
71
|
+
yielded = nil
|
72
|
+
r = fn.call(:foo) { |a| yielded = a }
|
73
|
+
yielded.should be r
|
74
|
+
end
|
75
|
+
|
76
|
+
def adds_object_to_hash(fn_sym, hash_inst)
|
77
|
+
fn = Cauterize.method(fn_sym)
|
78
|
+
|
79
|
+
f = fn.call(:foo)
|
80
|
+
b = fn.call(:bar)
|
81
|
+
|
82
|
+
hash_inst.keys.should == [:foo, :bar]
|
83
|
+
hash_inst.values[0].should be f
|
84
|
+
hash_inst.values[1].should be b
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_hash_of_created_objs(create_fn_sym, hash_inst)
|
88
|
+
create_fn = Cauterize.method(create_fn_sym)
|
89
|
+
|
90
|
+
f = create_fn.call(:foo)
|
91
|
+
b = create_fn.call(:bar)
|
92
|
+
z = create_fn.call(:zap)
|
93
|
+
|
94
|
+
vs = hash_inst.values
|
95
|
+
vs[0].should be f
|
96
|
+
vs[1].should be b
|
97
|
+
vs[2].should be z
|
98
|
+
hash_inst.keys.should == [:foo, :bar, :zap]
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
###############################################################################
|
103
|
+
|
104
|
+
def gen_test_main(sym_list)
|
105
|
+
sym_voids = sym_list.map {|s| "(void*)#{s}"}.join(", ")
|
106
|
+
str = <<-EOF
|
107
|
+
#include "testing.h"
|
108
|
+
|
109
|
+
int main(int argc, char * argv[])
|
110
|
+
{
|
111
|
+
(void)argc;
|
112
|
+
(void)argv;
|
113
|
+
|
114
|
+
void * ptr[] = {#{sym_voids}};
|
115
|
+
(void)ptr;
|
116
|
+
|
117
|
+
return 0;
|
118
|
+
}
|
119
|
+
EOF
|
120
|
+
end
|
27
121
|
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def is_tagged_as(cls, tag)
|
32
|
-
cls.new(:foo).tag.should == tag
|
33
|
-
end
|
34
|
-
|
35
|
-
def has_a_unique_id_for_each_instance(cls)
|
36
|
-
cls.new(:foo).id.should == 0
|
37
|
-
cls.new(:bar).id.should == 1
|
38
|
-
cls.new(:baz).id.should == 2
|
39
|
-
end
|
40
|
-
|
41
|
-
def creates_a_named_object(fn_sym, obj)
|
42
|
-
fn = method(fn_sym)
|
43
|
-
a = fn.call(:foo)
|
44
|
-
a.class.should == obj
|
45
|
-
a.name.should == :foo
|
46
122
|
end
|
47
123
|
|
48
|
-
|
49
|
-
fn = method(fn_sym)
|
50
|
-
a = fn.call(:foo)
|
51
|
-
b = fn.call(:foo)
|
52
|
-
a.should be b
|
53
|
-
end
|
54
|
-
|
55
|
-
def raises_exception_with_identical_name(fn_sym)
|
56
|
-
fn = method(fn_sym)
|
57
|
-
fn.call(:foo)
|
58
|
-
lambda { fn.call(:foo) }.should raise_error
|
59
|
-
end
|
60
|
-
|
61
|
-
def yields_the_object(fn_sym)
|
62
|
-
fn = method(fn_sym)
|
63
|
-
called = false
|
64
|
-
yielded = nil
|
65
|
-
r = fn.call(:foo) { |a| yielded = a }
|
66
|
-
yielded.should be r
|
67
|
-
end
|
68
|
-
|
69
|
-
def adds_object_to_hash(fn_sym, hash_fn_sym)
|
70
|
-
fn = method(fn_sym)
|
71
|
-
hash_fn = method(hash_fn_sym)
|
72
|
-
|
73
|
-
f = fn.call(:foo)
|
74
|
-
b = fn.call(:bar)
|
75
|
-
|
76
|
-
hash_fn.call.keys.should == [:foo, :bar]
|
77
|
-
hash_fn.call.values[0].should be f
|
78
|
-
hash_fn.call.values[1].should be b
|
79
|
-
end
|
80
|
-
|
81
|
-
def is_hash_of_created_objs(create_fn_sym, hash_fn_sym)
|
82
|
-
create_fn = method(create_fn_sym)
|
83
|
-
hash_fn = method(hash_fn_sym)
|
84
|
-
|
85
|
-
f = create_fn.call(:foo)
|
86
|
-
b = create_fn.call(:bar)
|
87
|
-
z = create_fn.call(:zap)
|
88
|
-
|
89
|
-
vs = hash_fn.call.values
|
90
|
-
vs[0].should be f
|
91
|
-
vs[1].should be b
|
92
|
-
vs[2].should be z
|
93
|
-
hash_fn.call.keys.should == [:foo, :bar, :zap]
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
###############################################################################
|
98
|
-
|
99
|
-
def gen_test_main(sym_list)
|
100
|
-
sym_voids = sym_list.map {|s| "(void*)#{s}"}.join(", ")
|
101
|
-
str = <<-EOF
|
102
|
-
#include "testing.h"
|
103
|
-
|
104
|
-
int main(int argc, char * argv[])
|
105
|
-
{
|
106
|
-
(void)argc;
|
107
|
-
(void)argv;
|
108
|
-
|
109
|
-
void * ptr[] = {#{sym_voids}};
|
110
|
-
(void)ptr;
|
111
|
-
|
112
|
-
return 0;
|
113
|
-
}
|
114
|
-
EOF
|
115
|
-
end
|
124
|
+
include Cauterize::CauterizeHelpers
|