1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_env.rb
nobu 05d8e212b1 * test/ruby/test_env.rb (setup, teardown): do not depend on the behavior setting nil.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-07-14 23:29:45 +00:00

84 lines
2 KiB
Ruby

require 'test/unit'
class TestEnv < Test::Unit::TestCase
IGNORE_CASE = /djgpp|bccwin|mswin|mingw/ =~ RUBY_PLATFORM
def setup
@backup = ENV['test']
@BACKUP = ENV['TEST']
ENV.delete('test')
ENV.delete('TEST')
end
def teardown
ENV['test'] = @backup if @backup
ENV['TEST'] = @BACKUP if @BACKUP
end
def test_bracket
assert_nil(ENV['test'])
assert_nil(ENV['TEST'])
ENV['test'] = 'foo'
assert_equal('foo', ENV['test'])
if IGNORE_CASE
assert_equal('foo', ENV['TEST'])
else
assert_nil(ENV['TEST'])
end
ENV['TEST'] = 'bar'
assert_equal('bar', ENV['TEST'])
if IGNORE_CASE
assert_equal('bar', ENV['test'])
else
assert_equal('foo', ENV['test'])
end
assert_raises(TypeError) {
tmp = ENV[1]
}
assert_raises(TypeError) {
ENV[1] = 'foo'
}
assert_raises(TypeError) {
ENV['test'] = 0
}
end
def test_has_value
val = 'a'
val.succ! while ENV.has_value?(val) && ENV.has_value?(val.upcase)
ENV['test'] = val[0...-1]
assert_equal(false, ENV.has_value?(val))
assert_equal(false, ENV.has_value?(val.upcase))
ENV['test'] = val
assert_equal(true, ENV.has_value?(val))
assert_equal(false, ENV.has_value?(val.upcase))
ENV['test'] = val.upcase
assert_equal(false, ENV.has_value?(val))
assert_equal(true, ENV.has_value?(val.upcase))
end
def test_key
val = 'a'
val.succ! while ENV.has_value?(val) && ENV.has_value?(val.upcase)
ENV['test'] = val[0...-1]
assert_nil(ENV.key(val))
assert_nil(ENV.key(val.upcase))
ENV['test'] = val
if IGNORE_CASE
assert_equal('TEST', ENV.key(val).upcase)
else
assert_equal('test', ENV.key(val))
end
assert_nil(ENV.key(val.upcase))
ENV['test'] = val.upcase
assert_nil(ENV.key(val))
if IGNORE_CASE
assert_equal('TEST', ENV.key(val.upcase).upcase)
else
assert_equal('test', ENV.key(val.upcase))
end
end
end