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/scalar_spec.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
module Cauterize
|
2
|
-
describe Scalar do
|
3
|
-
describe :initialize do
|
4
|
-
it "creates an scalar" do
|
5
|
-
Cauterize.scalar(:foo).name.should == :foo
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
it { can_be_documented(Cauterize::Scalar) }
|
10
|
-
|
11
|
-
describe :type_name do
|
12
|
-
it "specifies the builtin type to alias" do
|
13
|
-
s = Cauterize.scalar(:foo) do |t|
|
14
|
-
t.type_name(:int8)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "raises an exception when a non-builtin is specified" do
|
19
|
-
dummy = Cauterize.scalar(:dummy)
|
20
|
-
s = Cauterize.scalar(:foo) do |t|
|
21
|
-
t.type_name(:int32)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe :scalar do
|
28
|
-
it { creates_a_named_object(:scalar, Scalar) }
|
29
|
-
it { retrieves_obj_with_identical_name(:scalar) }
|
30
|
-
it { yields_the_object(:scalar) }
|
31
|
-
it { adds_object_to_hash(:scalar, Cauterize.scalars) }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe :scalar! do
|
35
|
-
it { creates_a_named_object(:scalar!, Scalar) }
|
36
|
-
it { raises_exception_with_identical_name(:scalar!) }
|
37
|
-
it { yields_the_object(:scalar!) }
|
38
|
-
it { adds_object_to_hash(:scalar!, Cauterize.scalars) }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe :scalars do
|
42
|
-
it { is_hash_of_created_objs(:scalar, Cauterize.scalars) }
|
43
|
-
end
|
44
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
describe Scalar do
|
3
|
+
describe :initialize do
|
4
|
+
it "creates an scalar" do
|
5
|
+
Cauterize.scalar(:foo).name.should == :foo
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it { can_be_documented(Cauterize::Scalar) }
|
10
|
+
|
11
|
+
describe :type_name do
|
12
|
+
it "specifies the builtin type to alias" do
|
13
|
+
s = Cauterize.scalar(:foo) do |t|
|
14
|
+
t.type_name(:int8)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an exception when a non-builtin is specified" do
|
19
|
+
dummy = Cauterize.scalar(:dummy)
|
20
|
+
s = Cauterize.scalar(:foo) do |t|
|
21
|
+
t.type_name(:int32)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :scalar do
|
28
|
+
it { creates_a_named_object(:scalar, Scalar) }
|
29
|
+
it { retrieves_obj_with_identical_name(:scalar) }
|
30
|
+
it { yields_the_object(:scalar) }
|
31
|
+
it { adds_object_to_hash(:scalar, Cauterize.scalars) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe :scalar! do
|
35
|
+
it { creates_a_named_object(:scalar!, Scalar) }
|
36
|
+
it { raises_exception_with_identical_name(:scalar!) }
|
37
|
+
it { yields_the_object(:scalar!) }
|
38
|
+
it { adds_object_to_hash(:scalar!, Cauterize.scalars) }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe :scalars do
|
42
|
+
it { is_hash_of_created_objs(:scalar, Cauterize.scalars) }
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'mocha/api'
|
3
|
-
require 'require_all'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
6
|
-
require 'cauterize/cauterize'
|
7
|
-
|
8
|
-
require_all Dir['spec/support/**/*.rb']
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.mock_framework = :mocha
|
12
|
-
config.before(:each) do
|
13
|
-
reset_for_test
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
###
|
18
|
-
|
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 can_be_documented(klass)
|
39
|
-
klass.new(:dokumented_klass, "precious documentation").description.should == "precious documentation"
|
40
|
-
end
|
41
|
-
|
42
|
-
def is_tagged_as(cls, tag)
|
43
|
-
cls.new(:foo).tag.should == tag
|
44
|
-
end
|
45
|
-
|
46
|
-
def creates_a_named_object(fn_sym, obj)
|
47
|
-
fn = Cauterize.method(fn_sym)
|
48
|
-
a = fn.call(:foo)
|
49
|
-
a.class.should == obj
|
50
|
-
a.name.should == :foo
|
51
|
-
end
|
52
|
-
|
53
|
-
def retrieves_obj_with_identical_name(fn_sym)
|
54
|
-
fn = Cauterize.method(fn_sym)
|
55
|
-
a = fn.call(:foo)
|
56
|
-
b = fn.call(:foo)
|
57
|
-
a.should be b
|
58
|
-
end
|
59
|
-
|
60
|
-
def raises_exception_with_identical_name(fn_sym)
|
61
|
-
fn = Cauterize.method(fn_sym)
|
62
|
-
fn.call(:foo)
|
63
|
-
lambda { fn.call(:foo) }.should raise_error
|
64
|
-
end
|
65
|
-
|
66
|
-
def yields_the_object(fn_sym)
|
67
|
-
fn = Cauterize.method(fn_sym)
|
68
|
-
called = false
|
69
|
-
yielded = nil
|
70
|
-
r = fn.call(:foo) { |a| yielded = a }
|
71
|
-
yielded.should be r
|
72
|
-
end
|
73
|
-
|
74
|
-
def adds_object_to_hash(fn_sym, hash_inst)
|
75
|
-
fn = Cauterize.method(fn_sym)
|
76
|
-
|
77
|
-
f = fn.call(:foo)
|
78
|
-
b = fn.call(:bar)
|
79
|
-
|
80
|
-
hash_inst.keys.should == [:foo, :bar]
|
81
|
-
hash_inst.values[0].should be f
|
82
|
-
hash_inst.values[1].should be b
|
83
|
-
end
|
84
|
-
|
85
|
-
def is_hash_of_created_objs(create_fn_sym, hash_inst)
|
86
|
-
create_fn = Cauterize.method(create_fn_sym)
|
87
|
-
|
88
|
-
f = create_fn.call(:foo)
|
89
|
-
b = create_fn.call(:bar)
|
90
|
-
z = create_fn.call(:zap)
|
91
|
-
|
92
|
-
vs = hash_inst.values
|
93
|
-
vs[0].should be f
|
94
|
-
vs[1].should be b
|
95
|
-
vs[2].should be z
|
96
|
-
hash_inst.keys.should == [:foo, :bar, :zap]
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
###############################################################################
|
101
|
-
|
102
|
-
def gen_test_main(sym_list)
|
103
|
-
sym_voids = sym_list.map {|s| "(void*)#{s}"}.join(", ")
|
104
|
-
str = <<-EOF
|
105
|
-
#include "testing.h"
|
106
|
-
|
107
|
-
int main(int argc, char * argv[])
|
108
|
-
{
|
109
|
-
(void)argc;
|
110
|
-
(void)argv;
|
111
|
-
|
112
|
-
void * ptr[] = {#{sym_voids}};
|
113
|
-
(void)ptr;
|
114
|
-
|
115
|
-
return 0;
|
116
|
-
}
|
117
|
-
EOF
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
include Cauterize::CauterizeHelpers
|
1
|
+
require 'set'
|
2
|
+
require 'mocha/api'
|
3
|
+
require 'require_all'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
6
|
+
require 'cauterize/cauterize'
|
7
|
+
|
8
|
+
require_all Dir['spec/support/**/*.rb']
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_framework = :mocha
|
12
|
+
config.before(:each) do
|
13
|
+
reset_for_test
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
###
|
18
|
+
|
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 can_be_documented(klass)
|
39
|
+
klass.new(:dokumented_klass, "precious documentation").description.should == "precious documentation"
|
40
|
+
end
|
41
|
+
|
42
|
+
def is_tagged_as(cls, tag)
|
43
|
+
cls.new(:foo).tag.should == tag
|
44
|
+
end
|
45
|
+
|
46
|
+
def creates_a_named_object(fn_sym, obj)
|
47
|
+
fn = Cauterize.method(fn_sym)
|
48
|
+
a = fn.call(:foo)
|
49
|
+
a.class.should == obj
|
50
|
+
a.name.should == :foo
|
51
|
+
end
|
52
|
+
|
53
|
+
def retrieves_obj_with_identical_name(fn_sym)
|
54
|
+
fn = Cauterize.method(fn_sym)
|
55
|
+
a = fn.call(:foo)
|
56
|
+
b = fn.call(:foo)
|
57
|
+
a.should be b
|
58
|
+
end
|
59
|
+
|
60
|
+
def raises_exception_with_identical_name(fn_sym)
|
61
|
+
fn = Cauterize.method(fn_sym)
|
62
|
+
fn.call(:foo)
|
63
|
+
lambda { fn.call(:foo) }.should raise_error
|
64
|
+
end
|
65
|
+
|
66
|
+
def yields_the_object(fn_sym)
|
67
|
+
fn = Cauterize.method(fn_sym)
|
68
|
+
called = false
|
69
|
+
yielded = nil
|
70
|
+
r = fn.call(:foo) { |a| yielded = a }
|
71
|
+
yielded.should be r
|
72
|
+
end
|
73
|
+
|
74
|
+
def adds_object_to_hash(fn_sym, hash_inst)
|
75
|
+
fn = Cauterize.method(fn_sym)
|
76
|
+
|
77
|
+
f = fn.call(:foo)
|
78
|
+
b = fn.call(:bar)
|
79
|
+
|
80
|
+
hash_inst.keys.should == [:foo, :bar]
|
81
|
+
hash_inst.values[0].should be f
|
82
|
+
hash_inst.values[1].should be b
|
83
|
+
end
|
84
|
+
|
85
|
+
def is_hash_of_created_objs(create_fn_sym, hash_inst)
|
86
|
+
create_fn = Cauterize.method(create_fn_sym)
|
87
|
+
|
88
|
+
f = create_fn.call(:foo)
|
89
|
+
b = create_fn.call(:bar)
|
90
|
+
z = create_fn.call(:zap)
|
91
|
+
|
92
|
+
vs = hash_inst.values
|
93
|
+
vs[0].should be f
|
94
|
+
vs[1].should be b
|
95
|
+
vs[2].should be z
|
96
|
+
hash_inst.keys.should == [:foo, :bar, :zap]
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
###############################################################################
|
101
|
+
|
102
|
+
def gen_test_main(sym_list)
|
103
|
+
sym_voids = sym_list.map {|s| "(void*)#{s}"}.join(", ")
|
104
|
+
str = <<-EOF
|
105
|
+
#include "testing.h"
|
106
|
+
|
107
|
+
int main(int argc, char * argv[])
|
108
|
+
{
|
109
|
+
(void)argc;
|
110
|
+
(void)argv;
|
111
|
+
|
112
|
+
void * ptr[] = {#{sym_voids}};
|
113
|
+
(void)ptr;
|
114
|
+
|
115
|
+
return 0;
|
116
|
+
}
|
117
|
+
EOF
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
include Cauterize::CauterizeHelpers
|
@@ -1,22 +1,22 @@
|
|
1
|
-
include Cauterize::Builders::C
|
2
|
-
|
3
|
-
shared_examples "an array buildable" do
|
4
|
-
let(:desc_instance) { type_constructor.call(:some_type_name) }
|
5
|
-
let(:formatter) { default_formatter }
|
6
|
-
subject { described_class.new(desc_instance) }
|
7
|
-
|
8
|
-
describe :render do
|
9
|
-
it "contains the name" do
|
10
|
-
t_name = subject.instance_variable_get(:@blueprint).array_type.name
|
11
|
-
subject.render.should match /#{t_name}/
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe :declare do
|
16
|
-
before { subject.declare(formatter, :some_sym) }
|
17
|
-
|
18
|
-
it "contains the name and a ;" do
|
19
|
-
formatter.to_s.should match /uint32_t some_sym\[16\]; \/\* some_type_name \*\//
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
include Cauterize::Builders::C
|
2
|
+
|
3
|
+
shared_examples "an array buildable" do
|
4
|
+
let(:desc_instance) { type_constructor.call(:some_type_name) }
|
5
|
+
let(:formatter) { default_formatter }
|
6
|
+
subject { described_class.new(desc_instance) }
|
7
|
+
|
8
|
+
describe :render do
|
9
|
+
it "contains the name" do
|
10
|
+
t_name = subject.instance_variable_get(:@blueprint).array_type.name
|
11
|
+
subject.render.should match /#{t_name}/
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe :declare do
|
16
|
+
before { subject.declare(formatter, :some_sym) }
|
17
|
+
|
18
|
+
it "contains the name and a ;" do
|
19
|
+
formatter.to_s.should match /uint32_t some_sym\[16\]; \/\* some_type_name \*\//
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,103 +1,103 @@
|
|
1
|
-
# shared examples for c buildables
|
2
|
-
|
3
|
-
module Cauterize
|
4
|
-
include Cauterize::Builders::C
|
5
|
-
|
6
|
-
shared_examples "a buildable" do
|
7
|
-
let(:desc_instance) { type_constructor.call(:some_type_name) }
|
8
|
-
let(:formatter) { default_formatter }
|
9
|
-
let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
|
10
|
-
subject { described_class.new(desc_instance) }
|
11
|
-
|
12
|
-
it "should be registered" do
|
13
|
-
builder.class.should be described_class
|
14
|
-
end
|
15
|
-
|
16
|
-
it "errors on duplicate type names" do
|
17
|
-
instances = BaseType.class_variable_get(:@@instances)
|
18
|
-
instances[:a_common_name] = nil
|
19
|
-
BaseType.class_variable_set(:@@instances, instances)
|
20
|
-
lambda {
|
21
|
-
type_constructor.call(:a_common_name)
|
22
|
-
}.should raise_error /already exists/
|
23
|
-
end
|
24
|
-
|
25
|
-
describe :packer_sym do
|
26
|
-
it "contains the word Pack" do
|
27
|
-
subject.packer_sym.should match /Pack_/
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe :packer_sig do
|
32
|
-
it "looks like this" do
|
33
|
-
r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* dst, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* src\)/
|
34
|
-
subject.packer_sig.should match r
|
35
|
-
m = subject.packer_sig.match(r)
|
36
|
-
m[:sym].should == subject.packer_sym
|
37
|
-
m[:rend].should == subject.render
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe :packer_proto do
|
42
|
-
it "should format the sig + ;" do
|
43
|
-
subject.packer_proto(formatter)
|
44
|
-
formatter.to_s.should == subject.packer_sig + ";"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe :wrapped_packer_defn do
|
49
|
-
before { subject.wrapped_packer_defn(formatter) }
|
50
|
-
|
51
|
-
it "contains the signature" do
|
52
|
-
formatter.to_s.should match Regexp.escape(subject.packer_sig)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe :packer_defn do
|
57
|
-
before { subject.packer_defn(formatter) }
|
58
|
-
|
59
|
-
it "contains a return statement" do
|
60
|
-
formatter.to_s.should match /return.*;/
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe :unpacker_sym do
|
65
|
-
it "contains the word Unpack" do
|
66
|
-
subject.unpacker_sym.should match /Unpack_/
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe :unpacker_sig do
|
71
|
-
it "looks like this" do
|
72
|
-
r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* src, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* dst\)/
|
73
|
-
subject.unpacker_sig.should match r
|
74
|
-
m = subject.unpacker_sig.match(r)
|
75
|
-
m[:sym].should == subject.unpacker_sym
|
76
|
-
m[:rend].should == subject.render
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe :unpacker_proto do
|
81
|
-
it "should format the sig + ;" do
|
82
|
-
subject.unpacker_proto(formatter)
|
83
|
-
formatter.to_s.should == subject.unpacker_sig + ";"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe :wrapped_unpacker_defn do
|
88
|
-
before { subject.wrapped_unpacker_defn(formatter) }
|
89
|
-
|
90
|
-
it "contains the signature" do
|
91
|
-
formatter.to_s.should match Regexp.escape(subject.unpacker_sig)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe :unpacker_defn do
|
96
|
-
before { subject.unpacker_defn(formatter) }
|
97
|
-
|
98
|
-
it "contains a return statement" do
|
99
|
-
formatter.to_s.should match /return.*;/
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
1
|
+
# shared examples for c buildables
|
2
|
+
|
3
|
+
module Cauterize
|
4
|
+
include Cauterize::Builders::C
|
5
|
+
|
6
|
+
shared_examples "a buildable" do
|
7
|
+
let(:desc_instance) { type_constructor.call(:some_type_name) }
|
8
|
+
let(:formatter) { default_formatter }
|
9
|
+
let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
|
10
|
+
subject { described_class.new(desc_instance) }
|
11
|
+
|
12
|
+
it "should be registered" do
|
13
|
+
builder.class.should be described_class
|
14
|
+
end
|
15
|
+
|
16
|
+
it "errors on duplicate type names" do
|
17
|
+
instances = BaseType.class_variable_get(:@@instances)
|
18
|
+
instances[:a_common_name] = nil
|
19
|
+
BaseType.class_variable_set(:@@instances, instances)
|
20
|
+
lambda {
|
21
|
+
type_constructor.call(:a_common_name)
|
22
|
+
}.should raise_error /already exists/
|
23
|
+
end
|
24
|
+
|
25
|
+
describe :packer_sym do
|
26
|
+
it "contains the word Pack" do
|
27
|
+
subject.packer_sym.should match /Pack_/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe :packer_sig do
|
32
|
+
it "looks like this" do
|
33
|
+
r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* dst, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* src\)/
|
34
|
+
subject.packer_sig.should match r
|
35
|
+
m = subject.packer_sig.match(r)
|
36
|
+
m[:sym].should == subject.packer_sym
|
37
|
+
m[:rend].should == subject.render
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe :packer_proto do
|
42
|
+
it "should format the sig + ;" do
|
43
|
+
subject.packer_proto(formatter)
|
44
|
+
formatter.to_s.should == subject.packer_sig + ";"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe :wrapped_packer_defn do
|
49
|
+
before { subject.wrapped_packer_defn(formatter) }
|
50
|
+
|
51
|
+
it "contains the signature" do
|
52
|
+
formatter.to_s.should match Regexp.escape(subject.packer_sig)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe :packer_defn do
|
57
|
+
before { subject.packer_defn(formatter) }
|
58
|
+
|
59
|
+
it "contains a return statement" do
|
60
|
+
formatter.to_s.should match /return.*;/
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe :unpacker_sym do
|
65
|
+
it "contains the word Unpack" do
|
66
|
+
subject.unpacker_sym.should match /Unpack_/
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe :unpacker_sig do
|
71
|
+
it "looks like this" do
|
72
|
+
r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* src, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* dst\)/
|
73
|
+
subject.unpacker_sig.should match r
|
74
|
+
m = subject.unpacker_sig.match(r)
|
75
|
+
m[:sym].should == subject.unpacker_sym
|
76
|
+
m[:rend].should == subject.render
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe :unpacker_proto do
|
81
|
+
it "should format the sig + ;" do
|
82
|
+
subject.unpacker_proto(formatter)
|
83
|
+
formatter.to_s.should == subject.unpacker_sig + ";"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe :wrapped_unpacker_defn do
|
88
|
+
before { subject.wrapped_unpacker_defn(formatter) }
|
89
|
+
|
90
|
+
it "contains the signature" do
|
91
|
+
formatter.to_s.should match Regexp.escape(subject.unpacker_sig)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe :unpacker_defn do
|
96
|
+
before { subject.unpacker_defn(formatter) }
|
97
|
+
|
98
|
+
it "contains a return statement" do
|
99
|
+
formatter.to_s.should match /return.*;/
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|