cauterize 0.0.1.pre13 → 0.0.1.pre14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -33
- data/.rspec +1 -1
- data/.travisci.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +177 -177
- data/Rakefile +54 -54
- data/bin/cauterize +61 -61
- data/cauterize.gemspec +27 -27
- data/example/Cauterize +68 -68
- data/example/build.sh +25 -25
- data/example/c_example_support/empty_main.c +1 -1
- data/example/c_example_support/example_project_config.c +11 -11
- data/example/c_example_support/example_project_config.h +15 -15
- data/example/ruby_ex.rb +14 -14
- data/lib/cauterize.rb +117 -117
- data/lib/cauterize/base_type.rb +78 -78
- data/lib/cauterize/builders.rb +41 -41
- data/lib/cauterize/builders/c/buildable.rb +91 -91
- data/lib/cauterize/builders/c/builtin.rb +43 -43
- data/lib/cauterize/builders/c/composite.rb +57 -57
- data/lib/cauterize/builders/c/enumeration.rb +60 -60
- data/lib/cauterize/builders/c/fixed_array.rb +74 -74
- data/lib/cauterize/builders/c/group.rb +143 -143
- data/lib/cauterize/builders/c/scalar.rb +34 -34
- data/lib/cauterize/builders/c/variable_array.rb +98 -98
- data/lib/cauterize/builders/cs/buildable.rb +59 -59
- data/lib/cauterize/builders/cs/builtin.rb +22 -22
- data/lib/cauterize/builders/cs/composite.rb +21 -21
- data/lib/cauterize/builders/cs/csarray.rb +32 -32
- data/lib/cauterize/builders/cs/enumeration.rb +21 -21
- data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
- data/lib/cauterize/builders/cs/group.rb +32 -32
- data/lib/cauterize/builders/cs/scalar.rb +10 -10
- data/lib/cauterize/builders/cs/variable_array.rb +40 -34
- data/lib/cauterize/builders/doc/buildable.rb +30 -30
- data/lib/cauterize/builders/doc/builtin.rb +21 -21
- data/lib/cauterize/builders/doc/composite.rb +23 -23
- data/lib/cauterize/builders/doc/enumeration.rb +24 -24
- data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
- data/lib/cauterize/builders/doc/group.rb +29 -29
- data/lib/cauterize/builders/doc/scalar.rb +21 -21
- data/lib/cauterize/builders/doc/variable_array.rb +26 -26
- data/lib/cauterize/builders/ruby/buildable.rb +11 -11
- data/lib/cauterize/builders/ruby/builtin.rb +25 -25
- data/lib/cauterize/builders/ruby/composite.rb +26 -26
- data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
- data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
- data/lib/cauterize/builders/ruby/group.rb +35 -35
- data/lib/cauterize/builders/ruby/scalar.rb +19 -19
- data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
- data/lib/cauterize/builtin.rb +62 -62
- data/lib/cauterize/c_builder.rb +103 -103
- data/lib/cauterize/cauterize.rb +76 -76
- data/lib/cauterize/composite.rb +64 -64
- data/lib/cauterize/cs_builder.rb +58 -58
- data/lib/cauterize/doc_builder.rb +34 -34
- data/lib/cauterize/enumeration.rb +98 -98
- data/lib/cauterize/fixed_array.rb +50 -50
- data/lib/cauterize/formatter.rb +67 -67
- data/lib/cauterize/group.rb +81 -81
- data/lib/cauterize/representation.rb +32 -32
- data/lib/cauterize/ruby_builder.rb +44 -44
- data/lib/cauterize/scalar.rb +53 -53
- data/lib/cauterize/snake_case.rb +21 -21
- data/lib/cauterize/variable_array.rb +55 -55
- data/lib/cauterize/version.rb +3 -3
- data/spec/base_type_spec.rb +251 -251
- data/spec/builders/c/buildable_spec.rb +25 -25
- data/spec/builders/c/builtin_spec.rb +22 -22
- data/spec/builders/c/composite_spec.rb +50 -50
- data/spec/builders/c/enumeration_spec.rb +95 -95
- data/spec/builders/c/fixed_array_spec.rb +36 -36
- data/spec/builders/c/group_spec.rb +140 -140
- data/spec/builders/c/scalar_spec.rb +26 -26
- data/spec/builders/c/variable_array_spec.rb +48 -48
- data/spec/builders/cs/buildable_spec.rb +8 -8
- data/spec/builders/cs/composite_spec.rb +32 -32
- data/spec/builders/cs/enumeration_spec.rb +33 -33
- data/spec/builders/cs/fixed_array_spec.rb +41 -41
- data/spec/builders/cs/group_spec.rb +56 -56
- data/spec/builders/cs/scalar_spec.rb +7 -7
- data/spec/builders/cs/variable_array_spec.rb +49 -45
- data/spec/builders/doc/buildable_spec.rb +25 -25
- data/spec/builders_spec.rb +57 -57
- data/spec/builtin_spec.rb +43 -43
- data/spec/c_builder_spec.rb +176 -176
- data/spec/cauterize_spec.rb +15 -15
- data/spec/composite_spec.rb +77 -77
- data/spec/cs_builder_spec.rb +115 -115
- data/spec/doc_builder_spec.rb +260 -260
- data/spec/enumeration_spec.rb +145 -145
- data/spec/fixed_array_spec.rb +61 -61
- data/spec/group_spec.rb +111 -111
- data/spec/ruby_builder_spec.rb +83 -83
- data/spec/ruby_generated_spec.rb +735 -735
- data/spec/scalar_spec.rb +44 -44
- data/spec/spec_helper.rb +122 -122
- data/spec/support/shared_examples_for_array_buildables.rb +22 -22
- data/spec/support/shared_examples_for_c_buildables.rb +103 -103
- data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
- data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
- data/spec/support/spec_sample_model.rb +74 -74
- data/spec/test_main.c +13 -13
- data/spec/variable_array_spec.rb +73 -73
- data/support/c/src/cauterize.c +75 -75
- data/support/c/src/cauterize.h +60 -60
- data/support/c/src/cauterize_debug.h +29 -29
- data/support/c/src/cauterize_util.h +8 -8
- data/support/c/test/greatest.h +536 -536
- data/support/c/test/test.c +166 -166
- data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
- data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
- data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
- data/support/cs/src/CauterizeException.cs +15 -15
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
- data/support/cs/src/CauterizeFormatter.cs +0 -0
- data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
- data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
- data/support/cs/src/CauterizeTypes.cs +46 -12
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
- data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
- data/support/cs/src/OrderAttribute.cs +0 -0
- data/support/cs/src/PrimitiveSupport.cs +12 -0
- data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
- data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
- data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
- data/support/cs/test/OrderAttributeTest.cs +0 -0
- data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
- data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
- metadata +20 -20
data/spec/enumeration_spec.rb
CHANGED
@@ -1,145 +1,145 @@
|
|
1
|
-
module Cauterize
|
2
|
-
describe Cauterize::EnumerationValue do
|
3
|
-
describe :initialize do
|
4
|
-
it "creates an EnumerationValue" do
|
5
|
-
e = Cauterize::EnumerationValue.new(:foo, 1)
|
6
|
-
e.name.should == :foo
|
7
|
-
e.value.should == 1
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe Cauterize::Enumeration do
|
13
|
-
describe :initialize do
|
14
|
-
it "creates a new enumeration with the right name" do
|
15
|
-
Cauterize::Enumeration.new(:foo).name.should == :foo
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it { can_be_documented(Cauterize::Enumeration) }
|
20
|
-
|
21
|
-
describe :value do
|
22
|
-
it "adds a new value to the enumeration" do
|
23
|
-
enum = Cauterize.enumeration(:foo) do |e|
|
24
|
-
e.value :a
|
25
|
-
e.value :b
|
26
|
-
e.value :c
|
27
|
-
e.value :d
|
28
|
-
end
|
29
|
-
|
30
|
-
values = enum.values
|
31
|
-
values.length.should == 4
|
32
|
-
values.keys.should == [:a, :b, :c, :d]
|
33
|
-
values.values.map(&:value).should == [0, 1, 2, 3]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "accepts a fixed value" do
|
37
|
-
enum = Cauterize.enumeration(:foo) do |e|
|
38
|
-
e.value :a, 10
|
39
|
-
e.value :b, 20
|
40
|
-
e.value :c
|
41
|
-
end
|
42
|
-
|
43
|
-
values = enum.values
|
44
|
-
values.keys.should == [:a, :b, :c]
|
45
|
-
values.values.map(&:value).should == [10, 20, 21]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "allows out-of-order values" do
|
49
|
-
lambda {
|
50
|
-
Cauterize.enumeration(:foo) do |e|
|
51
|
-
e.value :a, 10
|
52
|
-
e.value :b, 9
|
53
|
-
end
|
54
|
-
}.should_not raise_error
|
55
|
-
end
|
56
|
-
|
57
|
-
it "doesn't allow duplicate ids" do
|
58
|
-
lambda {
|
59
|
-
Cauterize.enumeration(:foo) do |e|
|
60
|
-
e.value :a, 1
|
61
|
-
e.value :b, 1
|
62
|
-
end
|
63
|
-
}.should raise_error /duplicate constant/
|
64
|
-
end
|
65
|
-
|
66
|
-
it "doesn't allow accidentally identical ids" do
|
67
|
-
en = Cauterize.enumeration(:foo) do |e|
|
68
|
-
e.value :a, 10
|
69
|
-
e.value :b, 9
|
70
|
-
e.value :c
|
71
|
-
end
|
72
|
-
|
73
|
-
en.values.values.map(&:value).should == [10,9,11]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "errors on duplicate names" do
|
77
|
-
lambda {
|
78
|
-
Cauterize.enumeration(:foo) do |e|
|
79
|
-
e.value :a
|
80
|
-
e.value :a
|
81
|
-
end
|
82
|
-
}.should raise_error /duplicate name/
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe :representation do
|
87
|
-
it "chooses int8 when appropriate" do
|
88
|
-
Cauterize.enumeration(:a) do |t|
|
89
|
-
t.value :a, -128
|
90
|
-
end.representation.name.should == :int8
|
91
|
-
Cauterize.enumeration(:b) do |t|
|
92
|
-
t.value :a, 127
|
93
|
-
end.representation.name.should == :int8
|
94
|
-
end
|
95
|
-
|
96
|
-
it "chooses int16 when appropriate" do
|
97
|
-
Cauterize.enumeration(:a) do |t|
|
98
|
-
t.value :a, -32768
|
99
|
-
end.representation.name.should == :int16
|
100
|
-
Cauterize.enumeration(:b) do |t|
|
101
|
-
t.value :a, 32767
|
102
|
-
end.representation.name.should == :int16
|
103
|
-
Cauterize.enumeration(:c) do |t|
|
104
|
-
t.value :a, 300
|
105
|
-
end.representation.name.should == :int16
|
106
|
-
end
|
107
|
-
|
108
|
-
it "chooses int32 when appropriate" do
|
109
|
-
Cauterize.enumeration(:a) do |t|
|
110
|
-
t.value :a, -2147483648
|
111
|
-
end.representation.name.should == :int32
|
112
|
-
Cauterize.enumeration(:b) do |t|
|
113
|
-
t.value :a, 2147483647
|
114
|
-
end.representation.name.should == :int32
|
115
|
-
end
|
116
|
-
|
117
|
-
it "chooses int64 when appropriate" do
|
118
|
-
Cauterize.enumeration(:a) do |t|
|
119
|
-
t.value :a, -9223372036854775808
|
120
|
-
end.representation.name.should == :int64
|
121
|
-
Cauterize.enumeration(:b) do |t|
|
122
|
-
t.value :a, 9223372036854775807
|
123
|
-
end.representation.name.should == :int64
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe :enumeration do
|
129
|
-
it { creates_a_named_object(:enumeration, Enumeration) }
|
130
|
-
it { retrieves_obj_with_identical_name(:enumeration) }
|
131
|
-
it { yields_the_object(:enumeration) }
|
132
|
-
it { adds_object_to_hash(:enumeration, Cauterize.enumerations) }
|
133
|
-
end
|
134
|
-
|
135
|
-
describe :enumeration! do
|
136
|
-
it { creates_a_named_object(:enumeration!, Enumeration) }
|
137
|
-
it { raises_exception_with_identical_name(:enumeration!) }
|
138
|
-
it { yields_the_object(:enumeration!) }
|
139
|
-
it { adds_object_to_hash(:enumeration!, Cauterize.enumerations) }
|
140
|
-
end
|
141
|
-
|
142
|
-
describe :enumerations do
|
143
|
-
it { is_hash_of_created_objs(:enumeration, Cauterize.enumerations) }
|
144
|
-
end
|
145
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
describe Cauterize::EnumerationValue do
|
3
|
+
describe :initialize do
|
4
|
+
it "creates an EnumerationValue" do
|
5
|
+
e = Cauterize::EnumerationValue.new(:foo, 1)
|
6
|
+
e.name.should == :foo
|
7
|
+
e.value.should == 1
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Cauterize::Enumeration do
|
13
|
+
describe :initialize do
|
14
|
+
it "creates a new enumeration with the right name" do
|
15
|
+
Cauterize::Enumeration.new(:foo).name.should == :foo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it { can_be_documented(Cauterize::Enumeration) }
|
20
|
+
|
21
|
+
describe :value do
|
22
|
+
it "adds a new value to the enumeration" do
|
23
|
+
enum = Cauterize.enumeration(:foo) do |e|
|
24
|
+
e.value :a
|
25
|
+
e.value :b
|
26
|
+
e.value :c
|
27
|
+
e.value :d
|
28
|
+
end
|
29
|
+
|
30
|
+
values = enum.values
|
31
|
+
values.length.should == 4
|
32
|
+
values.keys.should == [:a, :b, :c, :d]
|
33
|
+
values.values.map(&:value).should == [0, 1, 2, 3]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "accepts a fixed value" do
|
37
|
+
enum = Cauterize.enumeration(:foo) do |e|
|
38
|
+
e.value :a, 10
|
39
|
+
e.value :b, 20
|
40
|
+
e.value :c
|
41
|
+
end
|
42
|
+
|
43
|
+
values = enum.values
|
44
|
+
values.keys.should == [:a, :b, :c]
|
45
|
+
values.values.map(&:value).should == [10, 20, 21]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "allows out-of-order values" do
|
49
|
+
lambda {
|
50
|
+
Cauterize.enumeration(:foo) do |e|
|
51
|
+
e.value :a, 10
|
52
|
+
e.value :b, 9
|
53
|
+
end
|
54
|
+
}.should_not raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "doesn't allow duplicate ids" do
|
58
|
+
lambda {
|
59
|
+
Cauterize.enumeration(:foo) do |e|
|
60
|
+
e.value :a, 1
|
61
|
+
e.value :b, 1
|
62
|
+
end
|
63
|
+
}.should raise_error /duplicate constant/
|
64
|
+
end
|
65
|
+
|
66
|
+
it "doesn't allow accidentally identical ids" do
|
67
|
+
en = Cauterize.enumeration(:foo) do |e|
|
68
|
+
e.value :a, 10
|
69
|
+
e.value :b, 9
|
70
|
+
e.value :c
|
71
|
+
end
|
72
|
+
|
73
|
+
en.values.values.map(&:value).should == [10,9,11]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "errors on duplicate names" do
|
77
|
+
lambda {
|
78
|
+
Cauterize.enumeration(:foo) do |e|
|
79
|
+
e.value :a
|
80
|
+
e.value :a
|
81
|
+
end
|
82
|
+
}.should raise_error /duplicate name/
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe :representation do
|
87
|
+
it "chooses int8 when appropriate" do
|
88
|
+
Cauterize.enumeration(:a) do |t|
|
89
|
+
t.value :a, -128
|
90
|
+
end.representation.name.should == :int8
|
91
|
+
Cauterize.enumeration(:b) do |t|
|
92
|
+
t.value :a, 127
|
93
|
+
end.representation.name.should == :int8
|
94
|
+
end
|
95
|
+
|
96
|
+
it "chooses int16 when appropriate" do
|
97
|
+
Cauterize.enumeration(:a) do |t|
|
98
|
+
t.value :a, -32768
|
99
|
+
end.representation.name.should == :int16
|
100
|
+
Cauterize.enumeration(:b) do |t|
|
101
|
+
t.value :a, 32767
|
102
|
+
end.representation.name.should == :int16
|
103
|
+
Cauterize.enumeration(:c) do |t|
|
104
|
+
t.value :a, 300
|
105
|
+
end.representation.name.should == :int16
|
106
|
+
end
|
107
|
+
|
108
|
+
it "chooses int32 when appropriate" do
|
109
|
+
Cauterize.enumeration(:a) do |t|
|
110
|
+
t.value :a, -2147483648
|
111
|
+
end.representation.name.should == :int32
|
112
|
+
Cauterize.enumeration(:b) do |t|
|
113
|
+
t.value :a, 2147483647
|
114
|
+
end.representation.name.should == :int32
|
115
|
+
end
|
116
|
+
|
117
|
+
it "chooses int64 when appropriate" do
|
118
|
+
Cauterize.enumeration(:a) do |t|
|
119
|
+
t.value :a, -9223372036854775808
|
120
|
+
end.representation.name.should == :int64
|
121
|
+
Cauterize.enumeration(:b) do |t|
|
122
|
+
t.value :a, 9223372036854775807
|
123
|
+
end.representation.name.should == :int64
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe :enumeration do
|
129
|
+
it { creates_a_named_object(:enumeration, Enumeration) }
|
130
|
+
it { retrieves_obj_with_identical_name(:enumeration) }
|
131
|
+
it { yields_the_object(:enumeration) }
|
132
|
+
it { adds_object_to_hash(:enumeration, Cauterize.enumerations) }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe :enumeration! do
|
136
|
+
it { creates_a_named_object(:enumeration!, Enumeration) }
|
137
|
+
it { raises_exception_with_identical_name(:enumeration!) }
|
138
|
+
it { yields_the_object(:enumeration!) }
|
139
|
+
it { adds_object_to_hash(:enumeration!, Cauterize.enumerations) }
|
140
|
+
end
|
141
|
+
|
142
|
+
describe :enumerations do
|
143
|
+
it { is_hash_of_created_objs(:enumeration, Cauterize.enumerations) }
|
144
|
+
end
|
145
|
+
end
|
data/spec/fixed_array_spec.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
module Cauterize
|
2
|
-
describe :fixed_array do
|
3
|
-
it { creates_a_named_object(:fixed_array, FixedArray) }
|
4
|
-
it { retrieves_obj_with_identical_name(:fixed_array) }
|
5
|
-
it { yields_the_object(:fixed_array) }
|
6
|
-
it { adds_object_to_hash(:fixed_array, Cauterize.fixed_arrays) }
|
7
|
-
end
|
8
|
-
|
9
|
-
describe :fixed_array! do
|
10
|
-
it { creates_a_named_object(:fixed_array!, FixedArray) }
|
11
|
-
it { raises_exception_with_identical_name(:variable_array!) }
|
12
|
-
it { yields_the_object(:fixed_array!) }
|
13
|
-
it { adds_object_to_hash(:fixed_array!, Cauterize.fixed_arrays) }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe FixedArray do
|
17
|
-
before { @a = Cauterize.fixed_array(:foo) }
|
18
|
-
|
19
|
-
describe :initialize do
|
20
|
-
it "Creates a fixed array." do
|
21
|
-
@a.name.should == :foo
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it { can_be_documented(Cauterize::FixedArray) }
|
26
|
-
|
27
|
-
describe :array_type do
|
28
|
-
it "Defines the type of the FixedArray." do
|
29
|
-
Cauterize.scalar(:uint32_t)
|
30
|
-
@a.array_type :uint32_t
|
31
|
-
@a.instance_variable_get(:@array_type).name.should == :uint32_t
|
32
|
-
end
|
33
|
-
|
34
|
-
it "raises an error if type doesn't exist" do
|
35
|
-
lambda {
|
36
|
-
Cauterize.fixed_array(:fa) do |f|
|
37
|
-
f.array_type :lol
|
38
|
-
end
|
39
|
-
}.should raise_error /lol does not correspond/
|
40
|
-
end
|
41
|
-
|
42
|
-
it "is the defined type if no argument is passed" do
|
43
|
-
s = Cauterize.scalar(:uint32_t)
|
44
|
-
@a.array_type :uint32_t
|
45
|
-
@a.array_type.should be s
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe :array_size do
|
50
|
-
it "Defines the size of the FixedArray." do
|
51
|
-
@a.array_size 46
|
52
|
-
@a.instance_variable_get(:@array_size).should == 46
|
53
|
-
end
|
54
|
-
|
55
|
-
it "is the defined size if no argument is passed" do
|
56
|
-
@a.array_size 46
|
57
|
-
@a.array_size.should == 46
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
describe :fixed_array do
|
3
|
+
it { creates_a_named_object(:fixed_array, FixedArray) }
|
4
|
+
it { retrieves_obj_with_identical_name(:fixed_array) }
|
5
|
+
it { yields_the_object(:fixed_array) }
|
6
|
+
it { adds_object_to_hash(:fixed_array, Cauterize.fixed_arrays) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe :fixed_array! do
|
10
|
+
it { creates_a_named_object(:fixed_array!, FixedArray) }
|
11
|
+
it { raises_exception_with_identical_name(:variable_array!) }
|
12
|
+
it { yields_the_object(:fixed_array!) }
|
13
|
+
it { adds_object_to_hash(:fixed_array!, Cauterize.fixed_arrays) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe FixedArray do
|
17
|
+
before { @a = Cauterize.fixed_array(:foo) }
|
18
|
+
|
19
|
+
describe :initialize do
|
20
|
+
it "Creates a fixed array." do
|
21
|
+
@a.name.should == :foo
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it { can_be_documented(Cauterize::FixedArray) }
|
26
|
+
|
27
|
+
describe :array_type do
|
28
|
+
it "Defines the type of the FixedArray." do
|
29
|
+
Cauterize.scalar(:uint32_t)
|
30
|
+
@a.array_type :uint32_t
|
31
|
+
@a.instance_variable_get(:@array_type).name.should == :uint32_t
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises an error if type doesn't exist" do
|
35
|
+
lambda {
|
36
|
+
Cauterize.fixed_array(:fa) do |f|
|
37
|
+
f.array_type :lol
|
38
|
+
end
|
39
|
+
}.should raise_error /lol does not correspond/
|
40
|
+
end
|
41
|
+
|
42
|
+
it "is the defined type if no argument is passed" do
|
43
|
+
s = Cauterize.scalar(:uint32_t)
|
44
|
+
@a.array_type :uint32_t
|
45
|
+
@a.array_type.should be s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe :array_size do
|
50
|
+
it "Defines the size of the FixedArray." do
|
51
|
+
@a.array_size 46
|
52
|
+
@a.instance_variable_get(:@array_size).should == 46
|
53
|
+
end
|
54
|
+
|
55
|
+
it "is the defined size if no argument is passed" do
|
56
|
+
@a.array_size 46
|
57
|
+
@a.array_size.should == 46
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/group_spec.rb
CHANGED
@@ -1,111 +1,111 @@
|
|
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) }
|
8
|
-
end
|
9
|
-
|
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) }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe :groups do
|
18
|
-
it { is_hash_of_created_objs(:group, Cauterize.groups) }
|
19
|
-
end
|
20
|
-
|
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
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe Group do
|
33
|
-
describe :initialize do
|
34
|
-
it "makes a new Group" do
|
35
|
-
Group.new(:foo).name == :foo
|
36
|
-
end
|
37
|
-
|
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
|
43
|
-
end
|
44
|
-
|
45
|
-
it { can_be_documented(Cauterize::Group) }
|
46
|
-
|
47
|
-
describe :field do
|
48
|
-
it "adds a field to the Group" do
|
49
|
-
a = Cauterize.scalar(:aaa)
|
50
|
-
b = Cauterize.scalar(:bbb)
|
51
|
-
grp = Cauterize.group(:foo) do |g|
|
52
|
-
g.field(:a, :aaa)
|
53
|
-
g.field(:b, :bbb)
|
54
|
-
end
|
55
|
-
|
56
|
-
grp.fields.values.map(&:name).should == [:a, :b]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "errors on duplicate field names" do
|
60
|
-
a = Cauterize.scalar(:aaa)
|
61
|
-
lambda {
|
62
|
-
grp = Cauterize.group(:foo) do |g|
|
63
|
-
g.field(:a, :aaa)
|
64
|
-
g.field(:a, :aaa)
|
65
|
-
end
|
66
|
-
}.should raise_error /Field name a already used/
|
67
|
-
end
|
68
|
-
|
69
|
-
it "errors on non-existant types" do
|
70
|
-
lambda {
|
71
|
-
grp = Cauterize.group(:foo) do |g|
|
72
|
-
g.field(:a, :aaa)
|
73
|
-
end
|
74
|
-
}.should raise_error /name aaa does not correspond to a type/
|
75
|
-
end
|
76
|
-
|
77
|
-
it "adds a new value to the enum for each field" do
|
78
|
-
a = Cauterize.scalar(:aaa)
|
79
|
-
b = Cauterize.scalar(:bbb)
|
80
|
-
grp = Cauterize.group(:foo) do |g|
|
81
|
-
g.field(:a, :aaa)
|
82
|
-
g.field(:b, :bbb)
|
83
|
-
end
|
84
|
-
|
85
|
-
grp.tag_enum.values.keys.should =~ [:GROUP_FOO_TYPE_A, :GROUP_FOO_TYPE_B]
|
86
|
-
end
|
87
|
-
|
88
|
-
it "allows nil types" do
|
89
|
-
grp = Cauterize.group(:empty) do |g|
|
90
|
-
g.dataless(:a)
|
91
|
-
g.dataless(:b)
|
92
|
-
end
|
93
|
-
|
94
|
-
grp.tag_enum.values.keys.should =~ [:GROUP_EMPTY_TYPE_A, :GROUP_EMPTY_TYPE_B]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe ".tag_enum" do
|
99
|
-
it "is the enumeration used for the type tag" do
|
100
|
-
Group.new(:foo).tag_enum.class.should be Cauterize::Enumeration
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "enum_sym" do
|
105
|
-
it "returns the enumeration symbol for a field name" do
|
106
|
-
Cauterize.group(:foo).enum_sym(:a_field).should == :GROUP_FOO_TYPE_A_FIELD
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
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) }
|
8
|
+
end
|
9
|
+
|
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) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :groups do
|
18
|
+
it { is_hash_of_created_objs(:group, Cauterize.groups) }
|
19
|
+
end
|
20
|
+
|
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
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Group do
|
33
|
+
describe :initialize do
|
34
|
+
it "makes a new Group" do
|
35
|
+
Group.new(:foo).name == :foo
|
36
|
+
end
|
37
|
+
|
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
|
43
|
+
end
|
44
|
+
|
45
|
+
it { can_be_documented(Cauterize::Group) }
|
46
|
+
|
47
|
+
describe :field do
|
48
|
+
it "adds a field to the Group" do
|
49
|
+
a = Cauterize.scalar(:aaa)
|
50
|
+
b = Cauterize.scalar(:bbb)
|
51
|
+
grp = Cauterize.group(:foo) do |g|
|
52
|
+
g.field(:a, :aaa)
|
53
|
+
g.field(:b, :bbb)
|
54
|
+
end
|
55
|
+
|
56
|
+
grp.fields.values.map(&:name).should == [:a, :b]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "errors on duplicate field names" do
|
60
|
+
a = Cauterize.scalar(:aaa)
|
61
|
+
lambda {
|
62
|
+
grp = Cauterize.group(:foo) do |g|
|
63
|
+
g.field(:a, :aaa)
|
64
|
+
g.field(:a, :aaa)
|
65
|
+
end
|
66
|
+
}.should raise_error /Field name a already used/
|
67
|
+
end
|
68
|
+
|
69
|
+
it "errors on non-existant types" do
|
70
|
+
lambda {
|
71
|
+
grp = Cauterize.group(:foo) do |g|
|
72
|
+
g.field(:a, :aaa)
|
73
|
+
end
|
74
|
+
}.should raise_error /name aaa does not correspond to a type/
|
75
|
+
end
|
76
|
+
|
77
|
+
it "adds a new value to the enum for each field" do
|
78
|
+
a = Cauterize.scalar(:aaa)
|
79
|
+
b = Cauterize.scalar(:bbb)
|
80
|
+
grp = Cauterize.group(:foo) do |g|
|
81
|
+
g.field(:a, :aaa)
|
82
|
+
g.field(:b, :bbb)
|
83
|
+
end
|
84
|
+
|
85
|
+
grp.tag_enum.values.keys.should =~ [:GROUP_FOO_TYPE_A, :GROUP_FOO_TYPE_B]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "allows nil types" do
|
89
|
+
grp = Cauterize.group(:empty) do |g|
|
90
|
+
g.dataless(:a)
|
91
|
+
g.dataless(:b)
|
92
|
+
end
|
93
|
+
|
94
|
+
grp.tag_enum.values.keys.should =~ [:GROUP_EMPTY_TYPE_A, :GROUP_EMPTY_TYPE_B]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe ".tag_enum" do
|
99
|
+
it "is the enumeration used for the type tag" do
|
100
|
+
Group.new(:foo).tag_enum.class.should be Cauterize::Enumeration
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "enum_sym" do
|
105
|
+
it "returns the enumeration symbol for a field name" do
|
106
|
+
Cauterize.group(:foo).enum_sym(:a_field).should == :GROUP_FOO_TYPE_A_FIELD
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|