diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-10 00:41:47 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-10 00:41:47 +0000 |
commit | f852af0e59899157ef695edccbe86d51fc04d23b (patch) | |
tree | 64f6b3a62e8525c3d44fc6b69900400fcb7c3fa2 /test | |
parent | 44c01a5d3fda7feca63e28c04baca9c9e2dd64b3 (diff) | |
download | ruby-f852af0e59899157ef695edccbe86d51fc04d23b.tar.gz |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_parse.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 7229d0acb5..b05dbe2a0f 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -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")}} |