summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-01 09:38:50 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-01 09:38:50 +0000
commitc6a6e54f8f6240a6ed10610dff3f20181603c6b8 (patch)
treed7ddf0f388f75f38c741a64e0313f33a04833708 /test/ruby
parent18950f4523271de3e2576252bb013cb1c835142f (diff)
downloadruby-c6a6e54f8f6240a6ed10610dff3f20181603c6b8.tar.gz
ruby-c6a6e54f8f6240a6ed10610dff3f20181603c6b8.tar.xz
ruby-c6a6e54f8f6240a6ed10610dff3f20181603c6b8.zip
* parse.y (parser_yylex): removed an useless conditional, and magic
comment are ignored unless at the first of line. * test/ruby/test_m17n.rb (test_magic_comment_vim): added. * test/ruby/test_m17n.rb (test_magic_comment_at_variaous_positions): added. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_m17n.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index b2a67686a..f01b83873 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1192,6 +1192,24 @@ class TestM17N < Test::Unit::TestCase
assert_equal(Encoding::ASCII_8BIT, eval("# -*- encoding: ASCII-8BIT -*-\n__ENCODING__".force_encoding("US-ASCII")))
end
+ def test_magic_comment_vim
+ assert_equal(Encoding::US_ASCII, eval("# vim: filetype=ruby, fileencoding: US-ASCII, ts=3, sw=3\n__ENCODING__".force_encoding("ASCII-8BIT")))
+ assert_equal(Encoding::ASCII_8BIT, eval("# vim: filetype=ruby, fileencoding: ASCII-8BIT, ts=3, sw=3\n__ENCODING__".force_encoding("US-ASCII")))
+ end
+
+ def test_magic_comment_at_various_positions
+ # after shebang
+ assert_equal(Encoding::US_ASCII, eval("#!/usr/bin/ruby\n# -*- encoding: US-ASCII -*-\n__ENCODING__".force_encoding("ASCII-8BIT")))
+ assert_equal(Encoding::ASCII_8BIT, eval("#!/usr/bin/ruby\n# -*- encoding: ASCII-8BIT -*-\n__ENCODING__".force_encoding("US-ASCII")))
+ # wrong position
+ assert_equal(Encoding::ASCII_8BIT, eval("\n# -*- encoding: US-ASCII -*-\n__ENCODING__".force_encoding("ASCII-8BIT")))
+ assert_equal(Encoding::US_ASCII, eval("\n# -*- encoding: ASCII-8BIT -*-\n__ENCODING__".force_encoding("US-ASCII")))
+
+ # leading expressions
+ assert_equal(Encoding::ASCII_8BIT, eval("1+1 # -*- encoding: US-ASCII -*-\n__ENCODING__".force_encoding("ASCII-8BIT")))
+ assert_equal(Encoding::US_ASCII, eval("1+1 # -*- encoding: ASCII-8BIT -*-\n__ENCODING__".force_encoding("US-ASCII")))
+ end
+
def test_regexp_usascii
assert_regexp_usascii_literal('//', Encoding::US_ASCII)
assert_regexp_usascii_literal('/#{}/', Encoding::US_ASCII)