Sha256: c81352bbae679ca941471502eb49eee0b1e34e1ca21ea4cd0bc066d071229f9d

Contents?: true

Size: 1.33 KB

Versions: 27

Compression:

Stored size: 1.33 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

describe TwitterCldr::Collation::TrieWithFallback do

  let(:fallback) { TwitterCldr::Utils::Trie.new }
  let(:trie)     { described_class.new(fallback) }

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

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

    it 'resorts to the fallback if the key is not present' do
      expect(fallback).to receive(:get).with([3, 2, 1]).and_return('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
      expect(fallback).to_not receive(: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
      expect(fallback).to receive(:find_prefix).with([3, 2, 1]).and_return('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(described_class.new(TwitterCldr::Utils::Trie.new))).fallback).to be_nil
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
twitter_cldr-6.12.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.5 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.4 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.3 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.2 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.1 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.11.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.10.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.9.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.8.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.7.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.6.2 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.6.1 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.6.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.5.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.4.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.3.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.2.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.1.0 spec/collation/trie_with_fallback_spec.rb
twitter_cldr-6.0.2 spec/collation/trie_with_fallback_spec.rb