slow_blink 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_schema_parser/lexer.c +2793 -839
- data/ext/slow_blink/ext_schema_parser/lexer.h +14 -137
- data/ext/slow_blink/ext_schema_parser/parser.c +616 -670
- data/ext/slow_blink/ext_schema_parser/parser.h +6 -4
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +642 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +411 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +46 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +314 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +185 -0
- data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +382 -269
- data/lib/slow_blink/definition.rb +18 -53
- data/lib/slow_blink/dynamic_group.rb +8 -0
- data/lib/slow_blink/enum.rb +101 -0
- data/lib/slow_blink/field.rb +63 -33
- data/lib/slow_blink/generate_c/model.rb +89 -0
- data/lib/slow_blink/group.rb +119 -100
- data/lib/slow_blink/message/binary.rb +3 -4
- data/lib/slow_blink/message/boolean.rb +3 -4
- data/lib/slow_blink/message/date.rb +3 -4
- data/lib/slow_blink/message/decimal.rb +3 -5
- data/lib/slow_blink/message/{enumeration.rb → enum.rb} +17 -17
- data/lib/slow_blink/message/field.rb +77 -27
- data/lib/slow_blink/message/fixed.rb +5 -21
- data/lib/slow_blink/message/floating_point.rb +3 -4
- data/lib/slow_blink/message/group.rb +90 -161
- data/lib/slow_blink/message/integer.rb +24 -32
- data/lib/slow_blink/message/model.rb +50 -110
- data/lib/slow_blink/message/string.rb +3 -4
- data/lib/slow_blink/message/time.rb +5 -5
- data/lib/slow_blink/message/time_of_day.rb +5 -12
- data/lib/slow_blink/ref.rb +22 -71
- data/lib/slow_blink/schema.rb +64 -85
- data/lib/slow_blink/schema_buffer.rb +1 -4
- data/lib/slow_blink/static_group.rb +37 -0
- data/lib/slow_blink/string.rb +4 -5
- data/lib/slow_blink/sym.rb +8 -28
- data/lib/slow_blink/type.rb +10 -19
- data/lib/slow_blink/version.rb +1 -1
- data/lib/slow_blink.rb +1 -0
- data/test/tc_compact_encoder.rb +114 -147
- data/test/tc_inputs.rb +2 -4
- data/test/tc_model_string.rb +29 -0
- data/test/tc_schema_new.rb +212 -0
- metadata +17 -26
- data/ext/slow_blink/ext_schema_parser/common.h +0 -27
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +0 -258
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.h +0 -92
- data/lib/slow_blink/annotatable.rb +0 -48
- data/lib/slow_blink/annotation.rb +0 -47
- data/lib/slow_blink/enumeration.rb +0 -90
- data/lib/slow_blink/incremental_annotation.rb +0 -151
- data/lib/slow_blink/log.rb +0 -51
- data/lib/slow_blink/message/sequence.rb +0 -98
- data/lib/slow_blink/name_with_id.rb +0 -49
- data/lib/slow_blink/namespace.rb +0 -143
- data/lib/slow_blink/sequence.rb +0 -57
- data/test/tc_field.rb +0 -94
- data/test/tc_group.rb +0 -114
- data/test/tc_incr_annote.rb +0 -22
- data/test/tc_namespace.rb +0 -8
- data/test/tc_types.rb +0 -218
data/lib/slow_blink/namespace.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
# @license
|
2
|
-
#
|
3
|
-
# Copyright (c) 2016 Cameron Harper
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
# this software and associated documentation files (the "Software"), to deal in
|
7
|
-
# the Software without restriction, including without limitation the rights to
|
8
|
-
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
# subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
-
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
-
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
|
23
|
-
module SlowBlink
|
24
|
-
|
25
|
-
class Namespace
|
26
|
-
|
27
|
-
include Annotatable
|
28
|
-
|
29
|
-
# @return [Hash<Definition>]
|
30
|
-
attr_reader :definitions
|
31
|
-
|
32
|
-
# @return [Array<Group>]
|
33
|
-
attr_reader :groups
|
34
|
-
|
35
|
-
# @return [String]
|
36
|
-
attr_reader :name
|
37
|
-
|
38
|
-
# @return [Array<IncrementalAnnotation>]
|
39
|
-
attr_reader :incrAnnotations
|
40
|
-
|
41
|
-
# @!method self.parse(input, **opts)
|
42
|
-
#
|
43
|
-
# @api private
|
44
|
-
#
|
45
|
-
# @param input [String] Blink Schema
|
46
|
-
# @param opts [Hash] options
|
47
|
-
# @option opts [String] :fileName filename to append to error message strings
|
48
|
-
# @return [Namespace]
|
49
|
-
|
50
|
-
# @param filename [nil,String]
|
51
|
-
# @param name [nil,String]
|
52
|
-
# @param defs [Array<Definition,Group>]
|
53
|
-
def initialize(filename, name, defs)
|
54
|
-
|
55
|
-
@filename = filename
|
56
|
-
@annotes = {}
|
57
|
-
@incrAnnotations = []
|
58
|
-
@groups = []
|
59
|
-
@definitions = {}
|
60
|
-
@name = name
|
61
|
-
@schema = nil
|
62
|
-
|
63
|
-
error = false
|
64
|
-
|
65
|
-
# populate table of definitions
|
66
|
-
# gather list of groups and incrAnnotations
|
67
|
-
# set namespace reference in each def
|
68
|
-
defs.each do |d|
|
69
|
-
if d.is_a? IncrementalAnnotation
|
70
|
-
@incrAnnotations << d
|
71
|
-
else
|
72
|
-
if @definitions[d.nameWithID.name]
|
73
|
-
Log.error "#{d.location}: error: definitions must have unique names ('#{d.nameWithID.name}' first appears at #{definitions[d.nameWithID.name].location})"
|
74
|
-
error = true
|
75
|
-
else
|
76
|
-
@definitions[d.nameWithID.name] = d
|
77
|
-
if d.is_a? Group
|
78
|
-
@groups << d
|
79
|
-
end
|
80
|
-
d.namespace = self
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
if error
|
86
|
-
raise ParseError
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
# @api private
|
92
|
-
#
|
93
|
-
# @param namespace [Namespace]
|
94
|
-
def merge!(namespace)
|
95
|
-
@incrAnnotations.concat(namespace.incrAnnotations)
|
96
|
-
namespace.definitions.each do |d|
|
97
|
-
if @definitions[d.nameWithID.name]
|
98
|
-
Log.error "#{d.location}: error: definitions must have unique names ('#{d.nameWithID.name}' first appears at #{definitions[d.nameWithID.name].location})"
|
99
|
-
raise ParseError
|
100
|
-
else
|
101
|
-
@definitions[d.nameWithID.name] = d
|
102
|
-
if d.is_a? Group
|
103
|
-
@groups << d
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# @api private
|
110
|
-
#
|
111
|
-
# Resolve references, enforce constraints, and detect cycles
|
112
|
-
#
|
113
|
-
# @param schema [Schema] schema this definition belongs to
|
114
|
-
# @param stack [nil, Array] objects that depend on this object
|
115
|
-
# @return [true,false] linked?
|
116
|
-
def link(schema, stack=[])
|
117
|
-
errors = 0
|
118
|
-
@definitions.each do |name, d|
|
119
|
-
if !d.link(schema, stack.dup << self)
|
120
|
-
errors += 1
|
121
|
-
end
|
122
|
-
end
|
123
|
-
errors == 0
|
124
|
-
end
|
125
|
-
|
126
|
-
# @param name [String] unqualified name
|
127
|
-
# @return [Definition,Group]
|
128
|
-
def resolve(name)
|
129
|
-
@definitions[name]
|
130
|
-
end
|
131
|
-
|
132
|
-
# @param name [String]
|
133
|
-
# @return [Group,nil]
|
134
|
-
def group(name)
|
135
|
-
@groups.detect{|g|g.nameWithID.name == name}
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
|
data/lib/slow_blink/sequence.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# @license
|
2
|
-
#
|
3
|
-
# Copyright (c) 2016 Cameron Harper
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
# this software and associated documentation files (the "Software"), to deal in
|
7
|
-
# the Software without restriction, including without limitation the rights to
|
8
|
-
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
# subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
-
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
-
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
|
23
|
-
module SlowBlink
|
24
|
-
|
25
|
-
# Blink Specification 3.12
|
26
|
-
class SEQUENCE < Type
|
27
|
-
|
28
|
-
# @return [Type]
|
29
|
-
attr_reader :type
|
30
|
-
|
31
|
-
# @param type [Type] repeating type
|
32
|
-
# @param location [String]
|
33
|
-
def initialize(type, location)
|
34
|
-
@type = type
|
35
|
-
super(location)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @api private
|
39
|
-
#
|
40
|
-
# Resolve references, enforce constraints, and detect cycles
|
41
|
-
#
|
42
|
-
# @param schema [Schema] schema this definition belongs to
|
43
|
-
# @param ns [Namespace] namespace this definition belongs to
|
44
|
-
# @param stack [nil, Array] objects that depend on this object
|
45
|
-
# @return [true,false] linked?
|
46
|
-
def link(schema, ns, stack=[])
|
47
|
-
if stack.detect{|sf| sf.is_a? SEQUENCE}
|
48
|
-
Log.error "#{@location}: error: a sequence type specifier must not specify a sequence as the item type"
|
49
|
-
false
|
50
|
-
else
|
51
|
-
@type.link(schema, ns, stack << self)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
data/test/tc_field.rb
DELETED
@@ -1,94 +0,0 @@
|
|
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
|
-
def test_field_direct_cycle
|
54
|
-
input = <<-eos
|
55
|
-
test ->
|
56
|
-
test field
|
57
|
-
eos
|
58
|
-
assert_raise do
|
59
|
-
Schema.new(SchemaBuffer.new(input))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_field_direct_dynamic_cycle
|
64
|
-
input = <<-eos
|
65
|
-
test ->
|
66
|
-
test * field
|
67
|
-
eos
|
68
|
-
|
69
|
-
Schema.new(SchemaBuffer.new(input))
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_field_indirect_cycle
|
74
|
-
input = <<-eos
|
75
|
-
intermediate = test
|
76
|
-
test ->
|
77
|
-
intermediate field
|
78
|
-
eos
|
79
|
-
assert_raise do
|
80
|
-
Schema.new(SchemaBuffer.new(input))
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_field_indirect_dynamic_cycle
|
85
|
-
input = <<-eos
|
86
|
-
intermediate = test *
|
87
|
-
test ->
|
88
|
-
intermediate field
|
89
|
-
eos
|
90
|
-
|
91
|
-
Schema.new(SchemaBuffer.new(input))
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
data/test/tc_group.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require 'slow_blink'
|
3
|
-
|
4
|
-
class TestGroup < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include SlowBlink
|
7
|
-
|
8
|
-
def test_empty_group_without_id
|
9
|
-
input = "Test"
|
10
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
11
|
-
assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
|
12
|
-
assert_equal(nil, schema.ns[nil].group("Test").nameWithID.id)
|
13
|
-
assert_equal([], schema.ns[nil].group("Test").fields)
|
14
|
-
assert_equal({}, schema.tagged)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_empty_group_with_id
|
18
|
-
input = "Test/0"
|
19
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
20
|
-
assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
|
21
|
-
assert_equal(0, schema.ns[nil].group("Test").nameWithID.id)
|
22
|
-
assert_equal([], schema.ns[nil].group("Test").fields)
|
23
|
-
assert_equal({0 => schema.ns[nil].group("Test")}, schema.tagged)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_empty_group_with_hexid
|
27
|
-
input = "Test/0x2a"
|
28
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
29
|
-
assert_equal("Test", schema.ns[nil].group("Test").nameWithID.name)
|
30
|
-
assert_equal(42, schema.ns[nil].group("Test").nameWithID.id)
|
31
|
-
assert_equal([], schema.ns[nil].group("Test").fields)
|
32
|
-
assert_equal({42 => schema.ns[nil].group("Test")}, schema.tagged)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_group_of_one_field
|
36
|
-
input = "Test -> u8 one"
|
37
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
38
|
-
assert_equal(1, schema.ns[nil].group("Test").fields.size)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_group_of_many_field
|
42
|
-
input = "Test -> u8 one, u8 two, u8 three"
|
43
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
44
|
-
assert_equal(3, schema.ns[nil].group("Test").fields.size)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_with_supergroup
|
48
|
-
input = "Test : Super Super -> u8 one, u16 two, u32 three"
|
49
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
50
|
-
assert_equal(3, schema.ns[nil].group("Test").fields.size)
|
51
|
-
assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
|
52
|
-
assert_true(schema.ns[nil].group("Test").field("one") != nil)
|
53
|
-
assert_true(schema.ns[nil].group("Test").field("two") != nil)
|
54
|
-
assert_true(schema.ns[nil].group("Test").field("three") != nil)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_without_supergroup
|
58
|
-
input = "Test Super -> u8 one, u16 two, u32 three"
|
59
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
60
|
-
assert_equal(0, schema.ns[nil].group("Test").fields.size)
|
61
|
-
assert_true(!schema.ns[nil].group("Test").group_kind_of?(schema.ns[nil].group("Super")))
|
62
|
-
assert_true(schema.ns[nil].group("Test").field("one") == nil)
|
63
|
-
assert_true(schema.ns[nil].group("Test").field("two") == nil)
|
64
|
-
assert_true(schema.ns[nil].group("Test").field("three") == nil)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_with_multiple_supergroup
|
68
|
-
|
69
|
-
input = "Test : Super Super : SuperSuper SuperSuper -> u8 one, u16 two, u32 three"
|
70
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
71
|
-
assert_equal(3, schema.ns[nil].group("Test").fields.size)
|
72
|
-
assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
|
73
|
-
assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("SuperSuper"))
|
74
|
-
assert_true(schema.ns[nil].group("Test").field("one") != nil)
|
75
|
-
assert_true(schema.ns[nil].group("Test").field("two") != nil)
|
76
|
-
assert_true(schema.ns[nil].group("Test").field("three") != nil)
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_with_mixed_supergroup
|
80
|
-
input = "Test : Super -> u32 three Super -> u8 one, u16 two"
|
81
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
82
|
-
assert_equal(3, schema.ns[nil].group("Test").fields.size)
|
83
|
-
assert_true(schema.ns[nil].group("Test").group_kind_of? schema.ns[nil].group("Super"))
|
84
|
-
assert_true(schema.ns[nil].group("Test").field("one") != nil)
|
85
|
-
assert_true(schema.ns[nil].group("Test").field("two") != nil)
|
86
|
-
assert_true(schema.ns[nil].group("Test").field("three") != nil)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_supergroup_not_group
|
90
|
-
input = "Test : Thing Thing = u8"
|
91
|
-
assert_raise do
|
92
|
-
Schema.new(SchemaBuffer.new(input))
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_supergroup_unresolved
|
97
|
-
input = "Test : Thing"
|
98
|
-
assert_raise do
|
99
|
-
Schema.new(SchemaBuffer.new(input))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_supergroup_dynamic_reference
|
104
|
-
input = <<-eos
|
105
|
-
Super
|
106
|
-
Intermediate = Super *
|
107
|
-
Test : Intermediate
|
108
|
-
eos
|
109
|
-
assert_raise do
|
110
|
-
Schema.new(SchemaBuffer.new(input))
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
data/test/tc_incr_annote.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require 'slow_blink'
|
3
|
-
|
4
|
-
class TestIncrAnnote < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include SlowBlink
|
7
|
-
|
8
|
-
def test_schema
|
9
|
-
|
10
|
-
raw = <<-eos
|
11
|
-
Thing
|
12
|
-
AnotherThing ->
|
13
|
-
string Greeting
|
14
|
-
|
15
|
-
schema <- @test="test"
|
16
|
-
eos
|
17
|
-
|
18
|
-
schema = Schema.new(SchemaBuffer.new(raw))
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/test/tc_namespace.rb
DELETED
data/test/tc_types.rb
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require 'slow_blink'
|
3
|
-
|
4
|
-
class TestTypes < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include SlowBlink
|
7
|
-
|
8
|
-
def test_bool
|
9
|
-
input = "test -> bool test"
|
10
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
11
|
-
assert_equal(BOOLEAN, schema.ns[nil].group("test").field("test").type.class)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_u8
|
15
|
-
input = "test -> u8 test"
|
16
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
17
|
-
assert_equal(U8, schema.ns[nil].group("test").field("test").type.class)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_u16
|
21
|
-
input = "test -> u16 test"
|
22
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
23
|
-
assert_equal(U16, schema.ns[nil].group("test").field("test").type.class)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_u32
|
27
|
-
input = "test -> u32 test"
|
28
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
29
|
-
assert_equal(U32, schema.ns[nil].group("test").field("test").type.class)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_u64
|
33
|
-
input = "test -> u64 test"
|
34
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
35
|
-
assert_equal(U64, schema.ns[nil].group("test").field("test").type.class)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_i8
|
39
|
-
input = "test -> i8 test"
|
40
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
41
|
-
assert_equal(I8, schema.ns[nil].group("test").field("test").type.class)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_i16
|
45
|
-
input = "test -> i16 test"
|
46
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
47
|
-
assert_equal(I16, schema.ns[nil].group("test").field("test").type.class)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_i32
|
51
|
-
input = "test -> i32 test"
|
52
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
53
|
-
assert_equal(I32, schema.ns[nil].group("test").field("test").type.class)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_i64
|
57
|
-
input = "test -> i64 test"
|
58
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
59
|
-
assert_equal(I64, schema.ns[nil].group("test").field("test").type.class)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_f64
|
63
|
-
input = "test -> f64 test"
|
64
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
65
|
-
assert_equal(FLOATING_POINT, schema.ns[nil].group("test").field("test").type.class)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_string_without_size
|
69
|
-
input = "test -> string test"
|
70
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
71
|
-
assert_equal(STRING, schema.ns[nil].group("test").field("test").type.class)
|
72
|
-
assert_equal(nil, schema.ns[nil].group("test").field("test").type.size)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_string_with_size
|
76
|
-
input = "test -> string (42) test"
|
77
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
78
|
-
assert_equal(STRING, schema.ns[nil].group("test").field("test").type.class)
|
79
|
-
assert_equal(42, schema.ns[nil].group("test").field("test").type.size)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_binary_without_size
|
83
|
-
input = "test -> binary test"
|
84
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
85
|
-
assert_equal(BINARY, schema.ns[nil].group("test").field("test").type.class)
|
86
|
-
assert_equal(nil, schema.ns[nil].group("test").field("test").type.size)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_binary_with_size
|
90
|
-
input = "test -> binary (42) test "
|
91
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
92
|
-
assert_equal(BINARY, schema.ns[nil].group("test").field("test").type.class)
|
93
|
-
assert_equal(42, schema.ns[nil].group("test").field("test").type.size)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_fixed
|
97
|
-
input = "test -> fixed (42) test "
|
98
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
99
|
-
assert_equal(FIXED, schema.ns[nil].group("test").field("test").type.class)
|
100
|
-
assert_equal(42, schema.ns[nil].group("test").field("test").type.size)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_enum
|
104
|
-
input = "colour = | blue"
|
105
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_enum_many
|
109
|
-
input = "colour = blue | white | red/5"
|
110
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_ref_enum
|
114
|
-
input = "colour = | blue test -> colour test"
|
115
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
116
|
-
assert_equal(REF, schema.ns[nil].group("test").field("test").type.class)
|
117
|
-
assert_equal(ENUMERATION, schema.ns[nil].group("test").field("test").type.ref.class)
|
118
|
-
assert_equal("blue", schema.ns[nil].group("test").field("test").type.ref.symbol("blue").name)
|
119
|
-
assert_equal(0, schema.ns[nil].group("test").field("test").type.ref.symbol("blue").val)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_ref_enum_many
|
123
|
-
input = "colour = blue | white | red/5 | orange test -> colour test"
|
124
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
125
|
-
assert_equal(REF, schema.ns[nil].group("test").field("test").type.class)
|
126
|
-
assert_equal(ENUMERATION, schema.ns[nil].group("test").field("test").type.ref.class)
|
127
|
-
assert_equal("blue", schema.ns[nil].group("test").field("test").type.ref.symbol("blue").name)
|
128
|
-
assert_equal(0, schema.ns[nil].group("test").field("test").type.ref.symbol("blue").val)
|
129
|
-
assert_equal("white", schema.ns[nil].group("test").field("test").type.ref.symbol("white").name)
|
130
|
-
assert_equal(1, schema.ns[nil].group("test").field("test").type.ref.symbol("white").val)
|
131
|
-
assert_equal("red", schema.ns[nil].group("test").field("test").type.ref.symbol("red").name)
|
132
|
-
assert_equal(5, schema.ns[nil].group("test").field("test").type.ref.symbol("red").val)
|
133
|
-
assert_equal("orange", schema.ns[nil].group("test").field("test").type.ref.symbol("orange").name)
|
134
|
-
assert_equal(6, schema.ns[nil].group("test").field("test").type.ref.symbol("orange").val)
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_static_group
|
138
|
-
input = "static -> u8 one, u16 two test -> static one, string two"
|
139
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
140
|
-
assert_equal("one", schema.ns[nil].group("test").field("one").nameWithID.name)
|
141
|
-
assert_equal(REF, schema.ns[nil].group("test").field("one").type.class)
|
142
|
-
assert_equal(false, schema.ns[nil].group("test").field("one").type.dynamic?)
|
143
|
-
assert_equal("two", schema.ns[nil].group("test").field("two").nameWithID.name)
|
144
|
-
assert_equal(STRING, schema.ns[nil].group("test").field("two").type.class)
|
145
|
-
assert_equal("one", schema.ns[nil].group("test").field("one").type.ref.field("one").nameWithID.name)
|
146
|
-
assert_equal(U8, schema.ns[nil].group("test").field("one").type.ref.field("one").type.class)
|
147
|
-
assert_equal("two", schema.ns[nil].group("test").field("one").type.ref.field("two").nameWithID.name)
|
148
|
-
assert_equal(U16, schema.ns[nil].group("test").field("one").type.ref.field("two").type.class)
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_dynamic_group
|
152
|
-
input = "dynamic -> u8 one, u16 two test -> dynamic * one, string two"
|
153
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
154
|
-
assert_equal("one", schema.ns[nil].group("test").field("one").nameWithID.name)
|
155
|
-
assert_equal(REF, schema.ns[nil].group("test").field("one").type.class)
|
156
|
-
assert_equal(true, schema.ns[nil].group("test").field("one").type.dynamic?)
|
157
|
-
assert_equal("two", schema.ns[nil].group("test").field("two").nameWithID.name)
|
158
|
-
assert_equal(STRING, schema.ns[nil].group("test").field("two").type.class)
|
159
|
-
assert_equal("one", schema.ns[nil].group("test").field("one").type.ref.field("one").nameWithID.name)
|
160
|
-
assert_equal(U8, schema.ns[nil].group("test").field("one").type.ref.field("one").type.class)
|
161
|
-
assert_equal("two", schema.ns[nil].group("test").field("one").type.ref.field("two").nameWithID.name)
|
162
|
-
assert_equal(U16, schema.ns[nil].group("test").field("one").type.ref.field("two").type.class)
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_dynamic_not_group
|
166
|
-
input = "thing = u8 one test -> thing * one, string two"
|
167
|
-
assert_raise do
|
168
|
-
Schema.new(SchemaBuffer.new(input))
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_any_group
|
173
|
-
input = "dynamic -> u8 one, u16 two test -> object one, string two"
|
174
|
-
schema = Schema.new(SchemaBuffer.new(input))
|
175
|
-
assert_equal("one", schema.ns[nil].group("test").field("one").nameWithID.name)
|
176
|
-
assert_equal(OBJECT, schema.ns[nil].group("test").field("one").type.class)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_type_direct_reference_cycle
|
180
|
-
input = <<-eos
|
181
|
-
thing = thingref
|
182
|
-
thingref = thing
|
183
|
-
eos
|
184
|
-
assert_raise do
|
185
|
-
Schema.new(SchemaBuffer.new(input))
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_type_inderect_reference_cycle
|
190
|
-
input = <<-eos
|
191
|
-
thing = intermediate
|
192
|
-
intermediate = thingref
|
193
|
-
thingref = thing
|
194
|
-
eos
|
195
|
-
assert_raise do
|
196
|
-
Schema.new(SchemaBuffer.new(input))
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_sequence_sequence
|
201
|
-
input = "test -> i32 [] test"
|
202
|
-
Schema.new(SchemaBuffer.new(input))
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_sequence_sequence_direct
|
206
|
-
input = <<-eos
|
207
|
-
intermediate = u32 []
|
208
|
-
test ->
|
209
|
-
intermediate [] test
|
210
|
-
eos
|
211
|
-
|
212
|
-
assert_raise do
|
213
|
-
Schema.new(SchemaBuffer.new(input))
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|