spec/lib/rambling/trie/raw_node_spec.rb in rambling-trie-0.9.1 vs spec/lib/rambling/trie/raw_node_spec.rb in rambling-trie-0.9.2
- old
+ new
@@ -314,9 +314,40 @@
end
end
end
end
+ describe '#scan' do
+ context 'when the chars array is empty' do
+ it 'returns itself' do
+ expect(node.scan []).to eq node
+ end
+ end
+
+ context 'when the chars array is not empty' do
+ before do
+ node.add 'cba'
+ end
+
+ context 'when the chars are found' do
+ it 'returns the found child' do
+ expect(node.scan %w(c)).to eq node[:c]
+ expect(node.scan %w(c b)).to eq node[:c][:b]
+ expect(node.scan %w(c b a)).to eq node[:c][:b][:a]
+ end
+ end
+
+ context 'when the chars are not found' do
+ it 'returns a MissingNode' do
+ expect(node.scan %w(a)).to be_a Rambling::Trie::MissingNode
+ expect(node.scan %w(a b)).to be_a Rambling::Trie::MissingNode
+ expect(node.scan %w(a b c)).to be_a Rambling::Trie::MissingNode
+ expect(node.scan %w(c b a d)).to be_a Rambling::Trie::MissingNode
+ end
+ end
+ end
+ end
+
describe '#as_word' do
let(:node) { Rambling::Trie::RawNode.new }
context 'for an empty node' do
before do