From db1f7079b6ff3c7227f20fc9c0743f9147bba2d2 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 25 Oct 2012 10:07:22 +0000 Subject: [PATCH] remove string literal concatenation git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bootstraptest/runner.rb | 3 ++- bootstraptest/test_syntax.rb | 2 +- lib/matrix.rb | 3 +-- lib/mkmf.rb | 10 +++++----- lib/net/http/generic_request.rb | 4 +--- lib/rss/rss.rb | 8 ++++---- sample/test.rb | 4 ---- test/json/test_json.rb | 6 ++---- test/misc/test_ruby_mode.rb | 8 ++++---- test/ripper/test_scanner_events.rb | 4 ++-- test/ruby/envutil.rb | 4 ++-- test/ruby/test_literal.rb | 3 +++ test/ruby/test_parse.rb | 2 +- test/ruby/test_rubyoptions.rb | 12 ++++++------ test/ruby/test_stringchar.rb | 4 ---- test/ruby/test_syntax.rb | 2 +- 16 files changed, 35 insertions(+), 44 deletions(-) diff --git a/bootstraptest/runner.rb b/bootstraptest/runner.rb index 0dd1e35a88..60c9d26d95 100755 --- a/bootstraptest/runner.rb +++ b/bootstraptest/runner.rb @@ -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$ diff --git a/bootstraptest/test_syntax.rb b/bootstraptest/test_syntax.rb index 80eaa6416d..4d56908ac1 100644 --- a/bootstraptest/test_syntax.rb +++ b/bootstraptest/test_syntax.rb @@ -525,7 +525,7 @@ assert_equal %q{1}, %q{ } 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]' diff --git a/lib/matrix.rb b/lib/matrix.rb index 00fa762da6..f4e3b316f6 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1404,8 +1404,7 @@ class Matrix 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 diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 0996392300..ec110fd6f6 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -1026,7 +1026,7 @@ SRC # 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 @@ arch_hdrdir = #{$arch_hdrdir.quote} 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 @@ MESSAGE 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 @@ MESSAGE 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' diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb index bcf87d35be..f10ddebfaa 100644 --- a/lib/net/http/generic_request.rb +++ b/lib/net/http/generic_request.rb @@ -186,9 +186,7 @@ class Net::HTTPGenericRequest 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) diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 3d90d54912..e1b37e6a39 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -591,10 +591,10 @@ EOC 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]) diff --git a/sample/test.rb b/sample/test.rb index 26cf0a1d97..11f15de938 100755 --- a/sample/test.rb +++ b/sample/test.rb @@ -1612,10 +1612,6 @@ test_check "string & char" 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*$/) diff --git a/test/json/test_json.rb b/test/json/test_json.rb index 22cd5ee5a5..1f81cafd48 100755 --- a/test/json/test_json.rb +++ b/test/json/test_json.rb @@ -42,8 +42,7 @@ class TestJSON < Test::Unit::TestCase '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 @@ class TestJSON < Test::Unit::TestCase 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 diff --git a/test/misc/test_ruby_mode.rb b/test/misc/test_ruby_mode.rb index d654cdc34b..2211a7f9b9 100644 --- a/test/misc/test_ruby_mode.rb +++ b/test/misc/test_ruby_mode.rb @@ -19,10 +19,10 @@ class TestRubyMode 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") diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index bcbbf0192c..78d1f6495b 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -656,13 +656,13 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase 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 diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 3e04f55c0c..53dd210868 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -209,9 +209,9 @@ module Test "-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) diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index c34874e4a6..d9b999d22f 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -56,6 +56,7 @@ class TestRubyLiteral < Test::Unit::TestCase 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 @@ class TestRubyLiteral < Test::Unit::TestCase 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 diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 8623960b42..f4d8644e6a 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -560,7 +560,7 @@ FOO end assert_nothing_raised do - eval "x = <<""FOO\r\n1\r\nFOO" + eval "x = <\