symbol.c: non-ASCII constant names

* symbol.c (rb_sym_constant_char_p): support for non-ASCII
  constant names.  [Feature #13770]

* object.c (rb_mod_const_get, rb_mod_const_defined): support for
  non-ASCII constant names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-04-10 00:41:47 +00:00
parent 44c01a5d3f
commit f852af0e59
4 changed files with 80 additions and 3 deletions

View file

@ -1157,6 +1157,45 @@ x = __ENCODING__
end;
end
NONASCII_CONSTANTS = [
*%W"\u{00de} \u{00C0}".flat_map {|c| [c, c.encode("iso-8859-15")]},
"\u{1c4}", "\u{1f2}", "\u{1f88}", "\u{370}",
*%W"\u{391} \u{ff21}".flat_map {|c| [c, c.encode("cp932"), c.encode("euc-jp")]},
]
def assert_nonascii_const
assert_all_assertions_foreach("NONASCII_CONSTANTS", *NONASCII_CONSTANTS) do |n|
m = Module.new
assert_not_operator(m, :const_defined?, n)
assert_raise_with_message(NameError, /uninitialized/) do
m.const_get(n)
end
assert_nil(eval("defined?(m::#{n})"))
v = yield m, n
assert_operator(m, :const_defined?, n)
assert_equal("constant", eval("defined?(m::#{n})"))
assert_same(v, m.const_get(n))
m.__send__(:remove_const, n)
assert_not_operator(m, :const_defined?, n)
assert_nil(eval("defined?(m::#{n})"))
end
end
def test_nonascii_const_set
assert_nonascii_const do |m, n|
m.const_set(n, 42)
end
end
def test_nonascii_constant
assert_nonascii_const do |m, n|
m.module_eval("class #{n}; self; end")
end
end
=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}