mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #4328 from shuujii/fix-constant-name-validation
Fix constant name validation
This commit is contained in:
+10
-14
@@ -210,6 +210,7 @@ assert('Module#const_defined?', '15.2.2.4.20') do
|
||||
|
||||
assert_true Test4ConstDefined.const_defined?(:Const4Test4ConstDefined)
|
||||
assert_false Test4ConstDefined.const_defined?(:NotExisting)
|
||||
assert_raise(NameError){ Test4ConstDefined.const_defined?(:wrong_name) }
|
||||
end
|
||||
|
||||
assert('Module#const_get', '15.2.2.4.21') do
|
||||
@@ -224,6 +225,7 @@ assert('Module#const_get', '15.2.2.4.21') do
|
||||
assert_raise(TypeError){ Test4ConstGet.const_get(123) }
|
||||
assert_raise(NameError){ Test4ConstGet.const_get(:I_DO_NOT_EXIST) }
|
||||
assert_raise(NameError){ Test4ConstGet.const_get("I_DO_NOT_EXIST::ME_NEITHER") }
|
||||
assert_raise(NameError){ Test4ConstGet.const_get(:wrong_name) }
|
||||
end
|
||||
|
||||
assert('Module#const_set', '15.2.2.4.23') do
|
||||
@@ -233,6 +235,9 @@ assert('Module#const_set', '15.2.2.4.23') do
|
||||
|
||||
assert_equal 23, Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
|
||||
assert_equal 23, Test4ConstSet.const_get(:Const4Test4ConstSet)
|
||||
["", "wrongNAME", "Wrong-Name"].each do |n|
|
||||
assert_raise(NameError) { Test4ConstSet.const_set(n, 1) }
|
||||
end
|
||||
end
|
||||
|
||||
assert('Module#remove_const', '15.2.2.4.40') do
|
||||
@@ -240,21 +245,12 @@ assert('Module#remove_const', '15.2.2.4.40') do
|
||||
ExistingConst = 23
|
||||
end
|
||||
|
||||
result = Test4RemoveConst.module_eval { remove_const :ExistingConst }
|
||||
|
||||
name_error = false
|
||||
begin
|
||||
Test4RemoveConst.module_eval { remove_const :NonExistingConst }
|
||||
rescue NameError
|
||||
name_error = true
|
||||
assert_equal 23, Test4RemoveConst.remove_const(:ExistingConst)
|
||||
assert_false Test4RemoveConst.const_defined?(:ExistingConst)
|
||||
assert_raise(NameError) { Test4RemoveConst.remove_const(:NonExistingConst) }
|
||||
%i[x X!].each do |n|
|
||||
assert_raise(NameError) { Test4RemoveConst.remove_const(n) }
|
||||
end
|
||||
|
||||
# Constant removed from Module
|
||||
assert_false Test4RemoveConst.const_defined? :ExistingConst
|
||||
# Return value of binding
|
||||
assert_equal 23, result
|
||||
# Name Error raised when Constant doesn't exist
|
||||
assert_true name_error
|
||||
end
|
||||
|
||||
assert('Module#const_missing', '15.2.2.4.22') do
|
||||
|
||||
Reference in New Issue
Block a user