summaryrefslogtreecommitdiff
path: root/test/ruby/test_basicinstructions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_basicinstructions.rb')
-rw-r--r--test/ruby/test_basicinstructions.rb39
1 files changed, 32 insertions, 7 deletions
diff --git a/test/ruby/test_basicinstructions.rb b/test/ruby/test_basicinstructions.rb
index 4a1dc9ce12..f6b69cc1e5 100644
--- a/test/ruby/test_basicinstructions.rb
+++ b/test/ruby/test_basicinstructions.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
require 'test/unit'
ConstTest = 3
@@ -116,7 +117,6 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_equal({1=>2}, {1=>2})
assert_equal({1=>2, 3=>4}, {1=>2, 3=>4})
assert_equal({1=>2, 3=>4}, {3=>4, 1=>2})
- # assert_equal({1=>2, 3=>4}, {1,2, 3,4}) # 1.9 doesn't support
assert_equal({"key"=>"val"}, {"key"=>"val"})
end
@@ -210,9 +210,9 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_raise(NameError) { a }
assert_raise(NameError) { b }
assert_raise(NameError) { c }
- a = "NOT OK"
- b = "NOT OK"
- c = "NOT OK"
+ a = a = "NOT OK"
+ b = b = "NOT OK"
+ c = c = "NOT OK"
end
class Const
@@ -428,7 +428,9 @@ class TestBasicInstructions < Test::Unit::TestCase
end
class CVarA
- @@cv = 'CVarA@@cv'
+ def self.setup
+ @@cv = 'CVarA@@cv'
+ end
def self.cv() @@cv end
def self.cv=(v) @@cv = v end
class << self
@@ -449,6 +451,7 @@ class TestBasicInstructions < Test::Unit::TestCase
end
def test_class_variable
+ CVarA.setup
assert_equal 'CVarA@@cv', CVarA.cv
assert_equal 'CVarA@@cv', CVarA.cv2
assert_equal 'CVarA@@cv', CVarA.new.cv
@@ -610,8 +613,8 @@ class TestBasicInstructions < Test::Unit::TestCase
x = OP.new
assert_equal 42, x.foo = 42, bug7773
assert_equal 42, x.foo, bug7773
- assert_equal -6, x.send(:foo=, -6), bug7773
- assert_equal -6, x.foo, bug7773
+ assert_equal (-6), x.send(:foo=, -6), bug7773
+ assert_equal (-6), x.foo, bug7773
assert_equal :Bug1996, x.send(:x=, :case_when_setter_returns_other_value), bug7773
assert_equal :case_when_setter_returns_other_value, x.x, bug7773
end
@@ -697,4 +700,26 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_equal [], [*a]
assert_equal [1], [1, *a]
end
+
+ def test_special_const_instance_variables
+ assert_separately(%w(-W0), <<-INPUT, timeout: 60)
+ module M
+ def get
+ # we can not set instance variables on special const objects.
+ # However, we can access instance variables with default value (nil).
+ @ivar
+ end
+ end
+ class Integer; include M; end
+ class Float; include M; end
+ class Symbol; include M; end
+ class FalseClass; include M; end
+ class TrueClass; include M; end
+ class NilClass; include M; end
+
+ [123, 1.2, :sym, false, true, nil].each{|obj|
+ assert_equal(nil, obj.get)
+ }
+ INPUT
+ end
end