mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
0958923530
commit
f6b4cba666
3 changed files with 74 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue