diff --git a/lib/reline/kill_ring.rb b/lib/reline/kill_ring.rb index 84d94a7ff6997a..201f6f3ca0c2ba 100644 --- a/lib/reline/kill_ring.rb +++ b/lib/reline/kill_ring.rb @@ -68,7 +68,7 @@ def initialize(max = 1024) def append(string, before_p = false) case @state when State::FRESH, State::YANK - @ring << RingPoint.new(string) + @ring << RingPoint.new(+string) @state = State::CONTINUED when State::CONTINUED, State::PROCESSED if before_p diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index b7cc6b747dc4b2..5e3a862cc622bb 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1256,7 +1256,7 @@ def editing_mode item_mbchars = item.grapheme_clusters end size = [memo_mbchars.size, item_mbchars.size].min - result = '' + result = +'' size.times do |i| if @config.completion_ignore_case if memo_mbchars[i].casecmp?(item_mbchars[i]) @@ -2935,7 +2935,7 @@ def finish end private def ed_delete_prev_char(key, arg: 1) - deleted = '' + deleted = +'' arg.times do if @cursor > 0 byte_size = Reline::Unicode.get_prev_mbchar_size(@line, @byte_pointer) diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 4e09fe1af7e7d7..e893ac6a84adfe 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -696,7 +696,7 @@ def dump_my_heap_please assert_test_string_entry_correct_in_dump_all(output) end - assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}#{<<-'end;'}") do |(output), (error)| + assert_in_out_err(%w[-robjspace --disable=frozen-string-literal], "#{<<-"begin;"}#{<<-'end;'}") do |(output), (error)| begin; def dump_my_heap_please ObjectSpace.trace_object_allocations_start diff --git a/test/ruby/enc/test_case_mapping.rb b/test/ruby/enc/test_case_mapping.rb index 31acdc4331c3e6..2e16d5809c3cb2 100644 --- a/test/ruby/enc/test_case_mapping.rb +++ b/test/ruby/enc/test_case_mapping.rb @@ -47,7 +47,7 @@ def check_capitalize_suffixes(lower, upper) # different properties; careful: roundtrip isn't always guaranteed def check_swapcase_properties(expected, start, *flags) assert_equal expected, start.swapcase(*flags) - temp = start + temp = +start assert_equal expected, temp.swapcase!(*flags) assert_equal start, start.swapcase(*flags).swapcase(*flags) assert_equal expected, expected.swapcase(*flags).swapcase(*flags) diff --git a/test/ruby/enc/test_case_options.rb b/test/ruby/enc/test_case_options.rb index e9bf50fcfcb603..ac62da9961d6c2 100644 --- a/test/ruby/enc/test_case_options.rb +++ b/test/ruby/enc/test_case_options.rb @@ -51,7 +51,7 @@ def assert_okay_bang_operations(arg, *options) def assert_okay_both_types(*options) assert_okay_functional_operations 'a', *options - assert_okay_bang_operations 'a', *options + assert_okay_bang_operations +'a', *options assert_okay_functional_operations :a, *options end diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index fed1bf88b46997..ab7beac84624ee 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -593,7 +593,7 @@ def test_read def test_read2 ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" ARGF.read(8, s) p s }; @@ -604,7 +604,7 @@ def test_read2 def test_read2_with_not_empty_buffer ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "0123456789" + s = +"0123456789" ARGF.read(8, s) p s }; @@ -626,13 +626,13 @@ def test_read3 def test_readpartial ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" begin loop do s << ARGF.readpartial(1) - t = ""; ARGF.readpartial(1, t); s << t + t = +""; ARGF.readpartial(1, t); s << t # not empty buffer - u = "abcdef"; ARGF.readpartial(1, u); s << u + u = +"abcdef"; ARGF.readpartial(1, u); s << u end rescue EOFError puts s @@ -645,11 +645,11 @@ def test_readpartial def test_readpartial2 ruby('-e', "#{<<~"{#"}\n#{<<~'};'}") do |f| {# - s = "" + s = +"" begin loop do s << ARGF.readpartial(1) - t = ""; ARGF.readpartial(1, t); s << t + t = +""; ARGF.readpartial(1, t); s << t end rescue EOFError $stdout.binmode @@ -680,7 +680,7 @@ def test_readpartial_eof_twice def test_getc ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" while c = ARGF.getc s << c end @@ -706,7 +706,7 @@ def test_getbyte def test_readchar ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" begin while c = ARGF.readchar s << c @@ -784,7 +784,7 @@ def test_each_byte def test_each_char ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - s = "" + s = +"" ARGF.each_char {|c| s << c } puts s }; @@ -1073,7 +1073,7 @@ def test_read_nonblock ruby('-e', "#{<<~"{#"}\n#{<<~'};'}") do |f| {# $stdout.sync = true - :wait_readable == ARGF.read_nonblock(1, "", exception: false) or + :wait_readable == ARGF.read_nonblock(1, +"", exception: false) or abort "did not return :wait_readable" begin @@ -1086,7 +1086,7 @@ def test_read_nonblock IO.select([ARGF]) == [[ARGF], [], []] or abort 'did not awaken for readability (before byte)' - buf = '' + buf = +'' buf.object_id == ARGF.read_nonblock(1, buf).object_id or abort "read destination buffer failed" print buf diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 065a9448530e05..1f882c6cb9e2cb 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -207,7 +207,7 @@ def test_very_big_str_to_inum assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; digits = [["3", 700], ["0", 2700], ["1", 1], ["0", 26599]] - num = digits.inject("") {|s,(c,n)|s << c*n}.to_i + num = digits.inject(+"") {|s,(c,n)|s << c*n}.to_i assert_equal digits.sum {|c,n|n}, num.to_s.size end; end diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index 67bad8a514ea3e..b4b1007d629498 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -56,7 +56,7 @@ def test_filename_extutf8_invalid return if Bug::File::Fs.fsname(Dir.tmpdir) == "apfs" with_tmpdir {|d| assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d) - filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 + filename = "\xff".dup.force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -64,7 +64,7 @@ def test_filename_extutf8_invalid assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) - filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8 + filename = "\xff".dup.force_encoding("UTF-8") # invalid byte sequence as UTF-8 File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -77,7 +77,7 @@ def test_filename_extutf8_invalid def test_filename_as_bytes_extutf8 with_tmpdir {|d| assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) - filename = "\xc2\xa1".force_encoding("utf-8") + filename = "\xc2\xa1".dup.force_encoding("utf-8") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -85,9 +85,9 @@ def test_filename_as_bytes_extutf8 EOS assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d) if /mswin|mingw|darwin/ =~ RUBY_PLATFORM - filename = "\x8f\xa2\xc2".force_encoding("euc-jp") + filename = "\x8f\xa2\xc2".dup.force_encoding("euc-jp") else - filename = "\xc2\xa1".force_encoding("euc-jp") + filename = "\xc2\xa1".dup.force_encoding("euc-jp") end assert_nothing_raised(Errno::ENOENT) do open(filename) {} @@ -96,8 +96,8 @@ def test_filename_as_bytes_extutf8 # no meaning test on windows unless /mswin|mingw|darwin/ =~ RUBY_PLATFORM assert_separately(%W[-EUTF-8], <<-'EOS', :chdir=>d) - filename1 = "\xc2\xa1".force_encoding("utf-8") - filename2 = "\xc2\xa1".force_encoding("euc-jp") + filename1 = "\xc2\xa1".dup.force_encoding("utf-8") + filename2 = "\xc2\xa1".dup.force_encoding("euc-jp") filename3 = filename1.encode("euc-jp") filename4 = filename2.encode("utf-8") assert_file.stat(filename1) @@ -121,13 +121,13 @@ def test_filename_extutf8_inteucjp_representable assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) assert_include(ents, filename) EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") assert_nothing_raised(Errno::ENOENT) do open(filename) {} end @@ -149,7 +149,7 @@ def test_filename_extutf8_inteucjp_unrepresentable EOS assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP - filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + filename2 = "\xA4\xA2".dup.force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) assert_include(ents, filename1) @@ -158,7 +158,7 @@ def test_filename_extutf8_inteucjp_unrepresentable assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d) filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP - filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + filename3 = "\xA4\xA2".dup.force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP assert_file.stat(filename1) assert_file.stat(filename2) assert_file.stat(filename3) @@ -172,7 +172,7 @@ def test_filename_bytes_euc_jp return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -189,7 +189,7 @@ def test_filename_euc_jp return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} ents = Dir.entries(".") if /darwin/ =~ RUBY_PLATFORM @@ -200,7 +200,7 @@ def test_filename_euc_jp assert_include(ents, filename) EOS assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding('ASCII-8BIT') + filename = "\xA4\xA2".dup.force_encoding('ASCII-8BIT') ents = Dir.entries(".") unless ents.include?(filename) case RUBY_PLATFORM @@ -231,7 +231,7 @@ def test_filename_ext_euc_jp_and_int_utf_8 return if /cygwin/ =~ RUBY_PLATFORM with_tmpdir {|d| assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") + filename = "\xA4\xA2".dup.force_encoding("euc-jp") File.open(filename, "w") {} opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) @@ -241,7 +241,7 @@ def test_filename_ext_euc_jp_and_int_utf_8 assert_include(ents, filename) EOS assert_separately(%w[-EEUC-JP:UTF-8], <<-'EOS', :chdir=>d) - filename = "\u3042" + filename = "\u3042".dup opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM ents = Dir.entries(".", **(opts||{})) if /darwin/ =~ RUBY_PLATFORM @@ -350,7 +350,7 @@ def test_glob_warning_match_dir end def test_glob_escape_multibyte - name = "\x81\\".force_encoding(Encoding::Shift_JIS) + name = "\x81\\".dup.force_encoding(Encoding::Shift_JIS) with_tmpdir do open(name, "w") {} rescue next match, = Dir.glob("#{name}*") @@ -363,8 +363,8 @@ def test_glob_encoding with_tmpdir do list = %W"file_one.ext file_two.ext \u{6587 4ef6}1.txt \u{6587 4ef6}2.txt" list.each {|f| open(f, "w") {}} - a = "file_one*".force_encoding Encoding::IBM437 - b = "file_two*".force_encoding Encoding::EUC_JP + a = "file_one*".dup.force_encoding Encoding::IBM437 + b = "file_two*".dup.force_encoding Encoding::EUC_JP assert_equal([a, b].map(&:encoding), Dir[a, b].map(&:encoding)) if Bug::File::Fs.fsname(Dir.pwd) == "apfs" # High Sierra's APFS cannot use filenames with undefined character @@ -375,7 +375,7 @@ def test_glob_encoding Dir.mkdir(dir) list << dir bug12081 = '[ruby-core:73868] [Bug #12081]' - a = "*".force_encoding("us-ascii") + a = "*".dup.force_encoding("us-ascii") result = Dir[a].map {|n| if n.encoding == Encoding::ASCII_8BIT || n.encoding == Encoding::ISO_8859_1 || diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index cdadeac14886e8..4b5f18e7bb5534 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -612,8 +612,8 @@ def str_to_yield_invalid_envvar_errors(var_name, code_str) <<-"end;" envvars_to_check = [ "foo\0bar", - "#{'\xa1\xa1'}".force_encoding(Encoding::UTF_16LE), - "foo".force_encoding(Encoding::ISO_2022_JP), + "#{'\xa1\xa1'}".dup.force_encoding(Encoding::UTF_16LE), + "foo".dup.force_encoding(Encoding::ISO_2022_JP), ] envvars_to_check.each do |#{var_name}| #{str_for_yielding_exception_class(code_str)} diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index adf82620f3be85..f47c0b046b6300 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -372,7 +372,7 @@ def test_moving_strings_up_size_pools Fiber.new { str = "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] * 4 - $ary = STR_COUNT.times.map { "" << str } + $ary = STR_COUNT.times.map { +"" << str } }.resume stats = GC.verify_compaction_references(expand_heap: true, toward: :empty) diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index ebb28af11667d3..dc84d8bd7c4b51 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -168,7 +168,7 @@ def obj.foo(*) nil.instance_eval{ ->{super} } end end def test_disasm_encoding - src = "\u{3042} = 1; \u{3042}; \u{3043}" + src = +"\u{3042} = 1; \u{3042}; \u{3043}" asm = compile(src).disasm assert_equal(src.encoding, asm.encoding) assert_predicate(asm, :valid_encoding?) diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 4fb23d1b545324..11acf31f2173b3 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1044,7 +1044,7 @@ module Test end using Test def t - 'Refinements are broken!'.chop! + 'Refinements are broken!'.dup.chop! end t module Test diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 4b63263aae39db..ceef19e7ea5951 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -2265,7 +2265,7 @@ def test_loading_race result = th.map(&:value) end end - expected = "\xa4\xa2".force_encoding(Encoding::EUC_JP) + expected = "\xa4\xa2".dup.force_encoding(Encoding::EUC_JP) assert_equal([expected]*num, result, bug11277) end; end diff --git a/test/stringio/test_ractor.rb b/test/stringio/test_ractor.rb index 1c334e2c3f9ae8..4a2033bc1fbe85 100644 --- a/test/stringio/test_ractor.rb +++ b/test/stringio/test_ractor.rb @@ -11,7 +11,7 @@ def test_ractor require "stringio" $VERBOSE = nil r = Ractor.new do - io = StringIO.new("") + io = StringIO.new(+"") io.puts "abc" io.truncate(0) io.puts "def" diff --git a/test/test_trick.rb b/test/test_trick.rb index 878d79e628b080..c5c19d079e7198 100644 --- a/test/test_trick.rb +++ b/test/test_trick.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: false + require "test/unit" require "ripper" require "envutil" @@ -12,24 +14,24 @@ class TestTRICK2013 < Test::Unit::TestCase def test_kinaba src = File.join(__dir__, "../sample/trick2013/kinaba/entry.rb") expected = [*" ".."~"].join("") # all ASCII printables - assert_in_out_err(["-W0", src], "", [expected]) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src], "", [expected]) assert_equal(expected, File.read(src).chomp.chars.sort.join) end def test_mame src = File.join(__dir__, "../sample/trick2013/mame/entry.rb") ignore_dsp = "def open(_file, _mode); s = ''; def s.flush; self;end; yield s; end;" - assert_in_out_err(["-W0"], ignore_dsp + File.read(src), File.read(src).lines(chomp: true), timeout: 60) + assert_in_out_err(["-W0", "--disable-frozen-string-literal"], ignore_dsp + File.read(src), File.read(src).lines(chomp: true), timeout: 60) end def test_shinh src = File.join(__dir__, "../sample/trick2013/shinh/entry.rb") - assert_in_out_err(["-W0", src], "", []) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src], "", []) end def test_yhara src = File.join(__dir__, "../sample/trick2013/yhara/entry.rb") - assert_in_out_err(["-W0", src], "", ["JUST ANOTHER RUBY HACKER"]) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src], "", ["JUST ANOTHER RUBY HACKER"]) end end @@ -45,7 +47,7 @@ def test_kinaba end pi = "3#{ a - b }" - assert_in_out_err(["-W0", src], "", [pi], timeout: 60) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src], "", [pi], timeout: 60) assert_equal(pi[0, 242], Ripper.tokenize(File.read(src)).grep(/\S/).map{|t|t.size%10}.join) end @@ -60,7 +62,7 @@ def test_ksk_1 s << n.to_s end - assert_in_out_err(["-W0", src, "27"], "", s) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src, "27"], "", s) end def test_monae @@ -78,13 +80,13 @@ def test_monae end expected = /\A#{ expected.map {|s| "#{ Regexp.quote(s) }\s*\n" }.join }\z/ - assert_in_out_err(["-W0", src], "", expected) + assert_in_out_err(["-W0", "--disable-frozen-string-literal", src], "", expected) end def test_eregon src = File.join(__dir__, "../sample/trick2015/eregon/entry.rb") - assert_in_out_err(["-W0", src], "", <