rley 0.8.14 → 0.8.15
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/.rubocop.yml +20 -2
- data/CHANGELOG.md +3 -0
- data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
- data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
- data/examples/general/recursive_right.rb +2 -2
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/gfg/grm_flow_graph.rb +0 -1
- data/lib/rley/parser/parse_entry_set.rb +0 -1
- data/lib/rley/parser/parse_walker_factory.rb +0 -1
- data/lib/rley/rgn/grammar_builder.rb +0 -2
- data/lib/rley/rgn/tokenizer.rb +1 -1
- data/lib/rley/syntax/base_grammar_builder.rb +0 -1
- data/lib/rley/syntax/grammar.rb +0 -1
- data/spec/rley/base/dotted_item_spec.rb +46 -46
- data/spec/rley/base/grm_items_builder_spec.rb +1 -1
- data/spec/rley/engine_spec.rb +50 -50
- data/spec/rley/formatter/asciitree_spec.rb +8 -8
- data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
- data/spec/rley/formatter/debug_spec.rb +10 -10
- data/spec/rley/formatter/json_spec.rb +6 -7
- data/spec/rley/gfg/call_edge_spec.rb +6 -6
- data/spec/rley/gfg/edge_spec.rb +8 -7
- data/spec/rley/gfg/end_vertex_spec.rb +8 -7
- data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
- data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
- data/spec/rley/gfg/item_vertex_spec.rb +34 -36
- data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
- data/spec/rley/gfg/return_edge_spec.rb +6 -6
- data/spec/rley/gfg/scan_edge_spec.rb +7 -6
- data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
- data/spec/rley/gfg/start_vertex_spec.rb +8 -8
- data/spec/rley/gfg/vertex_spec.rb +18 -18
- data/spec/rley/lexical/literal_spec.rb +5 -5
- data/spec/rley/lexical/token_range_spec.rb +55 -55
- data/spec/rley/lexical/token_spec.rb +17 -16
- data/spec/rley/parse_forest_visitor_spec.rb +30 -32
- data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
- data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
- data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
- data/spec/rley/parse_rep/groucho_spec.rb +23 -23
- data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
- data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
- data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
- data/spec/rley/parse_tree_visitor_spec.rb +43 -46
- data/spec/rley/parser/dangling_else_spec.rb +12 -12
- data/spec/rley/parser/error_reason_spec.rb +37 -37
- data/spec/rley/parser/gfg_chart_spec.rb +27 -29
- data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
- data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
- data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
- data/spec/rley/parser/parse_entry_spec.rb +73 -71
- data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
- data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
- data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
- data/spec/rley/ptree/parse_tree_spec.rb +6 -8
- data/spec/rley/ptree/terminal_node_spec.rb +6 -6
- data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
- data/spec/rley/rgn/parser_spec.rb +63 -63
- data/spec/rley/rgn/repetition_node_spec.rb +15 -15
- data/spec/rley/rgn/sequence_node_spec.rb +10 -10
- data/spec/rley/rgn/symbol_node_spec.rb +5 -6
- data/spec/rley/rgn/tokenizer_spec.rb +68 -67
- data/spec/rley/sppf/alternative_node_spec.rb +16 -16
- data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
- data/spec/rley/sppf/token_node_spec.rb +13 -13
- data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
- data/spec/rley/syntax/grammar_spec.rb +40 -78
- data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
- data/spec/rley/syntax/match_closest_spec.rb +8 -8
- data/spec/rley/syntax/non_terminal_spec.rb +25 -25
- data/spec/rley/syntax/production_spec.rb +33 -33
- data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
- data/spec/rley/syntax/terminal_spec.rb +12 -11
- data/spec/support/base_tokenizer_spec.rb +9 -8
- metadata +2 -2
@@ -18,6 +18,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
18
18
|
def build_prod(theLHS, *theRHSSymbols)
|
19
19
|
return Syntax::Production.new(theLHS, theRHSSymbols)
|
20
20
|
end
|
21
|
+
subject(:a_vertex) { described_class.new(sample_item) }
|
21
22
|
|
22
23
|
let(:t_a) { Rley::Syntax::Terminal.new('a') }
|
23
24
|
let(:t_b) { Rley::Syntax::Terminal.new('b') }
|
@@ -31,101 +32,98 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
31
32
|
let(:empty_prod) { build_prod(nt_sentence) }
|
32
33
|
let(:sample_item) { Base::DottedItem.new(sample_prod, 1) }
|
33
34
|
let(:next_item) { Base::DottedItem.new(sample_prod, 2) }
|
34
|
-
subject { ItemVertex.new(sample_item) }
|
35
35
|
|
36
36
|
context 'Initialization:' do
|
37
|
-
it '
|
38
|
-
expect {
|
37
|
+
it 'is created with a dotted item' do
|
38
|
+
expect { described_class.new(sample_item) }.not_to raise_error
|
39
39
|
end
|
40
40
|
|
41
|
-
it '
|
42
|
-
expect(
|
41
|
+
it 'knows its dotted item' do
|
42
|
+
expect(a_vertex.dotted_item).to eq(sample_item)
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
46
|
-
expect(
|
45
|
+
it 'does not have any shortcut edge at start' do
|
46
|
+
expect(a_vertex.shortcut).to be_nil
|
47
47
|
end
|
48
48
|
end # context
|
49
49
|
|
50
50
|
context 'Provided services:' do
|
51
|
-
it '
|
52
|
-
expect(
|
51
|
+
it 'knows its label' do
|
52
|
+
expect(a_vertex.label).to eq(sample_item.to_s)
|
53
53
|
end
|
54
54
|
|
55
|
-
it '
|
56
|
-
expect(
|
55
|
+
it 'knows the lhs of the production' do
|
56
|
+
expect(a_vertex.lhs).to eq(nt_sentence)
|
57
57
|
end
|
58
58
|
|
59
|
-
it '
|
59
|
+
it 'knows whether it has a dot at the end of the rhs' do
|
60
60
|
# Case: dot not at the end
|
61
|
-
expect(
|
61
|
+
expect(a_vertex).not_to be_complete
|
62
62
|
|
63
63
|
# Case: dot at the end
|
64
|
-
instance1 =
|
64
|
+
instance1 = described_class.new(Base::DottedItem.new(sample_prod, 3))
|
65
65
|
expect(instance1).to be_complete
|
66
66
|
|
67
67
|
# Case: empty production
|
68
|
-
instance2 =
|
68
|
+
instance2 = described_class.new(Base::DottedItem.new(empty_prod, 0))
|
69
69
|
expect(instance2).to be_complete
|
70
70
|
end
|
71
71
|
|
72
|
-
it '
|
72
|
+
it 'knows the previous symbol (if any) in the rhs (i)' do
|
73
73
|
# Case: dot is after first symbol
|
74
|
-
instance1 =
|
74
|
+
instance1 = described_class.new(sample_item)
|
75
75
|
expect(instance1.prev_symbol).to eq(t_a)
|
76
76
|
|
77
77
|
# Case: dot is after second or later symbol
|
78
|
-
instance2 =
|
78
|
+
instance2 = described_class.new(next_item)
|
79
79
|
expect(instance2.prev_symbol).to eq(nt_b_sequence)
|
80
80
|
|
81
81
|
# Case: dot is at begin
|
82
|
-
instance3 =
|
82
|
+
instance3 = described_class.new(Base::DottedItem.new(sample_prod, 0))
|
83
83
|
expect(instance3.prev_symbol).to be_nil
|
84
84
|
|
85
85
|
# Case: empty production
|
86
|
-
instance4 =
|
86
|
+
instance4 = described_class.new(Base::DottedItem.new(empty_prod, 0))
|
87
87
|
expect(instance4.prev_symbol).to be_nil
|
88
88
|
end
|
89
89
|
|
90
90
|
|
91
|
-
it '
|
91
|
+
it 'knows the next symbol (if any) in the rhs (ii)' do
|
92
92
|
# Case: dot is not penultimate
|
93
|
-
expect(
|
93
|
+
expect(a_vertex.next_symbol).to eq(nt_b_sequence)
|
94
94
|
|
95
95
|
# Case: dot is penultimate
|
96
|
-
instance1 =
|
96
|
+
instance1 = described_class.new(next_item)
|
97
97
|
expect(instance1.next_symbol).to eq(t_c)
|
98
98
|
|
99
99
|
# Case: dot is at end
|
100
|
-
instance2 =
|
100
|
+
instance2 = described_class.new(Base::DottedItem.new(sample_prod, 3))
|
101
101
|
expect(instance2.next_symbol).to be_nil
|
102
102
|
|
103
103
|
# Case: empty production
|
104
|
-
instance3 =
|
104
|
+
instance3 = described_class.new(Base::DottedItem.new(empty_prod, 0))
|
105
105
|
expect(instance3.next_symbol).to be_nil
|
106
106
|
end
|
107
107
|
|
108
|
-
it '
|
109
|
-
next_vertex =
|
108
|
+
it 'accepts a shortcut edge' do
|
109
|
+
next_vertex = described_class.new(next_item)
|
110
110
|
|
111
111
|
# The ShortcutEdge constructor invokes the shortcut setter
|
112
|
-
shortcut = ShortcutEdge.new(
|
113
|
-
expect(
|
112
|
+
shortcut = ShortcutEdge.new(a_vertex, next_vertex)
|
113
|
+
expect(a_vertex.shortcut).to eq(shortcut)
|
114
114
|
end
|
115
115
|
|
116
|
-
it '
|
116
|
+
it 'rejects an invalid shortcut edge' do
|
117
117
|
err = StandardError
|
118
118
|
err_msg = 'Invalid shortcut argument'
|
119
|
-
expect {
|
119
|
+
expect { a_vertex.shortcut = 'invalid' }.to raise_error(err, err_msg)
|
120
120
|
end
|
121
|
-
end # context
|
122
121
|
|
123
|
-
|
124
|
-
it 'should provide human-readable representation of itself' do
|
122
|
+
it 'provides human-readable representation of itself' do
|
125
123
|
prefix = /^#<Rley::GFG::ItemVertex:\d+/
|
126
|
-
expect(
|
124
|
+
expect(a_vertex.inspect).to match(prefix)
|
127
125
|
suffix = /label="sentence => a \. b_sequence c">$/
|
128
|
-
expect(
|
126
|
+
expect(a_vertex.inspect).to match(suffix)
|
129
127
|
end
|
130
128
|
end # context
|
131
129
|
end # describe
|
@@ -8,30 +8,30 @@ require_relative '../../../lib/rley/gfg/non_terminal_vertex'
|
|
8
8
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
9
9
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
10
10
|
describe NonTerminalVertex do
|
11
|
+
subject(:a_vertex) { described_class.new(sample_nt) }
|
11
12
|
let(:sample_nt) { double('fake-non-terminal') }
|
12
|
-
subject { NonTerminalVertex.new(sample_nt) }
|
13
13
|
|
14
14
|
context 'Initialization:' do
|
15
|
-
it '
|
16
|
-
expect {
|
15
|
+
it 'is created with a non-terminal symbol' do
|
16
|
+
expect { described_class.new(sample_nt) }.not_to raise_error
|
17
17
|
end
|
18
18
|
|
19
|
-
it '
|
20
|
-
expect(
|
19
|
+
it 'knows its non-terminal' do
|
20
|
+
expect(a_vertex.non_terminal).to eq(sample_nt)
|
21
21
|
end
|
22
22
|
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'accepts at more than one outgoing edge' do
|
25
25
|
edge1 = double('fake-edge1')
|
26
26
|
edge2 = double('fake-edge2')
|
27
27
|
|
28
|
-
expect {
|
29
|
-
expect(
|
30
|
-
expect(
|
28
|
+
expect { a_vertex.add_edge(edge1) }.not_to raise_error
|
29
|
+
expect(a_vertex.edges.size).to eq(1)
|
30
|
+
expect(a_vertex.edges.last).to eq(edge1)
|
31
31
|
|
32
|
-
expect {
|
33
|
-
expect(
|
34
|
-
expect(
|
32
|
+
expect { a_vertex.add_edge(edge2) }.not_to raise_error
|
33
|
+
expect(a_vertex.edges.size).to eq(2)
|
34
|
+
expect(a_vertex.edges.last).to eq(edge2)
|
35
35
|
end
|
36
36
|
end # context
|
37
37
|
end # describe
|
@@ -21,6 +21,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
21
21
|
return Syntax::Production.new(theLHS, theRHSSymbols)
|
22
22
|
end
|
23
23
|
|
24
|
+
subject(:an_edge) { described_class.new(vertex1, vertex2) }
|
25
|
+
|
24
26
|
let(:t_a) { Rley::Syntax::Terminal.new('a') }
|
25
27
|
let(:t_b) { Rley::Syntax::Terminal.new('b') }
|
26
28
|
let(:t_c) { Rley::Syntax::Terminal.new('c') }
|
@@ -28,22 +30,20 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
28
30
|
let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
|
29
31
|
let(:sample_prod) { build_prod(nt_sentence, t_a, nt_b_sequence, t_c) }
|
30
32
|
let(:sample_item) { Base::DottedItem.new(sample_prod, 1) }
|
31
|
-
|
32
33
|
let(:vertex1) { EndVertex.new('from') }
|
33
34
|
let(:vertex2) { ItemVertex.new(sample_item) }
|
34
|
-
subject { ReturnEdge.new(vertex1, vertex2) }
|
35
35
|
|
36
36
|
context 'Initialization:' do
|
37
|
-
it '
|
38
|
-
expect {
|
37
|
+
it 'is created with two vertice arguments' do
|
38
|
+
expect { described_class.new(vertex1, vertex2) }.not_to raise_error
|
39
39
|
end
|
40
40
|
end # context
|
41
41
|
|
42
42
|
context 'Provided services:' do
|
43
|
-
it '
|
43
|
+
it 'knows its key' do
|
44
44
|
pos = sample_item.position
|
45
45
|
expectation = "RET_#{sample_prod.object_id}_#{pos - 1}"
|
46
|
-
expect(
|
46
|
+
expect(an_edge.key).to eq(expectation)
|
47
47
|
end
|
48
48
|
end # context
|
49
49
|
end # describe
|
@@ -10,21 +10,22 @@ require_relative '../../../lib/rley/gfg/scan_edge'
|
|
10
10
|
|
11
11
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
12
12
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
13
|
-
describe
|
13
|
+
describe ScanEdge do
|
14
|
+
subject(:an_edge) { described_class.new(vertex1, vertex2, sample_terminal) }
|
15
|
+
|
14
16
|
let(:vertex1) { StartVertex.new('from') }
|
15
17
|
let(:vertex2) { StartVertex.new('to') }
|
16
18
|
let(:sample_terminal) { double('fake-terminal') }
|
17
|
-
subject { ScanEdge.new(vertex1, vertex2, sample_terminal) }
|
18
19
|
|
19
20
|
context 'Initialization:' do
|
20
|
-
it '
|
21
|
+
it 'is created with two vertice arguments & a terminal' do
|
21
22
|
v1 = vertex1
|
22
23
|
v2 = vertex2
|
23
|
-
expect {
|
24
|
+
expect { described_class.new(v1, v2, sample_terminal) }.not_to raise_error
|
24
25
|
end
|
25
26
|
|
26
|
-
it '
|
27
|
-
expect(
|
27
|
+
it 'knows the related terminal' do
|
28
|
+
expect(an_edge.terminal).to eq(sample_terminal)
|
28
29
|
end
|
29
30
|
end # context
|
30
31
|
end # describe
|
@@ -8,34 +8,34 @@ require_relative '../../../lib/rley/gfg/shortcut_edge'
|
|
8
8
|
|
9
9
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
10
10
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
11
|
-
describe
|
12
|
-
|
11
|
+
describe ShortcutEdge do
|
12
|
+
subject(:an_edge) { described_class.new(vertex1, vertex2) }
|
13
13
|
|
14
|
+
let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
|
14
15
|
let(:vertex1) { double('fake_vertex1') }
|
15
16
|
let(:vertex2) { double('fake_vertex2') }
|
16
|
-
subject { ShortcutEdge.new(vertex1, vertex2) }
|
17
17
|
|
18
18
|
context 'Initialization:' do
|
19
|
-
it '
|
20
|
-
|
21
|
-
|
19
|
+
it 'is created with two vertice arguments & a non-terminal' do
|
20
|
+
allow(vertex1).to receive(:shortcut=)
|
21
|
+
allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
|
22
22
|
|
23
|
-
expect {
|
23
|
+
expect { described_class.new(vertex1, vertex2) }
|
24
24
|
.not_to raise_error
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
28
|
-
|
29
|
-
|
27
|
+
it 'knows the successor vertex' do
|
28
|
+
allow(vertex1).to receive(:shortcut=)
|
29
|
+
allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
|
30
30
|
|
31
|
-
expect(
|
31
|
+
expect(an_edge.successor).to eq(vertex2)
|
32
32
|
end
|
33
33
|
|
34
|
-
it '
|
35
|
-
|
36
|
-
|
34
|
+
it 'knows the related terminal' do
|
35
|
+
allow(vertex1).to receive(:shortcut=)
|
36
|
+
allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
|
37
37
|
|
38
|
-
expect(
|
38
|
+
expect(an_edge.nonterminal).to eq(nt_b_sequence)
|
39
39
|
end
|
40
40
|
end # context
|
41
41
|
end # describe
|
@@ -9,24 +9,24 @@ require_relative '../../../lib/rley/gfg/start_vertex'
|
|
9
9
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
10
10
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
11
11
|
describe StartVertex do
|
12
|
+
subject(:a_vertex) { described_class.new(sample_nt) }
|
12
13
|
let(:sample_nt) { Syntax::NonTerminal.new('NT') }
|
13
|
-
subject { StartVertex.new(sample_nt) }
|
14
14
|
|
15
15
|
context 'Initialization:' do
|
16
|
-
it '
|
17
|
-
expect {
|
16
|
+
it 'is created with a non-terminal symbol' do
|
17
|
+
expect { described_class.new(sample_nt) }.not_to raise_error
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
21
|
-
|
22
|
-
expect(
|
20
|
+
it 'knows its label' do
|
21
|
+
allow(sample_nt).to receive(:to_s).and_return('NT')
|
22
|
+
expect(a_vertex.label).to eq('.NT')
|
23
23
|
end
|
24
24
|
end # context
|
25
25
|
|
26
26
|
context 'Provided services:' do
|
27
|
-
it '
|
27
|
+
it 'provides human-readable representation of itself' do
|
28
28
|
pattern = /^#<Rley::GFG::StartVertex:\d+ label="\.NT"/
|
29
|
-
expect(
|
29
|
+
expect(a_vertex.inspect).to match(pattern)
|
30
30
|
end
|
31
31
|
end # context
|
32
32
|
end # describe
|
@@ -8,44 +8,44 @@ require_relative '../../../lib/rley/gfg/vertex'
|
|
8
8
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
9
9
|
module GFG # Open this namespace to avoid module qualifier prefixes
|
10
10
|
describe Vertex do
|
11
|
-
subject {
|
11
|
+
subject(:a_vertex) { described_class.new }
|
12
12
|
|
13
13
|
context 'Initialization:' do
|
14
|
-
it '
|
15
|
-
expect {
|
14
|
+
it 'is created without argument' do
|
15
|
+
expect { described_class.new }.not_to raise_error
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
19
|
-
expect(
|
18
|
+
it "doesn't have edges at start" do
|
19
|
+
expect(a_vertex.edges.empty?).to be(true)
|
20
20
|
end
|
21
21
|
end # context
|
22
22
|
|
23
23
|
context 'Provided services:' do
|
24
|
-
it '
|
25
|
-
expect(
|
24
|
+
it 'knows whether it has a dot at the end of the rhs' do
|
25
|
+
expect(a_vertex).not_to be_complete
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
29
|
-
expect(
|
28
|
+
it 'knows the previous symbol (if any) in the rhs' do
|
29
|
+
expect(a_vertex.prev_symbol).to be_nil
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
33
|
-
expect(
|
32
|
+
it 'knows the next symbol (if any) in the rhs' do
|
33
|
+
expect(a_vertex.next_symbol).to be_nil
|
34
34
|
end
|
35
35
|
|
36
|
-
it '
|
36
|
+
it 'accepts at most one new edge' do
|
37
37
|
edge1 = double('fake-edge1')
|
38
38
|
edge2 = double('fake-edge2')
|
39
39
|
|
40
|
-
expect {
|
41
|
-
expect(
|
42
|
-
expect(
|
40
|
+
expect { a_vertex.add_edge(edge1) }.not_to raise_error
|
41
|
+
expect(a_vertex.edges.size).to eq(1)
|
42
|
+
expect(a_vertex.edges.last).to eq(edge1)
|
43
43
|
|
44
44
|
err = StandardError
|
45
45
|
msg = 'At most one edge accepted'
|
46
|
-
expect {
|
47
|
-
expect(
|
48
|
-
expect(
|
46
|
+
expect { a_vertex.add_edge(edge2) }.to raise_error err, msg
|
47
|
+
expect(a_vertex.edges.size).to eq(1)
|
48
|
+
expect(a_vertex.edges.last).to eq(edge1)
|
49
49
|
end
|
50
50
|
end # context
|
51
51
|
end # describe
|
@@ -16,14 +16,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
16
16
|
|
17
17
|
context 'Initialization:' do
|
18
18
|
# Default instantiation rule
|
19
|
-
subject {
|
19
|
+
subject(:a_literal) { described_class.new(lexeme.to_f, lexeme, a_terminal, a_pos) }
|
20
20
|
|
21
|
-
it '
|
22
|
-
expect {
|
21
|
+
it 'is created with a value, lexeme, terminal and position' do
|
22
|
+
expect { described_class.new(lexeme.to_f, lexeme, a_terminal, a_pos) }.not_to raise_error
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
26
|
-
expect(
|
25
|
+
it 'knows its value' do
|
26
|
+
expect(a_literal.value).to eq(lexeme.to_f)
|
27
27
|
end
|
28
28
|
end # context
|
29
29
|
end # describe
|
@@ -11,87 +11,87 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
11
11
|
let(:sample_range) { { low: 0, high: 5 } }
|
12
12
|
|
13
13
|
# Default instantiation rule
|
14
|
-
subject {
|
14
|
+
subject(:a_range) { described_class.new(sample_range) }
|
15
15
|
|
16
16
|
context 'Initialization:' do
|
17
|
-
it '
|
17
|
+
it 'is created with a range Hash' do
|
18
18
|
# No bounds provided
|
19
|
-
expect {
|
19
|
+
expect { described_class.new({}) }.not_to raise_error
|
20
20
|
|
21
21
|
# Low bound provided
|
22
|
-
expect {
|
22
|
+
expect { described_class.new(low: 0) }.not_to raise_error
|
23
23
|
|
24
24
|
# High bound provided
|
25
|
-
expect {
|
25
|
+
expect { described_class.new(high: 5) }.not_to raise_error
|
26
26
|
|
27
27
|
# Both bounds provided
|
28
|
-
expect {
|
28
|
+
expect { described_class.new(low: 0, high: 5) }.not_to raise_error
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'is created with another TokenRange' do
|
32
32
|
# Low bound provided
|
33
|
-
instance =
|
34
|
-
expect {
|
33
|
+
instance = described_class.new(low: 0)
|
34
|
+
expect { described_class.new(instance) }.not_to raise_error
|
35
35
|
|
36
36
|
# High bound provided
|
37
|
-
instance =
|
38
|
-
expect {
|
37
|
+
instance = described_class.new(high: 5)
|
38
|
+
expect { described_class.new(instance) }.not_to raise_error
|
39
39
|
|
40
40
|
# Both bounds provided
|
41
|
-
instance =
|
42
|
-
expect {
|
41
|
+
instance = described_class.new(low: 0, high: 5)
|
42
|
+
expect { described_class.new(instance) }.not_to raise_error
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
46
|
-
expect(
|
45
|
+
it 'knows its low bound' do
|
46
|
+
expect(a_range.low).to eq(0)
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
50
|
-
expect(
|
49
|
+
it 'knows its high bound' do
|
50
|
+
expect(a_range.high).to eq(5)
|
51
51
|
end
|
52
52
|
end # context
|
53
53
|
|
54
54
|
context 'Provided services:' do
|
55
|
-
it '
|
56
|
-
me =
|
57
|
-
expect(
|
58
|
-
equal =
|
59
|
-
expect(
|
60
|
-
# expect(
|
61
|
-
expect(
|
55
|
+
it 'compares to another range' do
|
56
|
+
me = a_range
|
57
|
+
expect(a_range == me).to be(true)
|
58
|
+
equal = described_class.new(low: 0, high: 5)
|
59
|
+
expect(a_range == equal).to be(true)
|
60
|
+
# expect(a_range == [0..5]).to be(true)
|
61
|
+
expect(a_range == [0, 5]).to be(true)
|
62
62
|
end
|
63
63
|
|
64
64
|
|
65
|
-
it '
|
66
|
-
expect(
|
65
|
+
it 'knows whether it is bounded or not' do
|
66
|
+
expect(a_range).to be_bounded
|
67
67
|
|
68
68
|
# Case: only low bound is set
|
69
|
-
instance =
|
69
|
+
instance = described_class.new(low: 0)
|
70
70
|
expect(instance).not_to be_bounded
|
71
71
|
|
72
72
|
# Case: only upper bound is set
|
73
|
-
instance =
|
73
|
+
instance = described_class.new(high: 5)
|
74
74
|
expect(instance).not_to be_bounded
|
75
75
|
|
76
76
|
# No bound is set
|
77
|
-
instance =
|
77
|
+
instance = described_class.new({})
|
78
78
|
expect(instance).not_to be_bounded
|
79
79
|
end
|
80
80
|
|
81
|
-
it '
|
81
|
+
it 'assigns its open bounds' do
|
82
82
|
some_range = { low: 1, high: 4 }
|
83
83
|
|
84
84
|
###########
|
85
85
|
# Case of bounded token range...
|
86
|
-
|
86
|
+
a_range.assign(some_range)
|
87
87
|
|
88
88
|
# ... should be unchanged
|
89
|
-
expect(
|
90
|
-
expect(
|
89
|
+
expect(a_range.low).to eq(sample_range[:low])
|
90
|
+
expect(a_range.high).to eq(sample_range[:high])
|
91
91
|
|
92
92
|
###########
|
93
93
|
# Case: only low bound is set
|
94
|
-
instance =
|
94
|
+
instance = described_class.new(low: 0)
|
95
95
|
instance.assign(some_range)
|
96
96
|
|
97
97
|
# Expectation: high is assigned the new value
|
@@ -101,7 +101,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
101
101
|
|
102
102
|
###########
|
103
103
|
# Case: only high bound is set
|
104
|
-
instance =
|
104
|
+
instance = described_class.new(high: 5)
|
105
105
|
instance.assign(some_range)
|
106
106
|
|
107
107
|
# Expectation: low is assigned the new value
|
@@ -111,7 +111,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
111
111
|
|
112
112
|
###########
|
113
113
|
# Case: no bound is set
|
114
|
-
instance =
|
114
|
+
instance = described_class.new({})
|
115
115
|
instance.assign(some_range)
|
116
116
|
|
117
117
|
# Expectation: low is assigned the new value
|
@@ -120,48 +120,48 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
120
120
|
expect(instance.high).to eq(4)
|
121
121
|
end
|
122
122
|
|
123
|
-
it '
|
123
|
+
it 'tells whether an index value lies outside the range' do
|
124
124
|
# Out of range...
|
125
|
-
expect(
|
126
|
-
expect(
|
125
|
+
expect(a_range.out_of_range?(-1)).to be(true)
|
126
|
+
expect(a_range.out_of_range?(6)).to be(true)
|
127
127
|
|
128
128
|
# On boundaries...
|
129
|
-
expect(
|
130
|
-
expect(
|
129
|
+
expect(a_range.out_of_range?(0)).to be(false)
|
130
|
+
expect(a_range.out_of_range?(5)).to be(false)
|
131
131
|
|
132
132
|
# Inside boundaries
|
133
|
-
expect(
|
133
|
+
expect(a_range.out_of_range?(2)).to be(false)
|
134
134
|
|
135
|
-
instance =
|
135
|
+
instance = described_class.new(low: nil, high: 5)
|
136
136
|
|
137
137
|
# Lower bound is nil
|
138
|
-
expect(instance.out_of_range?(-1)).to
|
139
|
-
expect(instance.out_of_range?(5)).to
|
140
|
-
expect(instance.out_of_range?(6)).to
|
138
|
+
expect(instance.out_of_range?(-1)).to be(false)
|
139
|
+
expect(instance.out_of_range?(5)).to be(false)
|
140
|
+
expect(instance.out_of_range?(6)).to be(true)
|
141
141
|
|
142
|
-
instance =
|
142
|
+
instance = described_class.new(low: 0, high: nil)
|
143
143
|
|
144
144
|
# Upper bound is nil
|
145
|
-
expect(instance.out_of_range?(-1)).to
|
146
|
-
expect(instance.out_of_range?(0)).to
|
147
|
-
expect(instance.out_of_range?(6)).to
|
145
|
+
expect(instance.out_of_range?(-1)).to be(true)
|
146
|
+
expect(instance.out_of_range?(0)).to be(false)
|
147
|
+
expect(instance.out_of_range?(6)).to be(false)
|
148
148
|
end
|
149
149
|
|
150
|
-
it '
|
150
|
+
it 'provides a text representation of itself' do
|
151
151
|
# Case 1: not bound is set
|
152
|
-
instance =
|
152
|
+
instance = described_class.new({})
|
153
153
|
expect(instance.to_string(0)).to eq('[?, ?]')
|
154
154
|
|
155
155
|
# Case: only low bound is set
|
156
|
-
instance =
|
156
|
+
instance = described_class.new(low: 0)
|
157
157
|
expect(instance.to_string(0)).to eq('[0, ?]')
|
158
158
|
|
159
159
|
# Case: only upper bound is set
|
160
|
-
instance =
|
160
|
+
instance = described_class.new(high: 5)
|
161
161
|
expect(instance.to_string(0)).to eq('[?, 5]')
|
162
162
|
|
163
163
|
# Case: both bounds are set
|
164
|
-
instance =
|
164
|
+
instance = described_class.new(low: 0, high: 5)
|
165
165
|
expect(instance.to_string(0)).to eq('[0, 5]')
|
166
166
|
end
|
167
167
|
end
|