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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -2
  3. data/CHANGELOG.md +3 -0
  4. data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
  5. data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
  6. data/examples/general/recursive_right.rb +2 -2
  7. data/lib/rley/constants.rb +1 -1
  8. data/lib/rley/gfg/grm_flow_graph.rb +0 -1
  9. data/lib/rley/parser/parse_entry_set.rb +0 -1
  10. data/lib/rley/parser/parse_walker_factory.rb +0 -1
  11. data/lib/rley/rgn/grammar_builder.rb +0 -2
  12. data/lib/rley/rgn/tokenizer.rb +1 -1
  13. data/lib/rley/syntax/base_grammar_builder.rb +0 -1
  14. data/lib/rley/syntax/grammar.rb +0 -1
  15. data/spec/rley/base/dotted_item_spec.rb +46 -46
  16. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  17. data/spec/rley/engine_spec.rb +50 -50
  18. data/spec/rley/formatter/asciitree_spec.rb +8 -8
  19. data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
  20. data/spec/rley/formatter/debug_spec.rb +10 -10
  21. data/spec/rley/formatter/json_spec.rb +6 -7
  22. data/spec/rley/gfg/call_edge_spec.rb +6 -6
  23. data/spec/rley/gfg/edge_spec.rb +8 -7
  24. data/spec/rley/gfg/end_vertex_spec.rb +8 -7
  25. data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
  26. data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
  27. data/spec/rley/gfg/item_vertex_spec.rb +34 -36
  28. data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
  29. data/spec/rley/gfg/return_edge_spec.rb +6 -6
  30. data/spec/rley/gfg/scan_edge_spec.rb +7 -6
  31. data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
  32. data/spec/rley/gfg/start_vertex_spec.rb +8 -8
  33. data/spec/rley/gfg/vertex_spec.rb +18 -18
  34. data/spec/rley/lexical/literal_spec.rb +5 -5
  35. data/spec/rley/lexical/token_range_spec.rb +55 -55
  36. data/spec/rley/lexical/token_spec.rb +17 -16
  37. data/spec/rley/parse_forest_visitor_spec.rb +30 -32
  38. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
  39. data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
  40. data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
  41. data/spec/rley/parse_rep/groucho_spec.rb +23 -23
  42. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
  43. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
  44. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
  45. data/spec/rley/parse_tree_visitor_spec.rb +43 -46
  46. data/spec/rley/parser/dangling_else_spec.rb +12 -12
  47. data/spec/rley/parser/error_reason_spec.rb +37 -37
  48. data/spec/rley/parser/gfg_chart_spec.rb +27 -29
  49. data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
  50. data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
  51. data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
  52. data/spec/rley/parser/parse_entry_spec.rb +73 -71
  53. data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
  54. data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
  55. data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
  56. data/spec/rley/ptree/parse_tree_spec.rb +6 -8
  57. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  58. data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
  59. data/spec/rley/rgn/parser_spec.rb +63 -63
  60. data/spec/rley/rgn/repetition_node_spec.rb +15 -15
  61. data/spec/rley/rgn/sequence_node_spec.rb +10 -10
  62. data/spec/rley/rgn/symbol_node_spec.rb +5 -6
  63. data/spec/rley/rgn/tokenizer_spec.rb +68 -67
  64. data/spec/rley/sppf/alternative_node_spec.rb +16 -16
  65. data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
  66. data/spec/rley/sppf/token_node_spec.rb +13 -13
  67. data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
  68. data/spec/rley/syntax/grammar_spec.rb +40 -78
  69. data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
  70. data/spec/rley/syntax/match_closest_spec.rb +8 -8
  71. data/spec/rley/syntax/non_terminal_spec.rb +25 -25
  72. data/spec/rley/syntax/production_spec.rb +33 -33
  73. data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
  74. data/spec/rley/syntax/terminal_spec.rb +12 -11
  75. data/spec/support/base_tokenizer_spec.rb +9 -8
  76. 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 'should be created with a dotted item' do
38
- expect { ItemVertex.new(sample_item) }.not_to raise_error
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 'should know its dotted item' do
42
- expect(subject.dotted_item).to eq(sample_item)
41
+ it 'knows its dotted item' do
42
+ expect(a_vertex.dotted_item).to eq(sample_item)
43
43
  end
44
44
 
45
- it 'should not have any shortcut edge at start' do
46
- expect(subject.shortcut).to be_nil
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 'should know its label' do
52
- expect(subject.label).to eq(sample_item.to_s)
51
+ it 'knows its label' do
52
+ expect(a_vertex.label).to eq(sample_item.to_s)
53
53
  end
54
54
 
55
- it 'should know the lhs of the production' do
56
- expect(subject.lhs).to eq(nt_sentence)
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 'should know whether it has a dot at the end of the rhs' do
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(subject).not_to be_complete
61
+ expect(a_vertex).not_to be_complete
62
62
 
63
63
  # Case: dot at the end
64
- instance1 = ItemVertex.new(Base::DottedItem.new(sample_prod, 3))
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 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
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 'should know the previous symbol (if any) in the rhs' do
72
+ it 'knows the previous symbol (if any) in the rhs (i)' do
73
73
  # Case: dot is after first symbol
74
- instance1 = ItemVertex.new(sample_item)
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 = ItemVertex.new(next_item)
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 = ItemVertex.new(Base::DottedItem.new(sample_prod, 0))
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 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
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 'should know the next symbol (if any) in the rhs' do
91
+ it 'knows the next symbol (if any) in the rhs (ii)' do
92
92
  # Case: dot is not penultimate
93
- expect(subject.next_symbol).to eq(nt_b_sequence)
93
+ expect(a_vertex.next_symbol).to eq(nt_b_sequence)
94
94
 
95
95
  # Case: dot is penultimate
96
- instance1 = ItemVertex.new(next_item)
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 = ItemVertex.new(Base::DottedItem.new(sample_prod, 3))
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 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
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 'should accept a shortcut edge' do
109
- next_vertex = ItemVertex.new(next_item)
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(subject, next_vertex)
113
- expect(subject.shortcut).to eq(shortcut)
112
+ shortcut = ShortcutEdge.new(a_vertex, next_vertex)
113
+ expect(a_vertex.shortcut).to eq(shortcut)
114
114
  end
115
115
 
116
- it 'should reject an invalid shortcut edge' do
116
+ it 'rejects an invalid shortcut edge' do
117
117
  err = StandardError
118
118
  err_msg = 'Invalid shortcut argument'
119
- expect { subject.shortcut = 'invalid' }.to raise_error(err, err_msg)
119
+ expect { a_vertex.shortcut = 'invalid' }.to raise_error(err, err_msg)
120
120
  end
121
- end # context
122
121
 
123
- context 'Provided services:' do
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(subject.inspect).to match(prefix)
124
+ expect(a_vertex.inspect).to match(prefix)
127
125
  suffix = /label="sentence => a \. b_sequence c">$/
128
- expect(subject.inspect).to match(suffix)
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 'should be created with a non-terminal symbol' do
16
- expect { NonTerminalVertex.new(sample_nt) }.not_to raise_error
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 'should know its non-terminal' do
20
- expect(subject.non_terminal).to eq(sample_nt)
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 'should accept at more than one outgoing edge' do
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 { subject.add_edge(edge1) }.not_to raise_error
29
- expect(subject.edges.size).to eq(1)
30
- expect(subject.edges.last).to eq(edge1)
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 { subject.add_edge(edge2) }.not_to raise_error
33
- expect(subject.edges.size).to eq(2)
34
- expect(subject.edges.last).to eq(edge2)
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 'should be created with two vertice arguments' do
38
- expect { ReturnEdge.new(vertex1, vertex2) }.not_to raise_error
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 'should know its key' do
43
+ it 'knows its key' do
44
44
  pos = sample_item.position
45
45
  expectation = "RET_#{sample_prod.object_id}_#{pos - 1}"
46
- expect(subject.key).to eq(expectation)
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 Edge do
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 'should be created with two vertice arguments & a terminal' do
21
+ it 'is created with two vertice arguments & a terminal' do
21
22
  v1 = vertex1
22
23
  v2 = vertex2
23
- expect { ScanEdge.new(v1, v2, sample_terminal) }.not_to raise_error
24
+ expect { described_class.new(v1, v2, sample_terminal) }.not_to raise_error
24
25
  end
25
26
 
26
- it 'should know the related terminal' do
27
- expect(subject.terminal).to eq(sample_terminal)
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 Edge do
12
- let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
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 'should be created with two vertice arguments & a non-terminal' do
20
- expect(vertex1).to receive(:shortcut=)
21
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
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 { ShortcutEdge.new(vertex1, vertex2) }
23
+ expect { described_class.new(vertex1, vertex2) }
24
24
  .not_to raise_error
25
25
  end
26
26
 
27
- it 'should know the successor vertex' do
28
- expect(vertex1).to receive(:shortcut=)
29
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
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(subject.successor).to eq(vertex2)
31
+ expect(an_edge.successor).to eq(vertex2)
32
32
  end
33
33
 
34
- it 'should know the related terminal' do
35
- expect(vertex1).to receive(:shortcut=)
36
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
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(subject.nonterminal).to eq(nt_b_sequence)
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 'should be created with a non-terminal symbol' do
17
- expect { StartVertex.new(sample_nt) }.not_to raise_error
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 'should know its label' do
21
- expect(sample_nt).to receive(:to_s).and_return('NT')
22
- expect(subject.label).to eq('.NT')
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 'should provide human-readable representation of itself' do
27
+ it 'provides human-readable representation of itself' do
28
28
  pattern = /^#<Rley::GFG::StartVertex:\d+ label="\.NT"/
29
- expect(subject.inspect).to match(pattern)
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 { Vertex.new }
11
+ subject(:a_vertex) { described_class.new }
12
12
 
13
13
  context 'Initialization:' do
14
- it 'should be created without argument' do
15
- expect { Vertex.new }.not_to raise_error
14
+ it 'is created without argument' do
15
+ expect { described_class.new }.not_to raise_error
16
16
  end
17
17
 
18
- it "shouldn't have edges at start" do
19
- expect(subject.edges.empty?).to eq(true)
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 'should know whether it has a dot at the end of the rhs' do
25
- expect(subject).not_to be_complete
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 'should know the previous symbol (if any) in the rhs' do
29
- expect(subject.prev_symbol).to be_nil
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 'should know the next symbol (if any) in the rhs' do
33
- expect(subject.next_symbol).to be_nil
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 'should accept at most one new edge' do
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 { subject.add_edge(edge1) }.not_to raise_error
41
- expect(subject.edges.size).to eq(1)
42
- expect(subject.edges.last).to eq(edge1)
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 { subject.add_edge(edge2) }.to raise_error err, msg
47
- expect(subject.edges.size).to eq(1)
48
- expect(subject.edges.last).to eq(edge1)
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 { Literal.new(lexeme.to_f, lexeme, a_terminal, a_pos) }
19
+ subject(:a_literal) { described_class.new(lexeme.to_f, lexeme, a_terminal, a_pos) }
20
20
 
21
- it 'should be created with a value, lexeme, terminal and position' do
22
- expect { Literal.new(lexeme.to_f, lexeme, a_terminal, a_pos) }.not_to raise_error
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 'should know its value' do
26
- expect(subject.value).to eq(lexeme.to_f)
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 { TokenRange.new(sample_range) }
14
+ subject(:a_range) { described_class.new(sample_range) }
15
15
 
16
16
  context 'Initialization:' do
17
- it 'could be created with a range Hash' do
17
+ it 'is created with a range Hash' do
18
18
  # No bounds provided
19
- expect { TokenRange.new({}) }.not_to raise_error
19
+ expect { described_class.new({}) }.not_to raise_error
20
20
 
21
21
  # Low bound provided
22
- expect { TokenRange.new(low: 0) }.not_to raise_error
22
+ expect { described_class.new(low: 0) }.not_to raise_error
23
23
 
24
24
  # High bound provided
25
- expect { TokenRange.new(high: 5) }.not_to raise_error
25
+ expect { described_class.new(high: 5) }.not_to raise_error
26
26
 
27
27
  # Both bounds provided
28
- expect { TokenRange.new(low: 0, high: 5) }.not_to raise_error
28
+ expect { described_class.new(low: 0, high: 5) }.not_to raise_error
29
29
  end
30
30
 
31
- it 'could be created with another TokenRange' do
31
+ it 'is created with another TokenRange' do
32
32
  # Low bound provided
33
- instance = TokenRange.new(low: 0)
34
- expect { TokenRange.new(instance) }.not_to raise_error
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 = TokenRange.new(high: 5)
38
- expect { TokenRange.new(instance) }.not_to raise_error
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 = TokenRange.new(low: 0, high: 5)
42
- expect { TokenRange.new(instance) }.not_to raise_error
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 'should know its low bound' do
46
- expect(subject.low).to eq(0)
45
+ it 'knows its low bound' do
46
+ expect(a_range.low).to eq(0)
47
47
  end
48
48
 
49
- it 'should know its low bound' do
50
- expect(subject.high).to eq(5)
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 'should compare to another range' do
56
- me = subject
57
- expect(subject == me).to eq(true)
58
- equal = TokenRange.new(low: 0, high: 5)
59
- expect(subject == equal).to eq(true)
60
- # expect(subject == [0..5]).to eq(true)
61
- expect(subject == [0, 5]).to eq(true)
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 'should know whether it is bounded or not' do
66
- expect(subject).to be_bounded
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 = TokenRange.new(low: 0)
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 = TokenRange.new(high: 5)
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 = TokenRange.new({})
77
+ instance = described_class.new({})
78
78
  expect(instance).not_to be_bounded
79
79
  end
80
80
 
81
- it 'should assign its open bounds' do
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
- subject.assign(some_range)
86
+ a_range.assign(some_range)
87
87
 
88
88
  # ... should be unchanged
89
- expect(subject.low).to eq(sample_range[:low])
90
- expect(subject.high).to eq(sample_range[:high])
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 = TokenRange.new(low: 0)
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 = TokenRange.new(high: 5)
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 = TokenRange.new({})
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 'should tell whether an index value lies outside the range' do
123
+ it 'tells whether an index value lies outside the range' do
124
124
  # Out of range...
125
- expect(subject.out_of_range?(-1)).to eq(true)
126
- expect(subject.out_of_range?(6)).to eq(true)
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(subject.out_of_range?(0)).to eq(false)
130
- expect(subject.out_of_range?(5)).to eq(false)
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(subject.out_of_range?(2)).to eq(false)
133
+ expect(a_range.out_of_range?(2)).to be(false)
134
134
 
135
- instance = TokenRange.new(low: nil, high: 5)
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 eq(false)
139
- expect(instance.out_of_range?(5)).to eq(false)
140
- expect(instance.out_of_range?(6)).to eq(true)
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 = TokenRange.new(low: 0, high: nil)
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 eq(true)
146
- expect(instance.out_of_range?(0)).to eq(false)
147
- expect(instance.out_of_range?(6)).to eq(false)
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 'should provide a text representation of itself' do
150
+ it 'provides a text representation of itself' do
151
151
  # Case 1: not bound is set
152
- instance = TokenRange.new({})
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 = TokenRange.new(low: 0)
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 = TokenRange.new(high: 5)
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 = TokenRange.new(low: 0, high: 5)
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