[前][次][番号順一覧][スレッド一覧]

ruby-changes:19363

From: yugui <ko1@a...>
Date: Sun, 1 May 2011 18:37:34 +0900 (JST)
Subject: [ruby-changes:19363] Ruby:r31403 (ruby_1_9_2): merges r30784 from trunk into ruby_1_9_2.

yugui	2011-05-01 18:37:12 +0900 (Sun, 01 May 2011)

  New Revision: 31403

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31403

  Log:
    merges r30784 from trunk into ruby_1_9_2.
    --
    * parse.y (lex_getline, parser_set_encode): set encoding of lines
      in SCRIPT_LINES__ as source encoding.  [ruby-dev:43168]

  Added files:
    branches/ruby_1_9_2/test/ruby/test_syntax.rb
  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/parse.y
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 31402)
+++ ruby_1_9_2/ChangeLog	(revision 31403)
@@ -1,3 +1,8 @@
+Sat Feb  5 02:09:39 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (lex_getline, parser_set_encode): set encoding of lines
+	  in SCRIPT_LINES__ as source encoding.  [ruby-dev:43168]
+
 Wed Apr  6 21:25:08 2011  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* thread.c (thread_s_kill): workaround for [ruby-core:35086].
Index: ruby_1_9_2/parse.y
===================================================================
--- ruby_1_9_2/parse.y	(revision 31402)
+++ ruby_1_9_2/parse.y	(revision 31403)
@@ -5204,6 +5204,7 @@
     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) {
@@ -6239,6 +6240,15 @@
 	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
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 31402)
+++ ruby_1_9_2/version.h	(revision 31403)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 190
+#define RUBY_PATCHLEVEL 191
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/ruby/test_syntax.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_syntax.rb	(revision 0)
+++ ruby_1_9_2/test/ruby/test_syntax.rb	(revision 31403)
@@ -0,0 +1,81 @@
+require 'test/unit'
+
+class TestSyntax < Test::Unit::TestCase
+  def valid_syntax?(code, fname)
+    code = code.dup.force_encoding("ascii-8bit")
+    code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
+      "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
+    }
+    code.force_encoding("us-ascii")
+    catch {|tag| eval(code, binding, fname, 0)}
+  rescue SyntaxError
+    false
+  end
+
+  def test_syntax
+    assert_nothing_raised(Exception) do
+      for script in Dir[File.expand_path("../../../{lib,sample,ext,test}/**/*.rb", __FILE__)].sort
+        assert(valid_syntax?(IO::read(script), script))
+      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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]