spec/locale_tree/siblings_spec.rb in i18n-tasks-0.4.5 vs spec/locale_tree/siblings_spec.rb in i18n-tasks-0.5.0
- old
+ new
@@ -1,10 +1,22 @@
# 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)
@@ -20,11 +32,24 @@
# but b was
expect(b.to_hash).to eq(a_hash.merge('c' => 1))
end
it '#merge' do
- a = build_tree(a_hash)
+ 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