Close #1 - Always return non-frozen strings

This commit is contained in:
Josh Holtrop 2016-04-19 08:52:02 -04:00
parent e852d2755c
commit 3709cc7fef
2 changed files with 30 additions and 3 deletions

View File

@ -129,10 +129,10 @@ module Yawpa
short_idx += 1 short_idx += 1
end end
elsif flags[:posix_order] elsif flags[:posix_order]
args = params[i, params.length] args = params[i, params.length].map(&:dup)
break break
else else
args << params[i] args << params[i].dup
end end
i += 1 i += 1
end end
@ -161,7 +161,7 @@ module Yawpa
while n_gathered < nargs.last and while n_gathered < nargs.last and
index < params.length and index < params.length and
params[index][0] != '-' do params[index][0] != '-' do
result << params[index] result << params[index].dup
index += 1 index += 1
num_indices_used += 1 num_indices_used += 1
n_gathered += 1 n_gathered += 1

View File

@ -230,5 +230,32 @@ describe Yawpa do
expect(opts).to eq(push: false, pull: true) expect(opts).to eq(push: false, pull: true)
expect(args).to eq(%w[arg]) expect(args).to eq(%w[arg])
end end
it "returns non-frozen strings" do
options = {
o1: {nargs: 1, short: "1"},
o2: {nargs: 1, short: "2"},
o3: {nargs: 1, short: "3"},
o4: {nargs: 1, short: "4"},
}
arguments = %w[--o1=one --o2 two -3 three -4four arg].map(&:freeze)
opts, args = Yawpa.parse(arguments, options)
expect(opts[:o1].frozen?).to be_falsey
expect{opts[:o1].sub!(/./, '-')}.to_not raise_error
expect(opts[:o2].frozen?).to be_falsey
expect{opts[:o2].sub!(/./, '-')}.to_not raise_error
expect(opts[:o3].frozen?).to be_falsey
expect{opts[:o3].sub!(/./, '-')}.to_not raise_error
expect(opts[:o4].frozen?).to be_falsey
expect{opts[:o4].sub!(/./, '-')}.to_not raise_error
expect(args[0].frozen?).to be_falsey
expect{args[0].sub!(/./, '-')}.to_not raise_error
opts, args = Yawpa.parse(arguments, options, posix_order: true)
expect(args[0].frozen?).to be_falsey
expect{args[0].sub!(/./, '-')}.to_not raise_error
end
end end
end end