summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--MANIFEST1
-rw-r--r--test/ruby/test_env.rb84
3 files changed, 89 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f2cdc0b..8bf6e96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Nov 28 17:59:20 2003 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * test/ruby/test_env.rb: add tests for ENV.
+
Fri Nov 28 17:47:46 2003 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* lib/drb/drb.rb (DRbMessage#load): rescue Errno::* and raise
diff --git a/MANIFEST b/MANIFEST
index 3e2dbe5..cb8d44d 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -664,6 +664,7 @@ test/ruby/test_clone.rb
test/ruby/test_condition.rb
test/ruby/test_const.rb
test/ruby/test_defined.rb
+test/ruby/test_env.rb
test/ruby/test_eval.rb
test/ruby/test_exception.rb
test/ruby/test_file.rb
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb
new file mode 100644
index 0000000..6a7fd97
--- /dev/null
+++ b/test/ruby/test_env.rb
@@ -0,0 +1,84 @@
+require 'test/unit'
+
+$KCODE = 'none'
+
+class TestEnv < Test::Unit::TestCase
+ IGNORE_CASE = /djgpp|bccwin|mswin|mingw|emx/ =~ RUBY_PLATFORM
+
+ 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)
+
+ 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)
+
+ 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