2003-11-28 04:00:48 -05:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestEnv < Test::Unit::TestCase
|
2003-12-03 12:30:09 -05:00
|
|
|
IGNORE_CASE = /djgpp|bccwin|mswin|mingw/ =~ RUBY_PLATFORM
|
2003-11-28 04:00:48 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@backup = ENV['test']
|
|
|
|
@BACKUP = ENV['TEST']
|
|
|
|
ENV['test'] = nil
|
|
|
|
ENV['TEST'] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
ENV['test'] = @backup
|
|
|
|
ENV['TEST'] = @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)
|
2003-11-28 05:38:00 -05:00
|
|
|
ENV['test'] = val[0...-1]
|
2003-11-28 04:00:48 -05:00
|
|
|
|
|
|
|
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_index
|
|
|
|
val = 'a'
|
|
|
|
val.succ! while ENV.has_value?(val) && ENV.has_value?(val.upcase)
|
2003-11-28 05:38:00 -05:00
|
|
|
ENV['test'] = val[0...-1]
|
2003-11-28 04:00:48 -05:00
|
|
|
|
|
|
|
assert_nil(ENV.index(val))
|
|
|
|
assert_nil(ENV.index(val.upcase))
|
|
|
|
ENV['test'] = val
|
|
|
|
if IGNORE_CASE
|
|
|
|
assert_equal('TEST', ENV.index(val).upcase)
|
|
|
|
else
|
|
|
|
assert_equal('test', ENV.index(val))
|
|
|
|
end
|
|
|
|
assert_nil(ENV.index(val.upcase))
|
|
|
|
ENV['test'] = val.upcase
|
|
|
|
assert_nil(ENV.index(val))
|
|
|
|
if IGNORE_CASE
|
|
|
|
assert_equal('TEST', ENV.index(val.upcase).upcase)
|
|
|
|
else
|
|
|
|
assert_equal('test', ENV.index(val.upcase))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|