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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +33 -33
  3. data/.rspec +1 -1
  4. data/.travisci.yml +4 -4
  5. data/Gemfile +4 -4
  6. data/LICENSE.txt +21 -21
  7. data/README.md +177 -177
  8. data/Rakefile +54 -54
  9. data/bin/cauterize +61 -61
  10. data/cauterize.gemspec +27 -27
  11. data/example/Cauterize +68 -68
  12. data/example/build.sh +25 -25
  13. data/example/c_example_support/empty_main.c +1 -1
  14. data/example/c_example_support/example_project_config.c +11 -11
  15. data/example/c_example_support/example_project_config.h +15 -15
  16. data/example/ruby_ex.rb +14 -14
  17. data/lib/cauterize.rb +117 -117
  18. data/lib/cauterize/base_type.rb +78 -78
  19. data/lib/cauterize/builders.rb +41 -41
  20. data/lib/cauterize/builders/c/buildable.rb +91 -91
  21. data/lib/cauterize/builders/c/builtin.rb +43 -43
  22. data/lib/cauterize/builders/c/composite.rb +57 -57
  23. data/lib/cauterize/builders/c/enumeration.rb +60 -60
  24. data/lib/cauterize/builders/c/fixed_array.rb +74 -74
  25. data/lib/cauterize/builders/c/group.rb +143 -143
  26. data/lib/cauterize/builders/c/scalar.rb +34 -34
  27. data/lib/cauterize/builders/c/variable_array.rb +98 -98
  28. data/lib/cauterize/builders/cs/buildable.rb +59 -59
  29. data/lib/cauterize/builders/cs/builtin.rb +22 -22
  30. data/lib/cauterize/builders/cs/composite.rb +21 -21
  31. data/lib/cauterize/builders/cs/csarray.rb +32 -32
  32. data/lib/cauterize/builders/cs/enumeration.rb +21 -21
  33. data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
  34. data/lib/cauterize/builders/cs/group.rb +32 -32
  35. data/lib/cauterize/builders/cs/scalar.rb +10 -10
  36. data/lib/cauterize/builders/cs/variable_array.rb +40 -34
  37. data/lib/cauterize/builders/doc/buildable.rb +30 -30
  38. data/lib/cauterize/builders/doc/builtin.rb +21 -21
  39. data/lib/cauterize/builders/doc/composite.rb +23 -23
  40. data/lib/cauterize/builders/doc/enumeration.rb +24 -24
  41. data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
  42. data/lib/cauterize/builders/doc/group.rb +29 -29
  43. data/lib/cauterize/builders/doc/scalar.rb +21 -21
  44. data/lib/cauterize/builders/doc/variable_array.rb +26 -26
  45. data/lib/cauterize/builders/ruby/buildable.rb +11 -11
  46. data/lib/cauterize/builders/ruby/builtin.rb +25 -25
  47. data/lib/cauterize/builders/ruby/composite.rb +26 -26
  48. data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
  49. data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
  50. data/lib/cauterize/builders/ruby/group.rb +35 -35
  51. data/lib/cauterize/builders/ruby/scalar.rb +19 -19
  52. data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
  53. data/lib/cauterize/builtin.rb +62 -62
  54. data/lib/cauterize/c_builder.rb +103 -103
  55. data/lib/cauterize/cauterize.rb +76 -76
  56. data/lib/cauterize/composite.rb +64 -64
  57. data/lib/cauterize/cs_builder.rb +58 -58
  58. data/lib/cauterize/doc_builder.rb +34 -34
  59. data/lib/cauterize/enumeration.rb +98 -98
  60. data/lib/cauterize/fixed_array.rb +50 -50
  61. data/lib/cauterize/formatter.rb +67 -67
  62. data/lib/cauterize/group.rb +81 -81
  63. data/lib/cauterize/representation.rb +32 -32
  64. data/lib/cauterize/ruby_builder.rb +44 -44
  65. data/lib/cauterize/scalar.rb +53 -53
  66. data/lib/cauterize/snake_case.rb +21 -21
  67. data/lib/cauterize/variable_array.rb +55 -55
  68. data/lib/cauterize/version.rb +3 -3
  69. data/spec/base_type_spec.rb +251 -251
  70. data/spec/builders/c/buildable_spec.rb +25 -25
  71. data/spec/builders/c/builtin_spec.rb +22 -22
  72. data/spec/builders/c/composite_spec.rb +50 -50
  73. data/spec/builders/c/enumeration_spec.rb +95 -95
  74. data/spec/builders/c/fixed_array_spec.rb +36 -36
  75. data/spec/builders/c/group_spec.rb +140 -140
  76. data/spec/builders/c/scalar_spec.rb +26 -26
  77. data/spec/builders/c/variable_array_spec.rb +48 -48
  78. data/spec/builders/cs/buildable_spec.rb +8 -8
  79. data/spec/builders/cs/composite_spec.rb +32 -32
  80. data/spec/builders/cs/enumeration_spec.rb +33 -33
  81. data/spec/builders/cs/fixed_array_spec.rb +41 -41
  82. data/spec/builders/cs/group_spec.rb +56 -56
  83. data/spec/builders/cs/scalar_spec.rb +7 -7
  84. data/spec/builders/cs/variable_array_spec.rb +49 -45
  85. data/spec/builders/doc/buildable_spec.rb +25 -25
  86. data/spec/builders_spec.rb +57 -57
  87. data/spec/builtin_spec.rb +43 -43
  88. data/spec/c_builder_spec.rb +176 -176
  89. data/spec/cauterize_spec.rb +15 -15
  90. data/spec/composite_spec.rb +77 -77
  91. data/spec/cs_builder_spec.rb +115 -115
  92. data/spec/doc_builder_spec.rb +260 -260
  93. data/spec/enumeration_spec.rb +145 -145
  94. data/spec/fixed_array_spec.rb +61 -61
  95. data/spec/group_spec.rb +111 -111
  96. data/spec/ruby_builder_spec.rb +83 -83
  97. data/spec/ruby_generated_spec.rb +735 -735
  98. data/spec/scalar_spec.rb +44 -44
  99. data/spec/spec_helper.rb +122 -122
  100. data/spec/support/shared_examples_for_array_buildables.rb +22 -22
  101. data/spec/support/shared_examples_for_c_buildables.rb +103 -103
  102. data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
  103. data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
  104. data/spec/support/spec_sample_model.rb +74 -74
  105. data/spec/test_main.c +13 -13
  106. data/spec/variable_array_spec.rb +73 -73
  107. data/support/c/src/cauterize.c +75 -75
  108. data/support/c/src/cauterize.h +60 -60
  109. data/support/c/src/cauterize_debug.h +29 -29
  110. data/support/c/src/cauterize_util.h +8 -8
  111. data/support/c/test/greatest.h +536 -536
  112. data/support/c/test/test.c +166 -166
  113. data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
  114. data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
  115. data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
  116. data/support/cs/src/CauterizeException.cs +15 -15
  117. data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
  118. data/support/cs/src/CauterizeFormatter.cs +0 -0
  119. data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
  120. data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
  121. data/support/cs/src/CauterizeTypes.cs +46 -12
  122. data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
  123. data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
  124. data/support/cs/src/OrderAttribute.cs +0 -0
  125. data/support/cs/src/PrimitiveSupport.cs +12 -0
  126. data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
  127. data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
  128. data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
  129. data/support/cs/test/CauterizeFormatterTest.cs +0 -0
  130. data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
  131. data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
  132. data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
  133. data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
  134. data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
  135. data/support/cs/test/OrderAttributeTest.cs +0 -0
  136. data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
  137. data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
  138. metadata +20 -20
@@ -1,77 +1,77 @@
1
- module Cauterize
2
- describe Cauterize do
3
- describe CompositeField do
4
- describe :initialize do
5
- it "creates a new name -> type mapping" do
6
- a = Cauterize.scalar(:a_type)
7
- b = Cauterize.scalar(:b_type)
8
- f = CompositeField.new(:a_name, :a_type)
9
- f.name.should == :a_name
10
- f.type.should be a
11
- end
12
- end
13
- end
14
-
15
- describe Composite do
16
- describe :initialize do
17
- it "creates a Composite" do
18
- c = Composite.new(:foo)
19
- c.name.should == :foo
20
- end
21
- end
22
-
23
- it { can_be_documented(Composite) }
24
-
25
- describe :fields do
26
- it "defines a new field in the composite" do
27
- a = Cauterize.scalar(:foo)
28
- comp = Cauterize.composite(:comp) do |c|
29
- c.field :a_foo, :foo
30
- end
31
-
32
- comp.fields.keys[0].should == :a_foo
33
- comp.fields.values[0].name.should == :a_foo
34
- comp.fields.values[0].type.should be a
35
- end
36
-
37
- it "supports a doc string" do
38
- a = Cauterize.scalar(:foo)
39
- comp = Cauterize.composite(:comp) do |c|
40
- c.field :a_foo, :foo, "some foo"
41
- end
42
-
43
- comp.fields.values[0].description.should == "some foo"
44
- end
45
-
46
- it "errors on duplicate field names" do
47
- a = Cauterize.scalar(:foo)
48
- lambda {
49
- Cauterize.composite(:comp) do |c|
50
- c.field :a_foo, :foo
51
- c.field :b_foo, :foo
52
- c.field :b_foo, :foo
53
- end
54
- }.should raise_error /Field name b_foo already used/
55
- end
56
- end
57
- end
58
-
59
- describe :composite do
60
- it { creates_a_named_object(:composite, Composite) }
61
- it { retrieves_obj_with_identical_name(:composite) }
62
- it { yields_the_object(:composite) }
63
- it { adds_object_to_hash(:composite, Cauterize.composites) }
64
- end
65
-
66
- describe :composite! do
67
- it { creates_a_named_object(:composite!, Composite) }
68
- it { raises_exception_with_identical_name(:composite!) }
69
- it { yields_the_object(:composite!) }
70
- it { adds_object_to_hash(:composite!, Cauterize.composites) }
71
- end
72
-
73
- describe :composites do
74
- it { is_hash_of_created_objs(:composite, Cauterize.composites) }
75
- end
76
- end
77
- end
1
+ module Cauterize
2
+ describe Cauterize do
3
+ describe CompositeField do
4
+ describe :initialize do
5
+ it "creates a new name -> type mapping" do
6
+ a = Cauterize.scalar(:a_type)
7
+ b = Cauterize.scalar(:b_type)
8
+ f = CompositeField.new(:a_name, :a_type)
9
+ f.name.should == :a_name
10
+ f.type.should be a
11
+ end
12
+ end
13
+ end
14
+
15
+ describe Composite do
16
+ describe :initialize do
17
+ it "creates a Composite" do
18
+ c = Composite.new(:foo)
19
+ c.name.should == :foo
20
+ end
21
+ end
22
+
23
+ it { can_be_documented(Composite) }
24
+
25
+ describe :fields do
26
+ it "defines a new field in the composite" do
27
+ a = Cauterize.scalar(:foo)
28
+ comp = Cauterize.composite(:comp) do |c|
29
+ c.field :a_foo, :foo
30
+ end
31
+
32
+ comp.fields.keys[0].should == :a_foo
33
+ comp.fields.values[0].name.should == :a_foo
34
+ comp.fields.values[0].type.should be a
35
+ end
36
+
37
+ it "supports a doc string" do
38
+ a = Cauterize.scalar(:foo)
39
+ comp = Cauterize.composite(:comp) do |c|
40
+ c.field :a_foo, :foo, "some foo"
41
+ end
42
+
43
+ comp.fields.values[0].description.should == "some foo"
44
+ end
45
+
46
+ it "errors on duplicate field names" do
47
+ a = Cauterize.scalar(:foo)
48
+ lambda {
49
+ Cauterize.composite(:comp) do |c|
50
+ c.field :a_foo, :foo
51
+ c.field :b_foo, :foo
52
+ c.field :b_foo, :foo
53
+ end
54
+ }.should raise_error /Field name b_foo already used/
55
+ end
56
+ end
57
+ end
58
+
59
+ describe :composite do
60
+ it { creates_a_named_object(:composite, Composite) }
61
+ it { retrieves_obj_with_identical_name(:composite) }
62
+ it { yields_the_object(:composite) }
63
+ it { adds_object_to_hash(:composite, Cauterize.composites) }
64
+ end
65
+
66
+ describe :composite! do
67
+ it { creates_a_named_object(:composite!, Composite) }
68
+ it { raises_exception_with_identical_name(:composite!) }
69
+ it { yields_the_object(:composite!) }
70
+ it { adds_object_to_hash(:composite!, Cauterize.composites) }
71
+ end
72
+
73
+ describe :composites do
74
+ it { is_hash_of_created_objs(:composite, Cauterize.composites) }
75
+ end
76
+ end
77
+ end
@@ -1,115 +1,115 @@
1
- require 'tmpdir'
2
- require 'fileutils'
3
-
4
- module Cauterize
5
- describe Cauterize::CSBuilder do
6
- before do
7
- @tempdir = Dir.mktmpdir
8
- @cs_path = File.join(@tempdir, "testing.cs")
9
- @csb = CSBuilder.new(@cs_path, "testing")
10
- end
11
-
12
- after do
13
- FileUtils.rm_rf @tempdir
14
- end
15
-
16
- describe :build do
17
- before do
18
- Cauterize.set_version("1.2.3")
19
-
20
- Cauterize.scalar(:uint8_t) { |t| t.type_name(:uint8) }
21
- Cauterize.scalar(:uint16_t) { |t| t.type_name(:uint16) }
22
- Cauterize.scalar(:uint32_t) { |t| t.type_name(:uint32) }
23
-
24
- Cauterize.fixed_array(:mac_address) do |fa|
25
- fa.array_type :uint8_t
26
- fa.array_size 6
27
- end
28
-
29
- Cauterize.variable_array(:mac_table) do |t|
30
- t.array_type :mac_address
31
- t.array_size 64
32
- end
33
-
34
- Cauterize.variable_array(:name) do |va|
35
- va.array_type :uint8_t
36
- va.array_size 32
37
- end
38
-
39
- Cauterize.enumeration(:gender) do |e|
40
- e.value :male
41
- e.value :female
42
- end
43
-
44
- Cauterize.composite(:place) do |c|
45
- c.field :name, :name
46
- c.field :elevation, :uint32_t
47
- end
48
-
49
- Cauterize.composite(:person) do |c|
50
- c.field :first_name, :name
51
- c.field :last_name, :name
52
- c.field :gender, :gender
53
- end
54
-
55
- Cauterize.composite(:dog) do |c|
56
- c.field :name, :name
57
- c.field :gender, :gender
58
- c.field :leg_count, :uint8_t
59
- end
60
-
61
- Cauterize.group(:creature) do |g|
62
- g.field :person, :person
63
- g.field :dog, :dog
64
- end
65
-
66
- @csb.build
67
- @cs_text = File.read(@csb.cs)
68
- @cs_lines = @cs_text.lines.to_a
69
- end
70
-
71
- it "informs the user the code is generated" do
72
- @cs_text.should match /generated code. Do not edit/
73
- end
74
-
75
- it "includes namespaces" do
76
- @cs_lines.should include("using System;\n")
77
- @cs_lines.should include("using Cauterize;\n")
78
- end
79
-
80
- it "uses a namespace" do
81
- @cs_lines.should include("namespace Testing\n")
82
- end
83
-
84
- it "creates a cauterize info class with version and date" do
85
- @cs_text.should match /Name = \"Testing\",/
86
- @cs_text.should match /GeneratedVersion = \"1.2.3\",/
87
- @cs_text.should match /GeneratedDate = /
88
- end
89
-
90
- it "includes enumeration definitions" do
91
- @cs_text.should match /public enum Gender/
92
- @cs_text.should match /Male = 0/
93
- @cs_text.should match /Female = 1/
94
- end
95
-
96
- # it "can be built" do
97
- # caut_dir = "#{File.dirname(__FILE__)}/../cs/src"
98
-
99
- # res = Dir.chdir @tempdir do
100
- # File.open("test_main.cs", "wb") do |fh|
101
- # syms = BaseType.all_instances.map do |i|
102
- # b = Builders.get(:cs, i)
103
- # [b.packer_sym, b.unpacker_sym]
104
- # end.flatten
105
- # fh.write(gen_test_main(syms))
106
- # end
107
-
108
- # `dmcs -lib:#{caut_dir} -target:library test_main.cs 2>&1`
109
- # end
110
-
111
- # res.should == ""
112
- # end
113
- end
114
- end
115
- end
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+
4
+ module Cauterize
5
+ describe Cauterize::CSBuilder do
6
+ before do
7
+ @tempdir = Dir.mktmpdir
8
+ @cs_path = File.join(@tempdir, "testing.cs")
9
+ @csb = CSBuilder.new(@cs_path, "testing")
10
+ end
11
+
12
+ after do
13
+ FileUtils.rm_rf @tempdir
14
+ end
15
+
16
+ describe :build do
17
+ before do
18
+ Cauterize.set_version("1.2.3")
19
+
20
+ Cauterize.scalar(:uint8_t) { |t| t.type_name(:uint8) }
21
+ Cauterize.scalar(:uint16_t) { |t| t.type_name(:uint16) }
22
+ Cauterize.scalar(:uint32_t) { |t| t.type_name(:uint32) }
23
+
24
+ Cauterize.fixed_array(:mac_address) do |fa|
25
+ fa.array_type :uint8_t
26
+ fa.array_size 6
27
+ end
28
+
29
+ Cauterize.variable_array(:mac_table) do |t|
30
+ t.array_type :mac_address
31
+ t.array_size 64
32
+ end
33
+
34
+ Cauterize.variable_array(:name) do |va|
35
+ va.array_type :uint8_t
36
+ va.array_size 32
37
+ end
38
+
39
+ Cauterize.enumeration(:gender) do |e|
40
+ e.value :male
41
+ e.value :female
42
+ end
43
+
44
+ Cauterize.composite(:place) do |c|
45
+ c.field :name, :name
46
+ c.field :elevation, :uint32_t
47
+ end
48
+
49
+ Cauterize.composite(:person) do |c|
50
+ c.field :first_name, :name
51
+ c.field :last_name, :name
52
+ c.field :gender, :gender
53
+ end
54
+
55
+ Cauterize.composite(:dog) do |c|
56
+ c.field :name, :name
57
+ c.field :gender, :gender
58
+ c.field :leg_count, :uint8_t
59
+ end
60
+
61
+ Cauterize.group(:creature) do |g|
62
+ g.field :person, :person
63
+ g.field :dog, :dog
64
+ end
65
+
66
+ @csb.build
67
+ @cs_text = File.read(@csb.cs)
68
+ @cs_lines = @cs_text.lines.to_a
69
+ end
70
+
71
+ it "informs the user the code is generated" do
72
+ @cs_text.should match /generated code. Do not edit/
73
+ end
74
+
75
+ it "includes namespaces" do
76
+ @cs_lines.should include("using System;\n")
77
+ @cs_lines.should include("using Cauterize;\n")
78
+ end
79
+
80
+ it "uses a namespace" do
81
+ @cs_lines.should include("namespace Testing\n")
82
+ end
83
+
84
+ it "creates a cauterize info class with version and date" do
85
+ @cs_text.should match /Name = \"Testing\",/
86
+ @cs_text.should match /GeneratedVersion = \"1.2.3\",/
87
+ @cs_text.should match /GeneratedDate = /
88
+ end
89
+
90
+ it "includes enumeration definitions" do
91
+ @cs_text.should match /public enum Gender/
92
+ @cs_text.should match /Male = 0/
93
+ @cs_text.should match /Female = 1/
94
+ end
95
+
96
+ # it "can be built" do
97
+ # caut_dir = "#{File.dirname(__FILE__)}/../cs/src"
98
+
99
+ # res = Dir.chdir @tempdir do
100
+ # File.open("test_main.cs", "wb") do |fh|
101
+ # syms = BaseType.all_instances.map do |i|
102
+ # b = Builders.get(:cs, i)
103
+ # [b.packer_sym, b.unpacker_sym]
104
+ # end.flatten
105
+ # fh.write(gen_test_main(syms))
106
+ # end
107
+
108
+ # `dmcs -lib:#{caut_dir} -target:library test_main.cs 2>&1`
109
+ # end
110
+
111
+ # res.should == ""
112
+ # end
113
+ end
114
+ end
115
+ end
@@ -1,260 +1,260 @@
1
- require 'tmpdir'
2
- require 'fileutils'
3
-
4
- module Cauterize
5
- describe Cauterize::DocBuilder do
6
- before do
7
- @tempdir = Dir.mktmpdir
8
- @doc_path = File.join(@tempdir, "testing.txt")
9
-
10
- @db = DocBuilder.new(@doc_path, "testing")
11
- end
12
-
13
- after do
14
- FileUtils.rm_rf @tempdir
15
- end
16
-
17
- describe :initialize do
18
- it "should save the name" do
19
- @db.name.should == "testing"
20
- @db.doc_path.should == @doc_path
21
- end
22
- end
23
-
24
- describe :build do
25
- before do
26
- Cauterize.set_version("1.2.3")
27
-
28
- Cauterize.scalar(:an_int, "a useful int") {|t| t.type_name :int32}
29
- Cauterize.scalar(:another_int) {|t| t.type_name :int32}
30
-
31
- Cauterize.composite(:a_composite, "some useful fields") do |t|
32
- t.field :an_int, :int32, "a pretty integer"
33
- t.field :another_int, :int32, "another pretty integer"
34
- t.field :undescribed, :int32
35
- end
36
-
37
- Cauterize.composite(:mystery) do |t|
38
- t.field :undescribed, :int32
39
- end
40
-
41
- Cauterize.fixed_array(:a_fixed_array, "a few things") do |t|
42
- t.array_type :an_int
43
- t.array_size 5
44
- end
45
-
46
- Cauterize.fixed_array(:a_mystery_array) do |t|
47
- t.array_type :uint8
48
- t.array_size 1
49
- end
50
-
51
- Cauterize.variable_array(:a_var_array, "maybe some things") do |t|
52
- t.array_type :an_int
53
- t.array_size 5
54
- end
55
-
56
- Cauterize.variable_array(:a_var_mystery) do |t|
57
- t.array_type :uint8
58
- t.array_size 1
59
- end
60
-
61
- Cauterize.enumeration(:some_colors, "several colors to choose from") do |t|
62
- t.value :red
63
- t.value :blue
64
- t.value :green
65
- end
66
-
67
- Cauterize.enumeration(:mystery_things) do |t|
68
- t.value :thing1
69
- t.value :thing2
70
- t.value :thing3
71
- end
72
-
73
- Cauterize.group(:oddness, "a mix of weird things") do |t|
74
- t.field :a_color, :some_colors, "a color"
75
- t.field :a_cool_int, :int16, "only cool ints fit here"
76
- t.dataless :a_thing, "only a thing"
77
- t.dataless :undescribed
78
- end
79
-
80
- Cauterize.group(:mystery_oddness) do |t|
81
- t.field :a_color, :some_colors
82
- t.field :a_cool_int, :int16
83
- t.dataless :a_thing, "only a thing"
84
- t.dataless :undescribed
85
- end
86
-
87
- @db.build
88
- @doc_text = File.read(@doc_path)
89
- @doc_lines = @doc_text.lines.to_a
90
- end
91
-
92
- describe "doc generation" do
93
- it "contains type details" do
94
- t = <<EOF
95
- Type Name: int8
96
- Cauterize Class: built-in
97
- Description: <none>
98
- data - size: 1 bytes
99
-
100
- Type Name: int16
101
- Cauterize Class: built-in
102
- Description: <none>
103
- data - size: 2 bytes
104
-
105
- Type Name: int32
106
- Cauterize Class: built-in
107
- Description: <none>
108
- data - size: 4 bytes
109
-
110
- Type Name: int64
111
- Cauterize Class: built-in
112
- Description: <none>
113
- data - size: 8 bytes
114
-
115
- Type Name: uint8
116
- Cauterize Class: built-in
117
- Description: <none>
118
- data - size: 1 bytes
119
-
120
- Type Name: uint16
121
- Cauterize Class: built-in
122
- Description: <none>
123
- data - size: 2 bytes
124
-
125
- Type Name: uint32
126
- Cauterize Class: built-in
127
- Description: <none>
128
- data - size: 4 bytes
129
-
130
- Type Name: uint64
131
- Cauterize Class: built-in
132
- Description: <none>
133
- data - size: 8 bytes
134
-
135
- Type Name: float32
136
- Cauterize Class: built-in
137
- Description: <none>
138
- data - size: 4 bytes
139
-
140
- Type Name: float64
141
- Cauterize Class: built-in
142
- Description: <none>
143
- data - size: 8 bytes
144
-
145
- Type Name: bool
146
- Cauterize Class: built-in
147
- Description: <none>
148
- data - size: 1 bytes
149
-
150
- Type Name: an_int
151
- Cauterize Class: scalar
152
- Description: - a useful int
153
- data - type: int32
154
-
155
- Type Name: another_int
156
- Cauterize Class: scalar
157
- Description: <none>
158
- data - type: int32
159
-
160
- Type Name: a_composite
161
- Cauterize Class: composite
162
- Description: some useful fields
163
- an_int - type: int32 - description: a pretty integer
164
- another_int - type: int32 - description: another pretty integer
165
- undescribed - type: int32
166
-
167
- Type Name: mystery
168
- Cauterize Class: composite
169
- Description: <none>
170
- undescribed - type: int32
171
-
172
- Type Name: a_fixed_array
173
- Cauterize Class: fixed-array
174
- Description: a few things
175
- Stored Type: an_int
176
- Value Count: 5
177
- data - 5 values of type an_int
178
-
179
- Type Name: a_mystery_array
180
- Cauterize Class: fixed-array
181
- Description: <none>
182
- Stored Type: uint8
183
- Value Count: 1
184
- data - 1 values of type uint8
185
-
186
- Type Name: a_var_array
187
- Cauterize Class: variable-array
188
- Description: maybe some things
189
- Maximum Value Count: 5
190
- length - type uint8
191
- data - 0 to 5 values of type an_int
192
-
193
- Type Name: a_var_mystery
194
- Cauterize Class: variable-array
195
- Description: <none>
196
- Maximum Value Count: 1
197
- length - type uint8
198
- data - 0 to 1 values of type uint8
199
-
200
- Type Name: some_colors
201
- Cauterize Class: enumeration
202
- Description: several colors to choose from
203
- Encoding: int8
204
- red = 0
205
- blue = 1
206
- green = 2
207
-
208
- Type Name: mystery_things
209
- Cauterize Class: enumeration
210
- Description: <none>
211
- Encoding: int8
212
- thing1 = 0
213
- thing2 = 1
214
- thing3 = 2
215
-
216
- Type Name: group_oddness_type
217
- Cauterize Class: enumeration
218
- Description: <none>
219
- Encoding: int8
220
- GROUP_ODDNESS_TYPE_A_COLOR = 0
221
- GROUP_ODDNESS_TYPE_A_COOL_INT = 1
222
- GROUP_ODDNESS_TYPE_A_THING = 2
223
- GROUP_ODDNESS_TYPE_UNDESCRIBED = 3
224
-
225
- Type Name: oddness
226
- Cauterize Class: group
227
- Description: a mix of weird things
228
- kind tag: group_oddness_type
229
- kinds:
230
- a_color - payload: some_colors - description: a color
231
- a_cool_int - payload: int16 - description: only cool ints fit here
232
- a_thing - payload: <no payload> - description: only a thing
233
- undescribed - payload: <no payload>
234
-
235
- Type Name: group_mystery_oddness_type
236
- Cauterize Class: enumeration
237
- Description: <none>
238
- Encoding: int8
239
- GROUP_MYSTERY_ODDNESS_TYPE_A_COLOR = 0
240
- GROUP_MYSTERY_ODDNESS_TYPE_A_COOL_INT = 1
241
- GROUP_MYSTERY_ODDNESS_TYPE_A_THING = 2
242
- GROUP_MYSTERY_ODDNESS_TYPE_UNDESCRIBED = 3
243
-
244
- Type Name: mystery_oddness
245
- Cauterize Class: group
246
- Description: <none>
247
- kind tag: group_mystery_oddness_type
248
- kinds:
249
- a_color - payload: some_colors
250
- a_cool_int - payload: int16
251
- a_thing - payload: <no payload> - description: only a thing
252
- undescribed - payload: <no payload>
253
- EOF
254
- @doc_text.should == t
255
- end
256
- end
257
- end
258
- end
259
-
260
- end
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+
4
+ module Cauterize
5
+ describe Cauterize::DocBuilder do
6
+ before do
7
+ @tempdir = Dir.mktmpdir
8
+ @doc_path = File.join(@tempdir, "testing.txt")
9
+
10
+ @db = DocBuilder.new(@doc_path, "testing")
11
+ end
12
+
13
+ after do
14
+ FileUtils.rm_rf @tempdir
15
+ end
16
+
17
+ describe :initialize do
18
+ it "should save the name" do
19
+ @db.name.should == "testing"
20
+ @db.doc_path.should == @doc_path
21
+ end
22
+ end
23
+
24
+ describe :build do
25
+ before do
26
+ Cauterize.set_version("1.2.3")
27
+
28
+ Cauterize.scalar(:an_int, "a useful int") {|t| t.type_name :int32}
29
+ Cauterize.scalar(:another_int) {|t| t.type_name :int32}
30
+
31
+ Cauterize.composite(:a_composite, "some useful fields") do |t|
32
+ t.field :an_int, :int32, "a pretty integer"
33
+ t.field :another_int, :int32, "another pretty integer"
34
+ t.field :undescribed, :int32
35
+ end
36
+
37
+ Cauterize.composite(:mystery) do |t|
38
+ t.field :undescribed, :int32
39
+ end
40
+
41
+ Cauterize.fixed_array(:a_fixed_array, "a few things") do |t|
42
+ t.array_type :an_int
43
+ t.array_size 5
44
+ end
45
+
46
+ Cauterize.fixed_array(:a_mystery_array) do |t|
47
+ t.array_type :uint8
48
+ t.array_size 1
49
+ end
50
+
51
+ Cauterize.variable_array(:a_var_array, "maybe some things") do |t|
52
+ t.array_type :an_int
53
+ t.array_size 5
54
+ end
55
+
56
+ Cauterize.variable_array(:a_var_mystery) do |t|
57
+ t.array_type :uint8
58
+ t.array_size 1
59
+ end
60
+
61
+ Cauterize.enumeration(:some_colors, "several colors to choose from") do |t|
62
+ t.value :red
63
+ t.value :blue
64
+ t.value :green
65
+ end
66
+
67
+ Cauterize.enumeration(:mystery_things) do |t|
68
+ t.value :thing1
69
+ t.value :thing2
70
+ t.value :thing3
71
+ end
72
+
73
+ Cauterize.group(:oddness, "a mix of weird things") do |t|
74
+ t.field :a_color, :some_colors, "a color"
75
+ t.field :a_cool_int, :int16, "only cool ints fit here"
76
+ t.dataless :a_thing, "only a thing"
77
+ t.dataless :undescribed
78
+ end
79
+
80
+ Cauterize.group(:mystery_oddness) do |t|
81
+ t.field :a_color, :some_colors
82
+ t.field :a_cool_int, :int16
83
+ t.dataless :a_thing, "only a thing"
84
+ t.dataless :undescribed
85
+ end
86
+
87
+ @db.build
88
+ @doc_text = File.read(@doc_path)
89
+ @doc_lines = @doc_text.lines.to_a
90
+ end
91
+
92
+ describe "doc generation" do
93
+ it "contains type details" do
94
+ t = <<EOF
95
+ Type Name: int8
96
+ Cauterize Class: built-in
97
+ Description: <none>
98
+ data - size: 1 bytes
99
+
100
+ Type Name: int16
101
+ Cauterize Class: built-in
102
+ Description: <none>
103
+ data - size: 2 bytes
104
+
105
+ Type Name: int32
106
+ Cauterize Class: built-in
107
+ Description: <none>
108
+ data - size: 4 bytes
109
+
110
+ Type Name: int64
111
+ Cauterize Class: built-in
112
+ Description: <none>
113
+ data - size: 8 bytes
114
+
115
+ Type Name: uint8
116
+ Cauterize Class: built-in
117
+ Description: <none>
118
+ data - size: 1 bytes
119
+
120
+ Type Name: uint16
121
+ Cauterize Class: built-in
122
+ Description: <none>
123
+ data - size: 2 bytes
124
+
125
+ Type Name: uint32
126
+ Cauterize Class: built-in
127
+ Description: <none>
128
+ data - size: 4 bytes
129
+
130
+ Type Name: uint64
131
+ Cauterize Class: built-in
132
+ Description: <none>
133
+ data - size: 8 bytes
134
+
135
+ Type Name: float32
136
+ Cauterize Class: built-in
137
+ Description: <none>
138
+ data - size: 4 bytes
139
+
140
+ Type Name: float64
141
+ Cauterize Class: built-in
142
+ Description: <none>
143
+ data - size: 8 bytes
144
+
145
+ Type Name: bool
146
+ Cauterize Class: built-in
147
+ Description: <none>
148
+ data - size: 1 bytes
149
+
150
+ Type Name: an_int
151
+ Cauterize Class: scalar
152
+ Description: - a useful int
153
+ data - type: int32
154
+
155
+ Type Name: another_int
156
+ Cauterize Class: scalar
157
+ Description: <none>
158
+ data - type: int32
159
+
160
+ Type Name: a_composite
161
+ Cauterize Class: composite
162
+ Description: some useful fields
163
+ an_int - type: int32 - description: a pretty integer
164
+ another_int - type: int32 - description: another pretty integer
165
+ undescribed - type: int32
166
+
167
+ Type Name: mystery
168
+ Cauterize Class: composite
169
+ Description: <none>
170
+ undescribed - type: int32
171
+
172
+ Type Name: a_fixed_array
173
+ Cauterize Class: fixed-array
174
+ Description: a few things
175
+ Stored Type: an_int
176
+ Value Count: 5
177
+ data - 5 values of type an_int
178
+
179
+ Type Name: a_mystery_array
180
+ Cauterize Class: fixed-array
181
+ Description: <none>
182
+ Stored Type: uint8
183
+ Value Count: 1
184
+ data - 1 values of type uint8
185
+
186
+ Type Name: a_var_array
187
+ Cauterize Class: variable-array
188
+ Description: maybe some things
189
+ Maximum Value Count: 5
190
+ length - type uint8
191
+ data - 0 to 5 values of type an_int
192
+
193
+ Type Name: a_var_mystery
194
+ Cauterize Class: variable-array
195
+ Description: <none>
196
+ Maximum Value Count: 1
197
+ length - type uint8
198
+ data - 0 to 1 values of type uint8
199
+
200
+ Type Name: some_colors
201
+ Cauterize Class: enumeration
202
+ Description: several colors to choose from
203
+ Encoding: int8
204
+ red = 0
205
+ blue = 1
206
+ green = 2
207
+
208
+ Type Name: mystery_things
209
+ Cauterize Class: enumeration
210
+ Description: <none>
211
+ Encoding: int8
212
+ thing1 = 0
213
+ thing2 = 1
214
+ thing3 = 2
215
+
216
+ Type Name: group_oddness_type
217
+ Cauterize Class: enumeration
218
+ Description: <none>
219
+ Encoding: int8
220
+ GROUP_ODDNESS_TYPE_A_COLOR = 0
221
+ GROUP_ODDNESS_TYPE_A_COOL_INT = 1
222
+ GROUP_ODDNESS_TYPE_A_THING = 2
223
+ GROUP_ODDNESS_TYPE_UNDESCRIBED = 3
224
+
225
+ Type Name: oddness
226
+ Cauterize Class: group
227
+ Description: a mix of weird things
228
+ kind tag: group_oddness_type
229
+ kinds:
230
+ a_color - payload: some_colors - description: a color
231
+ a_cool_int - payload: int16 - description: only cool ints fit here
232
+ a_thing - payload: <no payload> - description: only a thing
233
+ undescribed - payload: <no payload>
234
+
235
+ Type Name: group_mystery_oddness_type
236
+ Cauterize Class: enumeration
237
+ Description: <none>
238
+ Encoding: int8
239
+ GROUP_MYSTERY_ODDNESS_TYPE_A_COLOR = 0
240
+ GROUP_MYSTERY_ODDNESS_TYPE_A_COOL_INT = 1
241
+ GROUP_MYSTERY_ODDNESS_TYPE_A_THING = 2
242
+ GROUP_MYSTERY_ODDNESS_TYPE_UNDESCRIBED = 3
243
+
244
+ Type Name: mystery_oddness
245
+ Cauterize Class: group
246
+ Description: <none>
247
+ kind tag: group_mystery_oddness_type
248
+ kinds:
249
+ a_color - payload: some_colors
250
+ a_cool_int - payload: int16
251
+ a_thing - payload: <no payload> - description: only a thing
252
+ undescribed - payload: <no payload>
253
+ EOF
254
+ @doc_text.should == t
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ end