1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# frozen_string_literal: true
require_relative '../test_helper'
describe IpynbDiff::SymbolMap do
def res(*cases)
cases&.to_h || []
end
describe '.parse' do
subject(:symbol_map) { described_class.parse(JSON.pretty_generate(source)) }
context 'when object has blank key' do
let(:source) { { "": { "": 5 } } }
it { is_expected.to match_array(res([".", 2], ["..", 3])) }
end
context 'when object is empty' do
let(:source) { {} }
it { is_expected.to be_empty }
end
context 'when object is empty array' do
let(:source) { [] }
it { is_expected.to be_empty }
end
context 'when object has inner object and number' do
let(:source) { { obj1: { obj2: 1 } } }
it { is_expected.to match_array(res(['.obj1', 2], ['.obj1.obj2', 3])) }
end
context 'when object has inner object and number, string and array with object' do
let(:source) { { obj1: { obj2: [123, 2, true], obj3: "hel\nlo", obj4: true, obj5: 123, obj6: 'a' } } }
specify do
expect(symbol_map).to match_array(
res(['.obj1', 2],
['.obj1.obj2', 3],
['.obj1.obj2.0', 4],
['.obj1.obj2.1', 5],
['.obj1.obj2.2', 6],
['.obj1.obj3', 8],
['.obj1.obj4', 9],
['.obj1.obj5', 10],
['.obj1.obj6', 11])
)
end
end
end
end
|