sequitur 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rubocop.yml +5 -4
- data/CHANGELOG.md +7 -2
- data/Rakefile +4 -6
- data/lib/sequitur.rb +0 -1
- data/lib/sequitur/constants.rb +1 -1
- data/lib/sequitur/digram.rb +0 -3
- data/lib/sequitur/dynamic_grammar.rb +0 -3
- data/lib/sequitur/formatter/base_formatter.rb +0 -3
- data/lib/sequitur/formatter/base_text.rb +0 -3
- data/lib/sequitur/formatter/debug.rb +0 -3
- data/lib/sequitur/grammar_visitor.rb +0 -4
- data/lib/sequitur/production.rb +0 -5
- data/lib/sequitur/production_ref.rb +0 -4
- data/lib/sequitur/sequitur_grammar.rb +0 -4
- data/lib/sequitur/symbol_sequence.rb +6 -8
- data/spec/sequitur/digram_spec.rb +0 -8
- data/spec/sequitur/dynamic_grammar_spec.rb +144 -159
- data/spec/sequitur/formatter/base_text_spec.rb +92 -95
- data/spec/sequitur/formatter/debug_spec.rb +111 -114
- data/spec/sequitur/grammar_visitor_spec.rb +80 -88
- data/spec/sequitur/production_ref_spec.rb +102 -111
- data/spec/sequitur/production_spec.rb +361 -376
- data/spec/sequitur/sequitur_grammar_spec.rb +1 -5
- data/spec/sequitur/symbol_sequence_spec.rb +115 -124
- metadata +2 -2
@@ -4,7 +4,6 @@ require_relative '../spec_helper'
|
|
4
4
|
require_relative '../../lib/sequitur/sequitur_grammar'
|
5
5
|
|
6
6
|
module Sequitur # Re-open the module to get rid of qualified names
|
7
|
-
|
8
7
|
describe SequiturGrammar do
|
9
8
|
# Factory method. Returns an empty enumerator (
|
10
9
|
# i.e. without elements to iterate)
|
@@ -13,7 +12,6 @@ describe SequiturGrammar do
|
|
13
12
|
end
|
14
13
|
|
15
14
|
context 'Creation from an enumeration of tokens:' do
|
16
|
-
|
17
15
|
it 'could be created with an empty enumerator' do
|
18
16
|
expect { SequiturGrammar.new(empty_enum) }.not_to raise_error
|
19
17
|
|
@@ -124,7 +122,7 @@ describe SequiturGrammar do
|
|
124
122
|
expect(instance.start.rhs).to eq([p3, p2, p3])
|
125
123
|
expect(p1.rhs).to eq(%w(letter_b letter_e))
|
126
124
|
expect(p2.rhs).to eq([p1, p1])
|
127
|
-
expect(p3.rhs).to eq(['letter_b',p2, 'letter_e'])
|
125
|
+
expect(p3.rhs).to eq(['letter_b', p2, 'letter_e'])
|
128
126
|
end
|
129
127
|
|
130
128
|
it 'should work with Symbol instead of single char input tokens' do
|
@@ -287,7 +285,6 @@ SNIPPET
|
|
287
285
|
end # context
|
288
286
|
|
289
287
|
context 'Generating a text representation of itself:' do
|
290
|
-
|
291
288
|
it 'should generate a text representation when empty' do
|
292
289
|
instance = SequiturGrammar.new(empty_enum)
|
293
290
|
expectation = "#{instance.start.object_id} : ."
|
@@ -301,7 +298,6 @@ SNIPPET
|
|
301
298
|
expect(instance.to_string).to eq(expectation)
|
302
299
|
end
|
303
300
|
end # context
|
304
|
-
|
305
301
|
end # describe
|
306
302
|
end # module
|
307
303
|
|
@@ -1,124 +1,115 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
# Load the class under test
|
4
|
-
require_relative '../../lib/sequitur/symbol_sequence'
|
5
|
-
require_relative '../../lib/sequitur/production_ref'
|
6
|
-
require_relative '../../lib/sequitur/production'
|
7
|
-
|
8
|
-
module Sequitur # Re-open the module to get rid of qualified names
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect(clone_a
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
expect(instance).to eq(instance)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
expect(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
expect(subject).
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
expect(subject).
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
expect(subject).not_to eq(
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
refs = subject.references
|
94
|
-
expect(refs.size).to eq(2)
|
95
|
-
expect(refs).to eq([ref, ref])
|
96
|
-
|
97
|
-
refs
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
expect(
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end # context
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end # describe
|
121
|
-
|
122
|
-
end # module
|
123
|
-
|
124
|
-
# End of file
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../lib/sequitur/symbol_sequence'
|
5
|
+
require_relative '../../lib/sequitur/production_ref'
|
6
|
+
require_relative '../../lib/sequitur/production'
|
7
|
+
|
8
|
+
module Sequitur # Re-open the module to get rid of qualified names
|
9
|
+
describe SymbolSequence do
|
10
|
+
let(:instance) { SymbolSequence.new }
|
11
|
+
|
12
|
+
context 'Creation and initialization:' do
|
13
|
+
it 'should be created without argument' do
|
14
|
+
expect { SymbolSequence.new }.not_to raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should be empty at creation' do
|
18
|
+
expect(subject).to be_empty
|
19
|
+
end
|
20
|
+
end # context
|
21
|
+
|
22
|
+
context 'Provided services:' do
|
23
|
+
let(:a_prod) { Production.new }
|
24
|
+
|
25
|
+
subject do
|
26
|
+
an_instance = SymbolSequence.new
|
27
|
+
[:a, :b, :c].each { |a_sym| an_instance << a_sym }
|
28
|
+
an_instance
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should deep-copy clone itself' do
|
32
|
+
ref = ProductionRef.new(a_prod)
|
33
|
+
|
34
|
+
a, c = 'a', 'c'
|
35
|
+
[a, ref, c].each { |ch| instance << ch }
|
36
|
+
clone_a = instance.clone
|
37
|
+
|
38
|
+
# Check that cloning works
|
39
|
+
expect(clone_a).to eq(instance)
|
40
|
+
|
41
|
+
# Reference objects are distinct but points to same production
|
42
|
+
expect(clone_a.symbols[1].object_id).not_to eq(instance.symbols[1])
|
43
|
+
|
44
|
+
# Modifying the clone...
|
45
|
+
clone_a.symbols[1] = 'diff'
|
46
|
+
expect(clone_a).not_to eq(instance)
|
47
|
+
|
48
|
+
# ... should leave original unchanged
|
49
|
+
expect(instance.symbols[1]).to eq(ref)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it 'should tell that it is equal to itself' do
|
54
|
+
# Case: Non-empty sequence
|
55
|
+
expect(subject).to eq(subject)
|
56
|
+
|
57
|
+
# Case: empty sequence
|
58
|
+
expect(instance).to eq(instance)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should know whether it is equal to another instance' do
|
62
|
+
expect(instance).to eq(instance)
|
63
|
+
|
64
|
+
expect(subject).not_to eq(instance)
|
65
|
+
[:a, :b, :c].each { |a_sym| instance << a_sym }
|
66
|
+
expect(subject).to eq(instance)
|
67
|
+
|
68
|
+
# Check that element order is relevant
|
69
|
+
instance.symbols.rotate!
|
70
|
+
expect(subject).not_to eq(instance)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should know whether it is equal to an array' do
|
74
|
+
expect(subject).to eq([:a, :b, :c])
|
75
|
+
|
76
|
+
# Check that element order is relevant
|
77
|
+
expect(subject).not_to eq([:c, :b, :a])
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should know that is not equal to something else' do
|
81
|
+
expect(subject).not_to eq(:abc)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
it 'should know its references' do
|
86
|
+
ref = ProductionRef.new(a_prod)
|
87
|
+
2.times { subject << ref }
|
88
|
+
|
89
|
+
refs = subject.references
|
90
|
+
expect(refs.size).to eq(2)
|
91
|
+
expect(refs).to eq([ref, ref])
|
92
|
+
|
93
|
+
refs = subject.references
|
94
|
+
expect(refs.size).to eq(2)
|
95
|
+
expect(refs).to eq([ref, ref])
|
96
|
+
specific_refs = subject.references_of(a_prod)
|
97
|
+
expect(specific_refs).to eq(refs)
|
98
|
+
|
99
|
+
|
100
|
+
another = Production.new
|
101
|
+
another_ref = ProductionRef.new(another)
|
102
|
+
subject << another_ref
|
103
|
+
refs = subject.references
|
104
|
+
expect(refs.size).to eq(3)
|
105
|
+
expect(refs).to eq([ref, ref, another])
|
106
|
+
specific_refs = subject.references_of(a_prod)
|
107
|
+
expect(specific_refs).to eq([ref, ref])
|
108
|
+
specific_refs = subject.references_of(another)
|
109
|
+
expect(specific_refs).to eq([another])
|
110
|
+
end
|
111
|
+
end # context
|
112
|
+
end # describe
|
113
|
+
end # module
|
114
|
+
|
115
|
+
# End of file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequitur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|