зеркало из https://github.com/github/ruby.git
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@18304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c6fb433c3f
Коммит
20486a7f64
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Fri Aug 01 18:27:15 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||
|
||||
* 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.
|
||||
|
||||
Fri Aug 1 14:54:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32/win32.c (rb_w32_seekdir): no need to rewind to seek forward.
|
||||
|
|
9
parse.y
9
parse.y
|
@ -6076,12 +6076,11 @@ parser_yylex(struct parser_params *parser)
|
|||
goto retry;
|
||||
|
||||
case '#': /* it's a comment */
|
||||
if (!parser->has_shebang || parser->line_count != 1) {
|
||||
/* no magic_comment in shebang line */
|
||||
/* no magic_comment in shebang line */
|
||||
if (parser->line_count == (parser->has_shebang ? 2 : 1)
|
||||
&& (lex_p - lex_pbeg) == 1) {
|
||||
if (!parser_magic_comment(parser, lex_p, lex_pend - lex_p)) {
|
||||
if (parser->line_count == (parser->has_shebang ? 2 : 1)) {
|
||||
set_file_encoding(parser, lex_p, lex_pend);
|
||||
}
|
||||
set_file_encoding(parser, lex_p, lex_pend);
|
||||
}
|
||||
}
|
||||
lex_p = lex_pend;
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче