require_relative '../spec_helper' require 'flydata-core/fluent/config_helper' module FlydataCore::Fluent describe ConfigHelper do describe '.escape_conf' do let(:input) { "" } let(:output) { "" } subject { ConfigHelper.escape_conf(input) } shared_examples 'escape conf expectedly' do it { is_expected.to eq(output) } end context 'when input contains escape characters' do let(:input) { %Q|aa\nbb\r\ncc\tdd"ee\\ff| } let(:output) { %Q|aa\\nbb\\r\\ncc\\tdd\\"ee\\\\ff| } it_behaves_like 'escape conf expectedly' end context 'when input does not contain escape characters' do let(:input) { %Q|aabbccddeeff| } let(:output) { %Q|aabbccddeeff| } it_behaves_like 'escape conf expectedly' end context 'when input is nil' do let(:input) { nil } it { is_expected.to eq("") } end context 'when input is empty' do let(:input) { "" } it { is_expected.to eq("") } end end describe '.unescape_conf' do let(:input) { "" } let(:output) { "" } subject { ConfigHelper.unescape_conf(input) } shared_examples 'unescape conf expectedly' do it { is_expected.to eq(output) } end context 'when input contains escaped characters' do let(:input) { %Q|aa\\nbb\\r\\ncc\\tdd\\"ee\\\\ff| } let(:output) { %Q|aa\nbb\r\ncc\tdd"ee\\ff| } it_behaves_like 'unescape conf expectedly' end context 'when input does not contain escape characters' do let(:input) { %Q|aabbccddeeff| } let(:output) { %Q|aabbccddeeff| } it_behaves_like 'unescape conf expectedly' end context 'when input is nil' do let(:input) { nil } it { is_expected.to eq("") } end context 'when input is empty' do let(:input) { "" } it { is_expected.to eq("") } end end end end