59 lines
1.6 KiB
Ruby
59 lines
1.6 KiB
Ruby
RSpec.describe FlatKeys do
|
|
describe '#as_nested_structure' do
|
|
it "works" do
|
|
result = FlatKeys.as_nested_structure([
|
|
'root_one',
|
|
'inventories.location.site',
|
|
'ppls.distribution_cables',
|
|
'dslams.port_spec',
|
|
'root_two',
|
|
'dslams.other_spec',
|
|
'root_three',
|
|
#'dslams.other_spec.and_then.some', # should raise
|
|
'very.deep.nested.structure.just.because.we.can',
|
|
'very.deep.nested.structure.with.other.tail',
|
|
'start.with.more.than.what.comes.after',
|
|
'start.with.more.than.what.comes',
|
|
'start.with.less.than.what.comes',
|
|
'start.with.less.than.what.comes2.after',
|
|
'start.with.less.than.what.comes.after',
|
|
'start.with.less.than.what.comes2.after', # duplicate, should be no problem
|
|
])
|
|
|
|
expect( result ).to eq [
|
|
:root_one,
|
|
:root_two,
|
|
:root_three,
|
|
{
|
|
inventories: {location: :site},
|
|
ppls: :distribution_cables,
|
|
dslams: [:port_spec, :other_spec],
|
|
very: {
|
|
deep: {
|
|
nested: {
|
|
structure: {
|
|
just: {
|
|
because: {we: :can}
|
|
},
|
|
with: {other: :tail}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
start: {
|
|
with: {
|
|
more: {
|
|
than: {what: {comes: :after}}
|
|
},
|
|
less: {
|
|
than: {what: {comes: :after, comes2: :after}}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
end
|
|
|
|
end
|
|
end
|