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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -1
  3. data/LICENSE +1 -1
  4. data/README.md +37 -21
  5. data/lib/rambling/trie/comparable.rb +2 -2
  6. data/lib/rambling/trie/compressible.rb +3 -3
  7. data/lib/rambling/trie/configuration/properties.rb +10 -9
  8. data/lib/rambling/trie/configuration/provider_collection.rb +17 -15
  9. data/lib/rambling/trie/container.rb +18 -20
  10. data/lib/rambling/trie/enumerable.rb +4 -1
  11. data/lib/rambling/trie/nodes/compressed.rb +3 -3
  12. data/lib/rambling/trie/nodes/node.rb +18 -18
  13. data/lib/rambling/trie/nodes/raw.rb +2 -2
  14. data/lib/rambling/trie/readers/plain_text.rb +9 -4
  15. data/lib/rambling/trie/readers/reader.rb +21 -0
  16. data/lib/rambling/trie/readers.rb +1 -1
  17. data/lib/rambling/trie/serializers/file.rb +1 -1
  18. data/lib/rambling/trie/serializers/marshal.rb +6 -5
  19. data/lib/rambling/trie/serializers/serializer.rb +27 -0
  20. data/lib/rambling/trie/serializers/yaml.rb +7 -7
  21. data/lib/rambling/trie/serializers/zip.rb +9 -5
  22. data/lib/rambling/trie/serializers.rb +1 -1
  23. data/lib/rambling/trie/stringifyable.rb +1 -1
  24. data/lib/rambling/trie/version.rb +1 -1
  25. data/lib/rambling/trie.rb +12 -10
  26. data/rambling-trie.gemspec +8 -4
  27. data/spec/integration/rambling/trie_spec.rb +13 -16
  28. data/spec/lib/rambling/trie/comparable_spec.rb +29 -39
  29. data/spec/lib/rambling/trie/compressor_spec.rb +17 -14
  30. data/spec/lib/rambling/trie/configuration/properties_spec.rb +25 -7
  31. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +42 -14
  32. data/spec/lib/rambling/trie/container_spec.rb +200 -325
  33. data/spec/lib/rambling/trie/enumerable_spec.rb +18 -10
  34. data/spec/lib/rambling/trie/inspectable_spec.rb +9 -3
  35. data/spec/lib/rambling/trie/nodes/node_spec.rb +1 -1
  36. data/spec/lib/rambling/trie/nodes/raw_spec.rb +26 -23
  37. data/spec/lib/rambling/trie/readers/plain_text_spec.rb +11 -1
  38. data/spec/lib/rambling/trie/readers/reader_spec.rb +14 -0
  39. data/spec/lib/rambling/trie/serializers/file_spec.rb +1 -3
  40. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +1 -3
  41. data/spec/lib/rambling/trie/serializers/serializer_spec.rb +21 -0
  42. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +1 -3
  43. data/spec/lib/rambling/trie/serializers/zip_spec.rb +24 -16
  44. data/spec/lib/rambling/trie/stringifyable_spec.rb +17 -13
  45. data/spec/lib/rambling/trie_spec.rb +106 -44
  46. data/spec/spec_helper.rb +14 -9
  47. data/spec/support/shared_examples/a_compressible_trie.rb +9 -3
  48. data/spec/support/shared_examples/a_container_partial_word.rb +17 -0
  49. data/spec/support/shared_examples/a_container_scan.rb +14 -0
  50. data/spec/support/shared_examples/a_container_word.rb +43 -0
  51. data/spec/support/shared_examples/a_container_words_within.rb +44 -0
  52. data/spec/support/shared_examples/a_serializable_trie.rb +4 -8
  53. data/spec/support/shared_examples/a_serializer.rb +36 -13
  54. data/spec/support/shared_examples/a_trie_data_structure.rb +24 -10
  55. data/spec/support/shared_examples/a_trie_node.rb +19 -12
  56. data/spec/support/shared_examples/a_trie_node_implementation.rb +40 -43
  57. 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) { Rambling::Trie::Configuration::Properties.new }
6
+ let(:properties) { described_class.new }
7
7
 
8
8
  describe '.new' do
9
- it 'configures the serializers' do
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 readers' do
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
- it 'resets the serializers and readers to initial values' do
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) { double :first_provider }
12
- let(:second_provider) { double :second_provider }
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
- Rambling::Trie::Configuration::ProviderCollection.new(
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) .to receive_messages(
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) { double :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) { double :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
- it 'returns the corresponding provider' do
121
- expect(provider_collection.resolve 'hola.one').to eq first_provider
122
- expect(provider_collection.resolve 'hola.two').to eq second_provider
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
- it 'returns the default provider' do
128
- expect(provider_collection.resolve 'hola.unknown').to eq first_provider
129
- expect(provider_collection.resolve 'hola').to eq first_provider
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) { double :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