Sha256: 725965b33e423acb4f892298bd0d2bb162f902554f70536d26a471c4a96b7bd2

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

# coding: utf-8
require 'spec_helper'

describe 'Tree siblings / forest' do

  context 'Node' do
    it '::new with children' do
      children = I18n::Tasks::Data::Tree::Siblings.from_key_attr([['a', value: 1]])
      #require 'byebug'; byebug
      node = I18n::Tasks::Data::Tree::Node.new(
          key: 'fr',
          children: children
      )
      expect(node.to_siblings.first.children.first.parent.key).to eq 'fr'
    end
  end

  context 'a tree' do
    let(:a_hash) { {a: 1, b: {ba: 1, bb: 2}}.deep_stringify_keys }

    it '::from_nested_hash' do
      a = build_tree(a_hash)
      expect(a.to_hash).to eq(a_hash)
    end

    it '#derive' do
      a = build_tree(a_hash)
      b = a.derive.append! build_tree(c: 1)

      # a was not modified
      expect(a.to_hash).to eq(a_hash)
      # but b was
      expect(b.to_hash).to eq(a_hash.merge('c' => 1))
    end

    it '#merge' do
      a      = build_tree(a_hash)
      b_hash = {b: {bc: 1}, c: 1}.deep_stringify_keys
      expect(a.merge(build_tree(b_hash)).to_hash).to eq(a_hash.deep_merge(b_hash))
    end

    it '#intersect' do
      x = {a: 1, b: {ba: 1, bb: 2}}
      y = {b: {ba: 1, bc: 3}, c: 1}
      intersection = {b: {ba: 1}}.deep_stringify_keys
      a = build_tree(x)
      b = build_tree(y)
      expect(a.intersect_keys(b, root: true).to_hash).to eq(intersection)
    end

    it '#select_keys' do
      expect(build_tree(a: 1, b: 1).select_keys {|k, node| k == 'b'}.to_hash).to eq({'b' => 1})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n-tasks-0.5.1 spec/locale_tree/siblings_spec.rb
i18n-tasks-0.5.0 spec/locale_tree/siblings_spec.rb