Sha256: 2504b6a66705803916a7e852564061f9be7d178ca1bd41c9069947d15acbb2c6

Contents?: true

Size: 1.22 KB

Versions: 21

Compression:

Stored size: 1.22 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'

include TwitterCldr::Collation

describe TrieWithFallback do

  let(:fallback) { Trie.new }
  let(:trie)     { TrieWithFallback.new(fallback) }

  before(:each) { trie.add([1, 2, 3], 'value') }

  describe '#get' do
    it 'returns result if the key is present' do
      dont_allow(fallback).get
      expect(trie.get([1, 2, 3])).to eq('value')
    end

    it 'resorts to the fallback if the key is not present' do
      mock(fallback).get([3, 2, 1]) { 'fallback-value' }
      expect(trie.get([3, 2, 1])).to eq('fallback-value')
    end
  end

  describe '#find_prefix' do
    it 'returns result if the key is present' do
      dont_allow(fallback).find_prefix
      expect(trie.find_prefix([1, 2, 3, 4]).first(2)).to eq(['value', 3])
    end

    it 'resorts to the fallback if the key is not present' do
      mock(fallback).find_prefix([3, 2, 1]) { 'fallback-result' }
      expect(trie.find_prefix([3, 2, 1])).to eq('fallback-result')
    end
  end

  describe 'marshaling' do
    it 'does not dump fallback' do
      expect(Marshal.load(Marshal.dump(TrieWithFallback.new(Trie.new))).fallback).to be_nil
    end
  end

end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
twitter_cldr-3.6.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.5.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.4.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.3.0 spec/collation/trie_with_fallback_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/spec/collation/trie_with_fallback_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/spec/collation/trie_with_fallback_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.2.1 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.2.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.1.2 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.1.1 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.1.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.10 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.9 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.8 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.7 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.6 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.5 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.4 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-3.0.3 spec/collation/trie_with_fallback_spec.rb