slow_blink 0.0.2 → 0.0.3

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_compact_encoder/compact_encoder.c +258 -0
  3. data/ext/slow_blink/ext_compact_encoder/compact_encoder.h +92 -0
  4. data/ext/slow_blink/ext_compact_encoder/ext_compact_encoder.c +555 -0
  5. data/ext/slow_blink/ext_compact_encoder/extconf.rb +4 -0
  6. data/ext/slow_blink/ext_schema_parser/lexer.c +59 -59
  7. data/ext/slow_blink/ext_schema_parser/lexer.h +2 -2
  8. data/ext/slow_blink/ext_schema_parser/parser.c +380 -367
  9. data/ext/slow_blink/ext_schema_parser/parser.h +1 -1
  10. data/lib/slow_blink/annotatable.rb +1 -1
  11. data/lib/slow_blink/annotation.rb +5 -5
  12. data/lib/slow_blink/binary.rb +26 -0
  13. data/lib/slow_blink/boolean.rb +26 -0
  14. data/lib/slow_blink/compact_encoder.rb +45 -71
  15. data/lib/slow_blink/date.rb +25 -0
  16. data/lib/slow_blink/decimal.rb +26 -0
  17. data/lib/slow_blink/definition.rb +19 -10
  18. data/lib/slow_blink/enumeration.rb +14 -36
  19. data/lib/slow_blink/error.rb +19 -0
  20. data/lib/slow_blink/field.rb +3 -16
  21. data/lib/slow_blink/fixed.rb +26 -0
  22. data/lib/slow_blink/floating_point.rb +27 -0
  23. data/lib/slow_blink/group.rb +30 -43
  24. data/lib/slow_blink/incremental_annotation.rb +75 -21
  25. data/lib/slow_blink/integer.rb +65 -0
  26. data/lib/slow_blink/message/binary.rb +87 -0
  27. data/lib/slow_blink/message/boolean.rb +68 -0
  28. data/lib/slow_blink/message/date.rb +33 -0
  29. data/lib/slow_blink/message/decimal.rb +25 -0
  30. data/lib/slow_blink/message/enumeration.rb +69 -0
  31. data/lib/slow_blink/message/field.rb +73 -0
  32. data/lib/slow_blink/message/fixed.rb +84 -0
  33. data/lib/slow_blink/message/floating_point.rb +68 -0
  34. data/lib/slow_blink/message/group.rb +260 -0
  35. data/lib/slow_blink/message/integer.rb +217 -0
  36. data/lib/slow_blink/message/model.rb +202 -0
  37. data/lib/slow_blink/message/sequence.rb +85 -0
  38. data/lib/slow_blink/message/string.rb +95 -0
  39. data/lib/slow_blink/message/time.rb +78 -0
  40. data/lib/slow_blink/message/time_of_day.rb +132 -0
  41. data/lib/slow_blink/name_with_id.rb +2 -1
  42. data/lib/slow_blink/namespace.rb +140 -0
  43. data/lib/slow_blink/object.rb +29 -0
  44. data/lib/slow_blink/ref.rb +93 -0
  45. data/lib/slow_blink/schema.rb +94 -68
  46. data/lib/slow_blink/{component_reference.rb → schema_buffer.rb} +11 -22
  47. data/lib/slow_blink/sequence.rb +58 -0
  48. data/lib/slow_blink/string.rb +40 -0
  49. data/lib/slow_blink/sym.rb +4 -0
  50. data/lib/slow_blink/time.rb +30 -0
  51. data/lib/slow_blink/time_of_day.rb +30 -0
  52. data/lib/slow_blink/type.rb +7 -402
  53. data/lib/slow_blink/version.rb +1 -1
  54. data/lib/slow_blink.rb +1 -0
  55. data/rakefile +14 -3
  56. data/test/{integration/capture_stderr.rb → capture_stderr.rb} +0 -0
  57. data/test/tc_compact_encoder.rb +341 -0
  58. data/test/tc_field.rb +53 -0
  59. data/test/tc_group.rb +122 -0
  60. data/test/tc_incr_annote.rb +27 -0
  61. data/test/{integration/tc_inputs.rb → tc_inputs.rb} +7 -11
  62. data/test/tc_model.rb +65 -0
  63. data/test/tc_model_encode.rb +63 -0
  64. data/test/tc_namespace.rb +8 -0
  65. data/test/tc_types.rb +198 -0
  66. metadata +58 -11
  67. data/ext/slow_blink/ext_schema_parser/parser.l +0 -139
  68. data/ext/slow_blink/ext_schema_parser/parser.y +0 -932
  69. data/lib/slow_blink/message.rb +0 -43
@@ -0,0 +1,341 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ require "test/unit"
21
+ require 'slow_blink'
22
+
23
+ class TestCompactEncoder < Test::Unit::TestCase
24
+
25
+ include SlowBlink
26
+
27
+ def test_putU8
28
+ input = 0x7f
29
+ output = "".putU8(input)
30
+ assert_equal("\x7f", output)
31
+ end
32
+
33
+ def test_putU8_big
34
+ input = 0x80
35
+ output = "".putU8(input)
36
+ assert_equal("\x80\x02", output)
37
+ end
38
+
39
+ def test_putU8_tooBig
40
+ input = 0x100
41
+ assert_raise do
42
+ "".putU8(input)
43
+ end
44
+ end
45
+
46
+ def test_putU8_null
47
+ input = nil
48
+ output = "".putU8(input)
49
+ assert_equal("\xc0", output)
50
+ end
51
+
52
+ def test_putU16_small
53
+ input = 0xff
54
+ output = "".putU16(input)
55
+ assert_equal("\xbf\x03", output)
56
+ end
57
+
58
+ def test_putU16
59
+ input = 0xffff
60
+ output = "".putU16(input)
61
+ assert_equal("\xC2\xff\xff", output)
62
+ end
63
+
64
+ # Blink Specification 3.1
65
+ def test_putU8_64unsigned
66
+ input = 64
67
+ output = "".putU8(input)
68
+ assert_equal("\x40", output)
69
+ end
70
+
71
+ # Blink Specification 3.1
72
+ def test_putI8_64signed
73
+ input = 64
74
+ output = "".putI8(input)
75
+ assert_equal("\x80\x01", output)
76
+ end
77
+
78
+ # Blink Specification 3.1
79
+ def test_putU16_4711unsigned
80
+ input = 4711
81
+ output = "".putU16(input)
82
+ assert_equal("\xa7\x49", output)
83
+ end
84
+
85
+ # Blink Specification 3.1
86
+ def test_putU32_4294967295unsigned
87
+ input = 4294967295
88
+ output = "".putU32(input)
89
+ assert_equal("\xc4\xff\xff\xff\xff", output)
90
+ end
91
+
92
+ # Blink Specification 3.1
93
+ def test_putI8_minus64
94
+ input = -64
95
+ output = "".putI8(input)
96
+ assert_equal("\x40", output)
97
+ end
98
+
99
+ # Blink Specification 3.1
100
+ def test_putI16_minus4711
101
+ input = -4711
102
+ output = "".putI16(input)
103
+ assert_equal("\x99\xb6", output)
104
+ end
105
+
106
+ # Blink Specification 3.1
107
+ def test_putI32_minus2147483648
108
+ input = -2147483648
109
+ output = "".putI32(input)
110
+ assert_equal("\xc4\x00\x00\x00\x80", output)
111
+ end
112
+
113
+ def test_putFixed
114
+ input = "hello world"
115
+ output = "".putFixed(input)
116
+ assert_equal("hello world", output)
117
+ end
118
+
119
+ def test_putFixedOptional
120
+ input = "hello world"
121
+ output = "".putFixedOptional(input)
122
+ assert_equal("\x01hello world", output)
123
+ end
124
+
125
+ def test_putFixedOptional_null
126
+ input = nil
127
+ output = "".putFixedOptional(input)
128
+ assert_equal("\xc0", output)
129
+ end
130
+
131
+ def test_putString
132
+ input = "hello world"
133
+ output = "".putString(input)
134
+ assert_equal("\x0bhello world", output)
135
+ end
136
+
137
+ def test_putString_null
138
+ input = nil
139
+ output = "".putString(input)
140
+ assert_equal("\xc0", output)
141
+ end
142
+
143
+ def test_putBinary
144
+ input = "hello world"
145
+ output = "".putBinary(input)
146
+ assert_equal("\x0bhello world", output)
147
+ end
148
+
149
+ def test_putBinary_null
150
+ input = nil
151
+ output = "".putBinary(input)
152
+ assert_equal("\xc0", output)
153
+ end
154
+
155
+ def test_putBool_true
156
+ input = true
157
+ output = "".putBool(input)
158
+ assert_equal("\x01", output)
159
+ end
160
+
161
+ def test_putBool_false
162
+ input = false
163
+ output = "".putBool(input)
164
+ assert_equal("\x00", output)
165
+ end
166
+
167
+ def test_putBool_null
168
+ input = nil
169
+ output = "".putBool(input)
170
+ assert_equal("\xc0", output)
171
+ end
172
+
173
+ def test_putF64
174
+ input = nil
175
+ output = "".putF64(input)
176
+ assert_equal("\xc0", output)
177
+ end
178
+
179
+ # Blink Specification 3.1
180
+ def test_getU8_64unsigned
181
+ input = "\x40"
182
+ output = input.getU8!
183
+ assert_equal(64, output)
184
+ assert_equal(0, input.size)
185
+ end
186
+
187
+ # Blink Specification 3.1
188
+ def test_getI8_64signed
189
+ input = "\x80\x01"
190
+ output = input.getI8!
191
+ assert_equal(64, output)
192
+ assert_equal(0, input.size)
193
+ end
194
+
195
+ # Blink Specification 3.1
196
+ def test_getU16_4711unsigned
197
+ input = "\xa7\x49"
198
+ output = input.getU16!
199
+ assert_equal(4711, output)
200
+ assert_equal(0, input.size)
201
+ end
202
+
203
+ # Blink Specification 3.1
204
+ def test_getU32_4294967295unsigned
205
+ input = "\xc4\xff\xff\xff\xff"
206
+ output = input.getU32!
207
+ assert_equal(4294967295, output)
208
+ assert_equal(0, input.size)
209
+ end
210
+
211
+ # Blink Specification 3.1
212
+ def test_getI8_minus64
213
+ input = "\x40"
214
+ output = input.getI8!
215
+ assert_equal(-64, output)
216
+ assert_equal(0, input.size)
217
+ end
218
+
219
+ # Blink Specification 3.1
220
+ def test_getI16_minus4711
221
+ input = "\x99\xb6"
222
+ output = input.getI16!
223
+ assert_equal(-4711, output)
224
+ assert_equal(0, input.size)
225
+ end
226
+
227
+ # Blink Specification 3.1
228
+ def test_getI32_minus2147483648
229
+ input = "\xc4\x00\x00\x00\x80"
230
+ output = input.getI32!
231
+ assert_equal(-2147483648, output)
232
+ assert_equal(0, input.size)
233
+ end
234
+
235
+ def test_getBool_true
236
+ input = "\x01"
237
+ output = input.getBool!
238
+ assert_equal(true, output)
239
+ assert_equal(0, input.size)
240
+ end
241
+
242
+ def test_getBool_false
243
+ input = "\x00"
244
+ output = input.getBool!
245
+ assert_equal(false, output)
246
+ assert_equal(0, input.size)
247
+ end
248
+
249
+ def test_getBool_other
250
+ input = "\x02"
251
+ assert_raise do
252
+ input.getBool!
253
+ end
254
+ assert_equal(0, input.size)
255
+ end
256
+
257
+ def test_getString
258
+ input = "\x0bhello world"
259
+ output = input.getString!
260
+ assert_equal("hello world", output)
261
+ assert_equal(0, input.size)
262
+ end
263
+
264
+ def test_getString_null
265
+ input = "\xc0"
266
+ output = input.getString!
267
+ assert_equal(nil, output)
268
+ assert_equal(0, input.size)
269
+ end
270
+
271
+ def test_getString_eof
272
+ input = "\x01"
273
+ assert_raise do
274
+ input.getString!
275
+ end
276
+ end
277
+
278
+ def test_getBinary
279
+ input = "\x0bhello world"
280
+ output = input.getBinary!
281
+ assert_equal("hello world", output)
282
+ assert_equal(0, input.size)
283
+ end
284
+
285
+ def test_getBinary_null
286
+ input = "\xc0"
287
+ output = input.getBinary!
288
+ assert_equal(nil, output)
289
+ assert_equal(0, input.size)
290
+ end
291
+
292
+ def test_getBinary_eof
293
+ input = "\x01"
294
+ assert_raise do
295
+ input.getBinary!
296
+ end
297
+ end
298
+
299
+ def test_getFixed
300
+ input = "hello world"
301
+ output = input.getFixed!("hello world".size)
302
+ assert_equal("hello world", output)
303
+ assert_equal(0, input.size)
304
+ end
305
+
306
+ def test_getFixed_eof
307
+ input = ""
308
+ assert_raise do
309
+ input.getFixed!(1)
310
+ end
311
+ end
312
+
313
+ def test_getFixedOptional
314
+ input = "\x01hello world"
315
+ output = input.getFixedOptional!("hello world".size)
316
+ assert_equal("hello world", output)
317
+ assert_equal(0, input.size)
318
+ end
319
+
320
+ def test_getFixedOptional_null
321
+ input = "\xc0"
322
+ output = input.getFixedOptional!("hello world".size)
323
+ assert_equal(nil, output)
324
+ assert_equal(0, input.size)
325
+ end
326
+
327
+ def test_getFixedOptional_eof
328
+ input = "\x01"
329
+ assert_raise do
330
+ input.getFixedOptional!(1)
331
+ end
332
+ end
333
+
334
+ def test_getU32_13548
335
+ input = "\x01"
336
+ assert_raise do
337
+ input.getFixedOptional!(1)
338
+ end
339
+ end
340
+
341
+ end
data/test/tc_field.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "test/unit"
2
+ require 'slow_blink'
3
+
4
+ class TestField < Test::Unit::TestCase
5
+
6
+ include SlowBlink
7
+
8
+ def test_optional
9
+ input = "Test -> u8 one?"
10
+ schema = Schema.new(SchemaBuffer.new(input))
11
+ assert_equal(true, schema.ns[nil].group("Test").field("one").opt?)
12
+ end
13
+
14
+ def test_not_optional
15
+ input = "Test -> u8 one"
16
+ schema = Schema.new(SchemaBuffer.new(input))
17
+ assert_equal(false, schema.ns[nil].group("Test").field("one").opt?)
18
+ end
19
+
20
+ def test_with_id
21
+ input = "Test -> u8 one/42"
22
+ schema = Schema.new(SchemaBuffer.new(input))
23
+ assert_equal(42, schema.ns[nil].group("Test").field("one").nameWithID.id)
24
+ end
25
+
26
+ def test_with_hexid
27
+ input = "Test -> u8 one/0x2a"
28
+ schema = Schema.new(SchemaBuffer.new(input))
29
+ assert_equal(42, schema.ns[nil].group("Test").field("one").nameWithID.id)
30
+ end
31
+
32
+ def test_without_id
33
+ input = "Test -> u8 one"
34
+ schema = Schema.new(SchemaBuffer.new(input))
35
+ assert_equal(nil, schema.ns[nil].group("Test").field("one").nameWithID.id)
36
+ end
37
+
38
+ def test_reference
39
+ input = "Ref = u8 Test -> Ref one"
40
+ schema = Schema.new(SchemaBuffer.new(input))
41
+ assert_true(schema.ns[nil].group("Test").field("one").type.is_a? REF)
42
+ assert_true(schema.ns[nil].group("Test").field("one").type.ref.is_a? U8)
43
+ end
44
+
45
+ def test_duplicate_name
46
+ input = "Ref = u8 Test -> Ref one, Ref one"
47
+
48
+ assert_raise do
49
+ Schema.new(SchemaBuffer.new(input))
50
+ end
51
+ end
52
+
53
+ end
data/test/tc_group.rb ADDED
@@ -0,0 +1,122 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ require "test/unit"
21
+ require 'slow_blink'
22
+
23
+ class TestGroup < Test::Unit::TestCase
24
+
25
+ include SlowBlink
26
+
27
+ def test_empty_group_without_id
28
+ input = "Test"
29
+ schema = Schema.new(SchemaBuffer.new(input))
30
+ assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
31
+ assert_equal(nil, schema.ns[nil].group("Test").nameWithID.id)
32
+ assert_equal([], schema.ns[nil].group("Test").fields)
33
+ assert_equal({}, schema.tagged)
34
+ end
35
+
36
+ def test_empty_group_with_id
37
+ input = "Test/0"
38
+ schema = Schema.new(SchemaBuffer.new(input))
39
+ assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
40
+ assert_equal(0, schema.ns[nil].group("Test").nameWithID.id)
41
+ assert_equal([], schema.ns[nil].group("Test").fields)
42
+ assert_equal({0 => schema.ns[nil].group("Test")}, schema.tagged)
43
+ end
44
+
45
+ def test_empty_group_with_hexid
46
+ input = "Test/0x2a"
47
+ schema = Schema.new(SchemaBuffer.new(input))
48
+ assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
49
+ assert_equal(42, schema.ns[nil].group("Test").nameWithID.id)
50
+ assert_equal([], schema.ns[nil].group("Test").fields)
51
+ assert_equal({42 => schema.ns[nil].group("Test")}, schema.tagged)
52
+ end
53
+
54
+ def test_group_of_one_field
55
+ input = "Test -> u8 one"
56
+ schema = Schema.new(SchemaBuffer.new(input))
57
+ assert_equal(1, schema.ns[nil].group("Test").fields.size)
58
+ end
59
+
60
+ def test_group_of_many_field
61
+ input = "Test -> u8 one, u8 two, u8 three"
62
+ schema = Schema.new(SchemaBuffer.new(input))
63
+ assert_equal(3, schema.ns[nil].group("Test").fields.size)
64
+ end
65
+
66
+ def test_with_supergroup
67
+ input = "Test : Super Super -> u8 one, u16 two, u32 three"
68
+ schema = Schema.new(SchemaBuffer.new(input))
69
+ assert_equal(3, schema.ns[nil].group("Test").fields.size)
70
+ assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
71
+ assert_true(schema.ns[nil].group("Test").field("one") != nil)
72
+ assert_true(schema.ns[nil].group("Test").field("two") != nil)
73
+ assert_true(schema.ns[nil].group("Test").field("three") != nil)
74
+ end
75
+
76
+ def test_without_supergroup
77
+ input = "Test Super -> u8 one, u16 two, u32 three"
78
+ schema = Schema.new(SchemaBuffer.new(input))
79
+ assert_equal(0, schema.ns[nil].group("Test").fields.size)
80
+ assert_true(!schema.ns[nil].group("Test").group_kind_of?(schema.ns[nil].group("Super")))
81
+ assert_true(schema.ns[nil].group("Test").field("one") == nil)
82
+ assert_true(schema.ns[nil].group("Test").field("two") == nil)
83
+ assert_true(schema.ns[nil].group("Test").field("three") == nil)
84
+ end
85
+
86
+ def test_with_multiple_supergroup
87
+
88
+ input = "Test : Super Super : SuperSuper SuperSuper -> u8 one, u16 two, u32 three"
89
+ schema = Schema.new(SchemaBuffer.new(input))
90
+ assert_equal(3, schema.ns[nil].group("Test").fields.size)
91
+ assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
92
+ assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("SuperSuper"))
93
+ assert_true(schema.ns[nil].group("Test").field("one") != nil)
94
+ assert_true(schema.ns[nil].group("Test").field("two") != nil)
95
+ assert_true(schema.ns[nil].group("Test").field("three") != nil)
96
+ end
97
+
98
+ def test_with_mixed_supergroup
99
+ input = "Test : Super -> u32 three Super -> u8 one, u16 two"
100
+ schema = Schema.new(SchemaBuffer.new(input))
101
+ assert_equal(3, schema.ns[nil].group("Test").fields.size)
102
+ assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
103
+ assert_true(schema.ns[nil].group("Test").field("one") != nil)
104
+ assert_true(schema.ns[nil].group("Test").field("two") != nil)
105
+ assert_true(schema.ns[nil].group("Test").field("three") != nil)
106
+ end
107
+
108
+ def test_supergroup_not_group
109
+ input = "Test : Thing Thing = u8"
110
+ assert_raise do
111
+ Schema.new(SchemaBuffer.new(input))
112
+ end
113
+ end
114
+
115
+ def test_supergroup_unresolved
116
+ input = "Test : Thing"
117
+ assert_raise do
118
+ Schema.new(SchemaBuffer.new(input))
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ require "test/unit"
21
+ require 'slow_blink'
22
+
23
+ class TestIncrAnnote < Test::Unit::TestCase
24
+
25
+ include SlowBlink
26
+
27
+ end
@@ -23,25 +23,21 @@ testClass = Class.new(Test::Unit::TestCase) do
23
23
  output = nil
24
24
 
25
25
  # run and intercept stderr output
26
- #err = capture_stderr do
26
+ err = capture_stderr do
27
27
 
28
- output = SlowBlink::Schema.parse(inputs[__method__][:buffer], filename: inputs[__method__][:fileName])
29
- puts output
30
-
28
+ SlowBlink::Schema.new(SlowBlink::SchemaBuffer.new(inputs[__method__][:buffer], filename: inputs[__method__][:fileName]))
31
29
 
32
- #end
30
+ end
33
31
 
34
32
  # there should have been no messages to stderr
35
- #assert_equal("", err.string, "unexpected error messages")
33
+ assert_equal("", err.string, "unexpected error messages")
36
34
 
37
35
  # if there were messages, forward them to stderr
38
- #if err.string != ""
36
+ if err.string != ""
39
37
 
40
- #STDERR.puts err.string
38
+ STDERR.puts err.string
41
39
 
42
- #end
43
-
44
- #puts output.to_s
40
+ end
45
41
 
46
42
  end
47
43
 
data/test/tc_model.rb ADDED
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ require "test/unit"
21
+ require 'slow_blink'
22
+
23
+ class TestModel < Test::Unit::TestCase
24
+
25
+ include SlowBlink
26
+
27
+ def test_think_blink
28
+ rawSchema = <<-eos
29
+ OrderExecuted/0x4c ->
30
+ string Symbol,
31
+ u64 OrderId,
32
+ u32 Price,
33
+ u32 Qty,
34
+ u8 MatchId
35
+ eos
36
+ schema = Schema.new(SchemaBuffer.new(rawSchema))
37
+ model = Message::Model.new(schema)
38
+ end
39
+
40
+ def test_from_compact
41
+ rawSchema = <<-eos
42
+ OrderExecuted/0x4c ->
43
+ string Symbol,
44
+ u64 OrderId,
45
+ u32 Price,
46
+ u32 Qty,
47
+ u8 MatchId
48
+ eos
49
+ schema = Schema.new(SchemaBuffer.new(rawSchema))
50
+
51
+ input = "\x0b\x4c\x05hello\x00\x01\x02\x03"
52
+ model = Message::Model.new(schema)
53
+
54
+ message = model.decode_compact(input)
55
+
56
+ assert_equal("hello", message["Symbol"])
57
+ assert_equal(0, message["OrderId"])
58
+ assert_equal(1, message["Price"])
59
+ assert_equal(2, message["Qty"])
60
+ assert_equal(3, message["MatchId"])
61
+ end
62
+
63
+
64
+
65
+ end