diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-04 17:09:45 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-04 17:09:45 +0000 |
commit | f6b4cba666b1cfb6dc6f8e2f9d57928c6d640ba5 (patch) | |
tree | af53039f659ca5d9f3d0396e4ffee797f7cf534d | |
parent | 0958923530594873703ccaec9ab92aa623f5578f (diff) | |
download | ruby-f6b4cba666b1cfb6dc6f8e2f9d57928c6d640ba5.tar.gz |
* parse.y (lex_getline, parser_set_encode): set encoding of lines
in SCRIPT_LINES__ as source encoding. [ruby-dev:43168]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | parse.y | 10 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 59 |
3 files changed, 74 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Sat Feb 5 02:09:39 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * parse.y (lex_getline, parser_set_encode): set encoding of lines + in SCRIPT_LINES__ as source encoding. [ruby-dev:43168] + Sat Feb 5 02:08:37 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> * vm.c (ruby_thread_data_type): add prefix. @@ -5220,6 +5220,7 @@ lex_getline(struct parser_params *parser) must_be_ascii_compatible(line); #ifndef RIPPER if (ruby_debug_lines) { + rb_enc_associate(line, parser->enc); rb_ary_push(ruby_debug_lines, line); } if (ruby_coverage) { @@ -6246,6 +6247,15 @@ parser_set_encode(struct parser_params *parser, const char *name) goto error; } parser->enc = enc; +#ifndef RIPPER + if (ruby_debug_lines) { + long i, n = RARRAY_LEN(ruby_debug_lines); + const VALUE *p = RARRAY_PTR(ruby_debug_lines); + for (i = 0; i < n; ++i) { + rb_enc_associate_index(*p, idx); + } + } +#endif } static int diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index e25ad75f7a..4624920536 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -19,4 +19,63 @@ class TestSyntax < Test::Unit::TestCase end end end + + def test_must_ascii_compatible + require 'tempfile' + f = Tempfile.new("must_ac_") + Encoding.list.each do |enc| + next unless enc.ascii_compatible? + make_tmpsrc(f, "# -*- coding: #{enc.name} -*-") + assert_nothing_raised(ArgumentError, enc.name) {load(f.path)} + end + Encoding.list.each do |enc| + next if enc.ascii_compatible? + make_tmpsrc(f, "# -*- coding: #{enc.name} -*-") + assert_raise(ArgumentError, enc.name) {load(f.path)} + end + f.close! + end + + def test_script_lines + require 'tempfile' + f = Tempfile.new("bug4361_") + bug4361 = '[ruby-dev:43168]' + with_script_lines do |debug_lines| + Encoding.list.each do |enc| + next unless enc.ascii_compatible? + make_tmpsrc(f, "# -*- coding: #{enc.name} -*-\n#----------------") + load(f.path) + assert_equal([f.path], debug_lines.keys) + assert_equal([enc, enc], debug_lines[f.path].map(&:encoding), bug4361) + end + end + f.close! + end + + private + + def make_tmpsrc(f, src) + f.open + f.truncate(0) + f.puts(src) + f.close + end + + def with_script_lines + script_lines = nil + debug_lines = {} + Object.class_eval do + if defined?(SCRIPT_LINES__) + script_lines = SCRIPT_LINES__ + remove_const :SCRIPT_LINES__ + end + const_set(:SCRIPT_LINES__, debug_lines) + end + yield debug_lines + ensure + Object.class_eval do + remove_const :SCRIPT_LINES__ + const_set(:SCRIPT_LINES__, script_lines) if script_lines + end + end end |