summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-01-28 21:29:55 +0900
committerKOBAYASHI Shuji <[email protected]>2019-01-28 21:29:55 +0900
commitabbc50143364dd84111573e594d24f6ace256eeb (patch)
treeda359578a20b9612f3edde4334323f6634e89674 /test
parent1b597f9da45aecfc4d02752629d93de1325d86a4 (diff)
downloadmruby-abbc50143364dd84111573e594d24f6ace256eeb.tar.gz
mruby-abbc50143364dd84111573e594d24f6ace256eeb.zip
`class`/`module` expression with empty body should return `nil`
Before: p(class A end) #=> A p(class << self; end) #=> #<Class:#<Object:0x7fdc3880e420>> p(module B end) #=> B After/Ruby: p(class A end) #=> nil p(class << self; end) #=> nil p(module B end) #=> nil
Diffstat (limited to 'test')
-rw-r--r--test/t/class.rb5
-rw-r--r--test/t/module.rb9
2 files changed, 14 insertions, 0 deletions
diff --git a/test/t/class.rb b/test/t/class.rb
index f37a891a4..6a0a3225c 100644
--- a/test/t/class.rb
+++ b/test/t/class.rb
@@ -236,6 +236,11 @@ assert('class to return the last value') do
assert_equal(m, :m)
end
+assert('class to return nil if body is empty') do
+ assert_nil(class C end)
+ assert_nil(class << self; end)
+end
+
assert('raise when superclass is not a class') do
module FirstModule; end
assert_raise(TypeError, 'should raise TypeError') do
diff --git a/test/t/module.rb b/test/t/module.rb
index 78cb5d07f..f01245e88 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -708,6 +708,15 @@ assert('module with non-class/module outer raises TypeError') do
assert_raise(TypeError) { module []::M2 end }
end
+assert('module to return the last value') do
+ m = module M; :m end
+ assert_equal(m, :m)
+end
+
+assert('module to return nil if body is empty') do
+ assert_nil(module M end)
+end
+
assert('get constant of parent module in singleton class; issue #3568') do
actual = module GetConstantInSingletonTest
EXPECTED = "value"