ruby-changes:6788
From: yugui <ko1@a...>
Date: Fri, 1 Aug 2008 18:39:10 +0900 (JST)
Subject: [ruby-changes:6788] Ruby:r18304 (trunk): * parse.y (parser_yylex): removed an useless conditional, and magic
yugui 2008-08-01 18:38:50 +0900 (Fri, 01 Aug 2008) New Revision: 18304 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18304 Log: * 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. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18303) +++ ChangeLog (revision 18304) @@ -1,3 +1,13 @@ +Fri Aug 01 18:27:15 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * 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@r...> * win32/win32.c (rb_w32_seekdir): no need to rewind to seek forward. Index: parse.y =================================================================== --- parse.y (revision 18303) +++ parse.y (revision 18304) @@ -6076,12 +6076,11 @@ 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; Index: test/ruby/test_m17n.rb =================================================================== --- test/ruby/test_m17n.rb (revision 18303) +++ test/ruby/test_m17n.rb (revision 18304) @@ -1192,6 +1192,24 @@ 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/