require 'spec_helper' require 'flydata/json/json_ext' describe JSON do describe '.generate_kv_pairs' do subject { described_class.generate_kv_pairs(keys, values) } context 'testing values' do let(:keys) { ['test'] } let(:values) { [ value ] } let(:expected_result) { %Q|{"test":"#{expected_value}"}| } shared_examples 'producing the expected result' do it do is_expected.to eq expected_result end end context 'regular string' do let(:value) { "a regular text" } let(:expected_value) { value } it_behaves_like "producing the expected result" end context 'regular UTF-8 2 byte chars' do let(:value) { "¢Àø" } let(:expected_value) { value } it_behaves_like "producing the expected result" end context 'regular UTF-8 3 byte chars' do let(:value) { "三国一" } let(:expected_value) { value } it_behaves_like "producing the expected result" end context '/' do let(:value) { "/" } let(:expected_value) { "\\/" } it_behaves_like "producing the expected result" end context '\\' do let(:value) { "\\" } let(:expected_value) { "\\\\" } it_behaves_like "producing the expected result" end context '"' do let(:value) { "\"" } let(:expected_value) { "\\\"" } it_behaves_like "producing the expected result" end context '\'' do let(:value) { "'" } let(:expected_value) { "'" } it_behaves_like "producing the expected result" end context '\b' do let(:value) { "\b" } let(:expected_value) { "\\b" } it_behaves_like "producing the expected result" end context '\x02' do let(:value) { "\x02" } let(:expected_value) { "\\u0002" } it_behaves_like "producing the expected result" end context '^\\' do let(:value) { "\x1c" } let(:expected_value) { "\\u001c" } it_behaves_like "producing the expected result" end end end end