rambling-trie 2.2.1 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -1
- data/LICENSE +1 -1
- data/README.md +37 -21
- data/lib/rambling/trie/comparable.rb +2 -2
- data/lib/rambling/trie/compressible.rb +3 -3
- data/lib/rambling/trie/configuration/properties.rb +10 -9
- data/lib/rambling/trie/configuration/provider_collection.rb +17 -15
- data/lib/rambling/trie/container.rb +18 -20
- data/lib/rambling/trie/enumerable.rb +4 -1
- data/lib/rambling/trie/nodes/compressed.rb +3 -3
- data/lib/rambling/trie/nodes/node.rb +18 -18
- data/lib/rambling/trie/nodes/raw.rb +2 -2
- data/lib/rambling/trie/readers/plain_text.rb +9 -4
- data/lib/rambling/trie/readers/reader.rb +21 -0
- data/lib/rambling/trie/readers.rb +1 -1
- data/lib/rambling/trie/serializers/file.rb +1 -1
- data/lib/rambling/trie/serializers/marshal.rb +6 -5
- data/lib/rambling/trie/serializers/serializer.rb +27 -0
- data/lib/rambling/trie/serializers/yaml.rb +7 -7
- data/lib/rambling/trie/serializers/zip.rb +9 -5
- data/lib/rambling/trie/serializers.rb +1 -1
- data/lib/rambling/trie/stringifyable.rb +1 -1
- data/lib/rambling/trie/version.rb +1 -1
- data/lib/rambling/trie.rb +12 -10
- data/rambling-trie.gemspec +8 -4
- data/spec/integration/rambling/trie_spec.rb +13 -16
- data/spec/lib/rambling/trie/comparable_spec.rb +29 -39
- data/spec/lib/rambling/trie/compressor_spec.rb +17 -14
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +25 -7
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +42 -14
- data/spec/lib/rambling/trie/container_spec.rb +200 -325
- data/spec/lib/rambling/trie/enumerable_spec.rb +18 -10
- data/spec/lib/rambling/trie/inspectable_spec.rb +9 -3
- data/spec/lib/rambling/trie/nodes/node_spec.rb +1 -1
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +26 -23
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +11 -1
- data/spec/lib/rambling/trie/readers/reader_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/file_spec.rb +1 -3
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +1 -3
- data/spec/lib/rambling/trie/serializers/serializer_spec.rb +21 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +1 -3
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +24 -16
- data/spec/lib/rambling/trie/stringifyable_spec.rb +17 -13
- data/spec/lib/rambling/trie_spec.rb +106 -44
- data/spec/spec_helper.rb +14 -9
- data/spec/support/shared_examples/a_compressible_trie.rb +9 -3
- data/spec/support/shared_examples/a_container_partial_word.rb +17 -0
- data/spec/support/shared_examples/a_container_scan.rb +14 -0
- data/spec/support/shared_examples/a_container_word.rb +43 -0
- data/spec/support/shared_examples/a_container_words_within.rb +44 -0
- data/spec/support/shared_examples/a_serializable_trie.rb +4 -8
- data/spec/support/shared_examples/a_serializer.rb +36 -13
- data/spec/support/shared_examples/a_trie_data_structure.rb +24 -10
- data/spec/support/shared_examples/a_trie_node.rb +19 -12
- data/spec/support/shared_examples/a_trie_node_implementation.rb +40 -43
- metadata +26 -10
@@ -3,13 +3,17 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Rambling::Trie::Configuration::Properties do
|
6
|
-
let(:properties) {
|
6
|
+
let(:properties) { described_class.new }
|
7
7
|
|
8
8
|
describe '.new' do
|
9
|
-
it 'configures the
|
9
|
+
it 'configures the serializer formats' do
|
10
10
|
serializers = properties.serializers
|
11
|
-
|
12
11
|
expect(serializers.formats).to match_array %i(marshal yaml yml zip)
|
12
|
+
end
|
13
|
+
|
14
|
+
# rubocop:disable RSpec/ExampleLength
|
15
|
+
it 'configures the serializer providers' do
|
16
|
+
serializers = properties.serializers
|
13
17
|
expect(serializers.providers.to_a).to match_array [
|
14
18
|
[:marshal, Rambling::Trie::Serializers::Marshal],
|
15
19
|
[:yaml, Rambling::Trie::Serializers::Yaml],
|
@@ -17,11 +21,15 @@ describe Rambling::Trie::Configuration::Properties do
|
|
17
21
|
[:zip, Rambling::Trie::Serializers::Zip],
|
18
22
|
]
|
19
23
|
end
|
24
|
+
# rubocop:enable RSpec/ExampleLength
|
20
25
|
|
21
|
-
it 'configures the
|
26
|
+
it 'configures the reader formats' do
|
22
27
|
readers = properties.readers
|
23
|
-
|
24
28
|
expect(readers.formats).to match_array %i(txt)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'configures the reader providers' do
|
32
|
+
readers = properties.readers
|
25
33
|
expect(readers.providers.to_a).to match_array [
|
26
34
|
[:txt, Rambling::Trie::Readers::PlainText],
|
27
35
|
]
|
@@ -44,14 +52,24 @@ describe Rambling::Trie::Configuration::Properties do
|
|
44
52
|
properties.readers.add :test, 'test'
|
45
53
|
end
|
46
54
|
|
47
|
-
|
55
|
+
# rubocop:disable RSpec/MultipleExpectations
|
56
|
+
it 'resets the serializers to initial values' do
|
48
57
|
expect(properties.serializers.formats).to include :test
|
49
|
-
expect(properties.readers.formats).to include :test
|
50
58
|
|
51
59
|
properties.reset
|
52
60
|
|
53
61
|
expect(properties.serializers.formats).not_to include :test
|
62
|
+
end
|
63
|
+
# rubocop:enable RSpec/MultipleExpectations
|
64
|
+
|
65
|
+
# rubocop:disable RSpec/MultipleExpectations
|
66
|
+
it 'resets the readers to initial values' do
|
67
|
+
expect(properties.readers.formats).to include :test
|
68
|
+
|
69
|
+
properties.reset
|
70
|
+
|
54
71
|
expect(properties.readers.formats).not_to include :test
|
55
72
|
end
|
73
|
+
# rubocop:enable RSpec/MultipleExpectations
|
56
74
|
end
|
57
75
|
end
|
@@ -8,11 +8,15 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
8
8
|
{ one: first_provider, two: second_provider }
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:first_provider)
|
12
|
-
|
11
|
+
let(:first_provider) do
|
12
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :first_provider
|
13
|
+
end
|
14
|
+
let(:second_provider) do
|
15
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :second_provider
|
16
|
+
end
|
13
17
|
|
14
18
|
let(:provider_collection) do
|
15
|
-
|
19
|
+
described_class.new(
|
16
20
|
:provider,
|
17
21
|
configured_providers,
|
18
22
|
configured_default,
|
@@ -46,25 +50,31 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
46
50
|
let(:providers) { provider_collection.providers }
|
47
51
|
|
48
52
|
before do
|
49
|
-
allow(providers)
|
53
|
+
allow(providers).to receive_messages(
|
50
54
|
:[] => 'value',
|
51
55
|
keys: %i(a b),
|
52
56
|
)
|
53
57
|
end
|
54
58
|
|
59
|
+
# rubocop:disable RSpec/MultipleExpectations
|
55
60
|
it 'delegates `#[]` to providers' do
|
56
61
|
expect(provider_collection[:key]).to eq 'value'
|
57
62
|
expect(providers).to have_received(:[]).with :key
|
58
63
|
end
|
64
|
+
# rubocop:enable RSpec/MultipleExpectations
|
59
65
|
|
66
|
+
# rubocop:disable RSpec/MultipleExpectations
|
60
67
|
it 'aliases `#formats` to `providers#keys`' do
|
61
68
|
expect(provider_collection.formats).to eq %i(a b)
|
62
69
|
expect(providers).to have_received :keys
|
63
70
|
end
|
71
|
+
# rubocop:enable RSpec/MultipleExpectations
|
64
72
|
end
|
65
73
|
|
66
74
|
describe '#add' do
|
67
|
-
let(:provider)
|
75
|
+
let(:provider) do
|
76
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :provider
|
77
|
+
end
|
68
78
|
|
69
79
|
before do
|
70
80
|
provider_collection.add :three, provider
|
@@ -76,7 +86,9 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
76
86
|
end
|
77
87
|
|
78
88
|
describe '#default=' do
|
79
|
-
let(:other_provider)
|
89
|
+
let(:other_provider) do
|
90
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :other_provider
|
91
|
+
end
|
80
92
|
|
81
93
|
context 'when the given value is in the providers list' do
|
82
94
|
it 'changes the default provider' do
|
@@ -106,43 +118,59 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
106
118
|
expect(provider_collection.default).to be_nil
|
107
119
|
end
|
108
120
|
|
121
|
+
# rubocop:disable RSpec/MultipleExpectations
|
109
122
|
it 'raises an ArgumentError for any other provider' do
|
110
123
|
expect do
|
111
124
|
provider_collection.default = other_provider
|
112
125
|
end.to raise_error ArgumentError
|
113
126
|
expect(provider_collection.default).to be_nil
|
114
127
|
end
|
128
|
+
# rubocop:enable RSpec/MultipleExpectations
|
115
129
|
end
|
116
130
|
end
|
117
131
|
|
118
132
|
describe '#resolve' do
|
119
133
|
context 'when the file extension is one of the providers' do
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
[
|
135
|
+
['hola.one', :first_provider],
|
136
|
+
['hola.two', :second_provider],
|
137
|
+
].each do |test_params|
|
138
|
+
filepath, provider = test_params
|
139
|
+
|
140
|
+
it 'returns the corresponding provider' do
|
141
|
+
provider_instance = public_send provider
|
142
|
+
expect(provider_collection.resolve filepath).to eq provider_instance
|
143
|
+
end
|
123
144
|
end
|
124
145
|
end
|
125
146
|
|
126
147
|
context 'when the file extension is not one of the providers' do
|
127
|
-
|
128
|
-
|
129
|
-
|
148
|
+
%w(hola.unknown hola).each do |filepath|
|
149
|
+
it 'returns the default provider' do
|
150
|
+
expect(provider_collection.resolve filepath).to eq first_provider
|
151
|
+
end
|
130
152
|
end
|
131
153
|
end
|
132
154
|
end
|
133
155
|
|
134
156
|
describe '#reset' do
|
135
157
|
let(:configured_default) { second_provider }
|
136
|
-
let(:provider)
|
158
|
+
let(:provider) do
|
159
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :provider
|
160
|
+
end
|
137
161
|
|
138
162
|
before do
|
139
163
|
provider_collection.add :three, provider
|
140
164
|
provider_collection.default = provider
|
141
165
|
end
|
142
166
|
|
143
|
-
it 'resets to back to the initially configured values' do
|
167
|
+
it 'resets to back to the initially configured values (:three => nil)' do
|
144
168
|
provider_collection.reset
|
145
169
|
expect(provider_collection[:three]).to be_nil
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'resets to back to the initially configured default' do
|
173
|
+
provider_collection.reset
|
146
174
|
expect(provider_collection.default).to eq second_provider
|
147
175
|
end
|
148
176
|
end
|