Refine ENV tests

This commit is contained in:
Nobuyoshi Nakada 2024-12-26 13:02:29 +09:00
parent 16665c3623
commit 037bffec07
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2024-12-26 04:52:52 +00:00

View File

@ -345,12 +345,16 @@ class TestEnv < Test::Unit::TestCase
ENV["foo"] = "bar" ENV["foo"] = "bar"
ENV["baz"] = "qux" ENV["baz"] = "qux"
s = ENV.inspect s = ENV.inspect
expected = [%("foo"=>"bar"), %("baz"=>"qux")]
unless s.start_with?(/\{"foo"/i)
expected.reverse!
end
expected = '{' + expected.join(', ') + '}'
if IGNORE_CASE if IGNORE_CASE
s = s.upcase s = s.upcase
assert(s == '{"FOO"=>"BAR", "BAZ"=>"QUX"}' || s == '{"BAZ"=>"QUX", "FOO"=>"BAR"}') expected = expected.upcase
else
assert(s == '{"foo"=>"bar", "baz"=>"qux"}' || s == '{"baz"=>"qux", "foo"=>"bar"}')
end end
assert_equal(expected, s)
end end
def test_to_a def test_to_a
@ -359,12 +363,7 @@ class TestEnv < Test::Unit::TestCase
ENV["baz"] = "qux" ENV["baz"] = "qux"
a = ENV.to_a a = ENV.to_a
assert_equal(2, a.size) assert_equal(2, a.size)
if IGNORE_CASE check([%w(baz qux), %w(foo bar)], a)
a = a.map {|x| x.map {|y| y.upcase } }
assert(a == [%w(FOO BAR), %w(BAZ QUX)] || a == [%w(BAZ QUX), %w(FOO BAR)])
else
assert(a == [%w(foo bar), %w(baz qux)] || a == [%w(baz qux), %w(foo bar)])
end
end end
def test_rehash def test_rehash
@ -450,13 +449,14 @@ class TestEnv < Test::Unit::TestCase
assert_equal(h1, h2) assert_equal(h1, h2)
end end
def check(as, bs) def assert_equal_env(as, bs)
if IGNORE_CASE if IGNORE_CASE
as = as.map {|k, v| [k.upcase, v] } as = as.map {|k, v| [k.upcase, v] }
bs = bs.map {|k, v| [k.upcase, v] } bs = bs.map {|k, v| [k.upcase, v] }
end end
assert_equal(as.sort, bs.sort) assert_equal(as.sort, bs.sort)
end end
alias check assert_equal_env
def test_shift def test_shift
ENV.clear ENV.clear
@ -1089,12 +1089,16 @@ class TestEnv < Test::Unit::TestCase
Ractor.yield s Ractor.yield s
end end
s = r.take s = r.take
expected = ['"foo"=>"bar"', '"baz"=>"qux"']
unless s.start_with?(/\{"foo"/i)
expected.reverse!
end
expected = "{" + expected.join(', ') + "}"
if #{ignore_case_str} if #{ignore_case_str}
s = s.upcase s = s.upcase
assert(s == '{"FOO"=>"BAR", "BAZ"=>"QUX"}' || s == '{"BAZ"=>"QUX", "FOO"=>"BAR"}') expected = expected.upcase
else
assert(s == '{"foo"=>"bar", "baz"=>"qux"}' || s == '{"baz"=>"qux", "foo"=>"bar"}')
end end
assert_equal(expected, s)
end; end;
end end
@ -1109,12 +1113,13 @@ class TestEnv < Test::Unit::TestCase
end end
a = r.take a = r.take
assert_equal(2, a.size) assert_equal(2, a.size)
expected = [%w(baz qux), %w(foo bar)]
if #{ignore_case_str} if #{ignore_case_str}
a = a.map {|x| x.map {|y| y.upcase } } a = a.map {|x, y| [x.upcase, y]}
assert(a == [%w(FOO BAR), %w(BAZ QUX)] || a == [%w(BAZ QUX), %w(FOO BAR)]) expected.map! {|x, y| [x.upcase, y]}
else
assert(a == [%w(foo bar), %w(baz qux)] || a == [%w(baz qux), %w(foo bar)])
end end
a.sort!
assert_equal(expected, a)
end; end;
end end