ruby-changes:25274
From: nobu <ko1@a...>
Date: Thu, 25 Oct 2012 19:07:39 +0900 (JST)
Subject: [ruby-changes:25274] nobu:r37326 (trunk): remove string literal concatenation
nobu 2012-10-25 19:07:22 +0900 (Thu, 25 Oct 2012) New Revision: 37326 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37326 Log: remove string literal concatenation Modified files: trunk/bootstraptest/runner.rb trunk/bootstraptest/test_syntax.rb trunk/lib/matrix.rb trunk/lib/mkmf.rb trunk/lib/net/http/generic_request.rb trunk/lib/rss/rss.rb trunk/sample/test.rb trunk/test/json/test_json.rb trunk/test/misc/test_ruby_mode.rb trunk/test/ripper/test_scanner_events.rb trunk/test/ruby/envutil.rb trunk/test/ruby/test_literal.rb trunk/test/ruby/test_parse.rb trunk/test/ruby/test_rubyoptions.rb trunk/test/ruby/test_stringchar.rb trunk/test/ruby/test_syntax.rb Index: bootstraptest/test_syntax.rb =================================================================== --- bootstraptest/test_syntax.rb (revision 37325) +++ bootstraptest/test_syntax.rb (revision 37326) @@ -525,7 +525,7 @@ } def assert_syntax_error expected, code, message = '' assert_equal "#{expected}", - "begin eval(%q{#{code}}, nil, '', 0)"'; rescue SyntaxError => e; e.message[/\A:(?:\d+:)? (.*)/, 1] end', message + "begin eval(%q{#{code}}, nil, '', 0); rescue SyntaxError => e; e.message[/\\A:(?:\\d+:)? (.*)/, 1] end", message end assert_syntax_error "unterminated string meets end of file", '().."', '[ruby-dev:29732]' assert_equal %q{[]}, %q{$&;[]}, '[ruby-dev:31068]' Index: bootstraptest/runner.rb =================================================================== --- bootstraptest/runner.rb (revision 37325) +++ bootstraptest/runner.rb (revision 37326) @@ -1,4 +1,5 @@ -"exec" "${RUBY-ruby}" "-x" "$0" "$@" || true # -*- mode: ruby; coding: utf-8 -*- +#!/bin/sh +exec "${RUBY-ruby}" -x "$0" "$@" # -*- mode: ruby; coding: utf-8 -*- #!./ruby # $Id$ Index: sample/test.rb =================================================================== --- sample/test.rb (revision 37325) +++ sample/test.rb (revision 37326) @@ -1612,10 +1612,6 @@ test_ok("abcd" == "abcd") test_ok("abcd" =~ /abcd/) test_ok("abcd" === "abcd") -# compile time string concatenation -test_ok("ab" "cd" == "abcd") -test_ok("#{22}aa" "cd#{44}" == "22aacd44") -test_ok("#{22}aa" "cd#{44}" "55" "#{66}" == "22aacd445566") test_ok("abc" !~ /^$/) test_ok("abc\n" !~ /^$/) test_ok("abc" !~ /^d*$/) Index: lib/rss/rss.rb =================================================================== --- lib/rss/rss.rb (revision 37325) +++ lib/rss/rss.rb (revision 37326) @@ -591,10 +591,10 @@ def #{accessor_name}=(*args) receiver = self.class.name - warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " \ - "Don't use `\#{receiver}\##{accessor_name} = XXX'/" \ - "`\#{receiver}\#set_#{accessor_name}(XXX)'. " \ - "Those APIs are not sense of Ruby. " \ + warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " << + "Don't use `\#{receiver}\##{accessor_name} = XXX'/" << + "`\#{receiver}\#set_#{accessor_name}(XXX)'. " << + "Those APIs are not sense of Ruby. " << "Use `\#{receiver}\##{plural_name} << XXX' instead of them.") if args.size == 1 @#{accessor_name}.push(args[0]) Index: lib/mkmf.rb =================================================================== --- lib/mkmf.rb (revision 37325) +++ lib/mkmf.rb (revision 37326) @@ -1026,7 +1026,7 @@ # def have_framework(fw, &b) checking_for fw do - src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}" + src = cpp_include("#{fw}/#{fw}.h") << "\n#{''}int main(void){return 0;}" opt = " -framework #{fw}" if try_link(src, "-ObjC#{opt}", &b) $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp)) @@ -1761,7 +1761,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} } if $extmk - mk << "RUBYLIB =\n""RUBYOPT = -\n" + mk << "RUBYLIB =\n#{''}RUBYOPT = -\n" end prefix = mkintpath(CONFIG["prefix"]) if destdir = prefix[$dest_prefix_pattern, 1] @@ -2376,7 +2376,7 @@ EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip} - hdr = ['#include "ruby.h"' "\n"] + hdr = ["#include \"ruby.h\"\n"] config_string('COMMON_MACROS') do |s| Shellwords.shellwords(s).each do |w| w, v = w.split(/=/, 2) @@ -2396,13 +2396,13 @@ COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<' COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<' TRY_LINK = config_string('TRY_LINK') || - "$(CC) #{OUTFLAG}conftest#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) " \ + "$(CC) #{OUTFLAG}conftest#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) " << "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)" LINK_SO = config_string('LINK_SO') || if CONFIG["DLEXT"] == $OBJEXT "ld $(DLDFLAGS) -r -o $@ $(OBJS)\n" else - "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " \ + "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " << "$(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)" end LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L%s' Index: lib/net/http/generic_request.rb =================================================================== --- lib/net/http/generic_request.rb (revision 37325) +++ lib/net/http/generic_request.rb (revision 37326) @@ -186,9 +186,7 @@ if filename filename = quote_string(filename, charset) type = h[:content_type] || 'application/octet-stream' - buf << "Content-Disposition: form-data; " \ - "name=\"#{key}\"; filename=\"#{filename}\"\r\n" \ - "Content-Type: #{type}\r\n\r\n" + buf << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{filename}\"\r\nContent-Type: #{type}\r\n\r\n" if !out.respond_to?(:write) || !value.respond_to?(:read) # if +out+ is not an IO or +value+ is not an IO buf << (value.respond_to?(:read) ? value.read : value) Index: lib/matrix.rb =================================================================== --- lib/matrix.rb (revision 37325) +++ lib/matrix.rb (revision 37326) @@ -1404,8 +1404,7 @@ begin ret = obj.__send__(meth) rescue Exception => e - raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \ - "(#{e.message})" + raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n(#{e.message})" end raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls ret Index: test/ruby/test_literal.rb =================================================================== --- test/ruby/test_literal.rb (revision 37325) +++ test/ruby/test_literal.rb (revision 37326) @@ -56,6 +56,7 @@ assert_equal "\n", "\n" bug2500 = '[ruby-core:27228]' bug5262 = '[ruby-core:39222]' + verbose, $VERBOSE = $VERBOSE, nil %w[c C- M-].each do |pre| ["u", %w[u{ }]].each do |open, close| ["?", ['"', '"']].each do |qopen, qclose| @@ -89,6 +90,8 @@ assert_equal "\u201c", eval(%[?\\\u{201c}]), bug6069 assert_equal "\u201c".encode("euc-jp"), eval(%[?\\\u{201c}].encode("euc-jp")), bug6069 assert_equal "\u201c".encode("iso-8859-13"), eval(%[?\\\u{201c}].encode("iso-8859-13")), bug6069 + ensure + $VERBOSE = verbose end def test_dstring Index: test/ruby/test_stringchar.rb =================================================================== --- test/ruby/test_stringchar.rb (revision 37325) +++ test/ruby/test_stringchar.rb (revision 37326) @@ -5,10 +5,6 @@ assert_equal("abcd", "abcd") assert_match(/abcd/, "abcd") assert("abcd" === "abcd") - # compile time string concatenation - assert_equal("abcd", "ab" "cd") - assert_equal("22aacd44", "#{22}aa" "cd#{44}") - assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}") assert("abc" !~ /^$/) assert("abc\n" !~ /^$/) assert("abc" !~ /^d*$/) Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 37325) +++ test/ruby/test_syntax.rb (revision 37326) @@ -118,7 +118,7 @@ def test_warn_unreachable assert_warn("test:3: warning: statement not reached\n") do - code = "loop do\n" "break\n" "foo\n" "end" + code = "loop do\nbreak\nfoo\nend" assert_valid_syntax(code, "test") {$VERBOSE = true} end end Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 37325) +++ test/ruby/envutil.rb (revision 37326) @@ -209,9 +209,9 @@ "-v", "-", ] cmd = [ - 'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}', + %Q[END {STDERR.puts #{token_dump}+"FINAL=\#{Memory::Status.new.size}"}], prepare, - 'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")', + %Q[STDERR.puts(#{token_dump}+"START=\#{$initial_size = Memory::Status.new.size}")], code, ].join("\n") _, err, status = EnvUtil.invoke_ruby(args, cmd, true, true) Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 37325) +++ test/ruby/test_rubyoptions.rb (revision 37326) @@ -303,9 +303,9 @@ end bug4118 = '[ruby-dev:42680]' - assert_in_out_err(%w[], "#!/bin/sh\n""#!shebang\n""#!ruby\n""puts __LINE__\n", + assert_in_out_err(%w[], "#!/bin/sh\n#!shebang\n#!ruby\nputs __LINE__\n", %w[4], [], bug4118) - assert_in_out_err(%w[-x], "#!/bin/sh\n""#!shebang\n""#!ruby\n""puts __LINE__\n", + assert_in_out_err(%w[-x], "#!/bin/sh\n#!shebang\n#!ruby\nputs __LINE__\n", %w[4], [], bug4118) end @@ -498,22 +498,22 @@ assert_in_out_err(["-we", "def foo\n eval('a=1')\nend"], "", [], [], feature3446) assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], [], feature3446) assert_in_out_err(["-we", "def foo\n 1.times do\n a=1\n end\nend"], "", [], ["-e:3: warning: assigned but unused variable - a"], feature3446) - assert_in_out_err(["-we", "def foo\n"" 1.times do |a| end\n""end"], "", [], []) + assert_in_out_err(["-we", "def foo\n 1.times do |a| end\nend"], "", [], []) feature6693 = '[ruby-core:46160]' assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], [], feature6693) end def test_shadowing_variable bug4130 = '[ruby-dev:42718]' - assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n"" a\n""end"], + assert_in_out_err(["-we", "def foo\n a=1\n 1.times do |a| end\n a\nend"], "", [], ["-e:3: warning: shadowing outer local variable - a"], bug4130) - assert_in_out_err(["-we", "def foo\n"" a=1\n"" 1.times do |a| end\n""end"], + assert_in_out_err(["-we", "def foo\n a=1\n 1.times do |a| end\nend"], "", [], ["-e:3: warning: shadowing outer local variable - a", "-e:2: warning: assigned but unused variable - a", ], bug4130) feature6693 = '[ruby-core:46160]' - assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"], + assert_in_out_err(["-we", "def foo\n _a=1\n 1.times do |_a| end\nend"], "", [], [], feature6693) end Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 37325) +++ test/ruby/test_parse.rb (revision 37326) @@ -560,7 +560,7 @@ end assert_nothing_raised do - eval "x = <<""FOO\r\n1\r\nFOO" + eval "x = <\<FOO\r\n1\r\nFOO" end assert_equal("1\n", x) end Index: test/json/test_json.rb =================================================================== --- test/json/test_json.rb (revision 37325) +++ test/json/test_json.rb (revision 37326) @@ -42,8 +42,7 @@ 'h' => 1000.0, 'i' => 0.001 } - @json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\ - '"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}' + @json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}' end def test_construction @@ -190,8 +189,7 @@ assert_equal([1], parse('[1]')) assert_equal([1], parse(' [ 1 ] ')) assert_equal(@ary, - parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]]'\ - ',[false],[true]]')) + parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]],[false],[true]]')) assert_equal(@ary, parse(%Q{ [ [1] , ["foo"] , [3.14] \t , [47.11e+2]\s , [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] })) end Index: test/misc/test_ruby_mode.rb =================================================================== --- test/misc/test_ruby_mode.rb (revision 37325) +++ test/misc/test_ruby_mode.rb (revision 37326) @@ -19,10 +19,10 @@ EVAL_OPT = "--eval" EXPR_SAVE = "(save-buffer)" EXPR_RUBYMODE = "(ruby-mode)" - EXPR_NOBACKUP = "(progn" \ - " (set (make-local-variable \'backup-inhibited) t)" \ - " (set-buffer-modified-p t)" \ - ")" + EXPR_NOBACKUP = "(progn" << + " (set (make-local-variable \'backup-inhibited) t)" << + " (set-buffer-modified-p t)" << + ")" def run_emacs(src, *exprs) tmp = Tempfile.new(%w"ruby-mode.test. .rb") Index: test/ripper/test_scanner_events.rb =================================================================== --- test/ripper/test_scanner_events.rb (revision 37325) +++ test/ripper/test_scanner_events.rb (revision 37326) @@ -656,13 +656,13 @@ assert_equal ['<<-EOS'], scan('heredoc_beg', "<<-EOS\nheredoc\n\tEOS \n") assert_equal ['<<"EOS"'], - scan('heredoc_beg', '<<"EOS"'"\nheredoc\nEOS") + scan('heredoc_beg', "<<\"EOS\"\nheredoc\nEOS") assert_equal ["<<'EOS'"], scan('heredoc_beg', "<<'EOS'\nheredoc\nEOS") assert_equal ['<<`EOS`'], scan('heredoc_beg', "<<`EOS`\nheredoc\nEOS") assert_equal ['<<" "'], - scan('heredoc_beg', '<<" "'"\nheredoc\nEOS") + scan('heredoc_beg', "<<\" \"\nheredoc\nEOS") end def test_tstring_content_HEREDOC -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/