test/replace_command_test.rb in pups-1.0.3 vs test/replace_command_test.rb in pups-1.1.0

- old
+ new

@@ -1,111 +1,109 @@ +# frozen_string_literal: true + require 'test_helper' require 'tempfile' module Pups class ReplaceCommandTest < MiniTest::Test - def test_simple command = ReplaceCommand.new({}) - command.text = "hello world" + command.text = 'hello world' command.from = /he[^o]+o/ - command.to = "world" + command.to = 'world' - assert_equal("world world", command.replaced_text) + assert_equal('world world', command.replaced_text) end def test_reverse - source = <<SCR -1 one thousand 1 -1 one thousand 1 -1 one thousand 1 -SCR + source = <<~SCR + 1 one thousand 1 + 1 one thousand 1 + 1 one thousand 1 + SCR - f = Tempfile.new("test") + f = Tempfile.new('test') f.write source f.close hash = { - "filename" => f.path, - "from" => "/one t.*d/", - "to" => "hello world", - "direction" => "reverse" + 'filename' => f.path, + 'from' => '/one t.*d/', + 'to' => 'hello world', + 'direction' => 'reverse' } command = ReplaceCommand.from_hash(hash, {}) assert_equal("1 one thousand 1\n1 one thousand 1\n1 hello world 1\n", command.replaced_text) ensure f.unlink end def test_global - source = <<SCR -one -one -one -SCR + source = <<~SCR + one + one + one + SCR - f = Tempfile.new("test") + f = Tempfile.new('test') f.write source f.close hash = { - "filename" => f.path, - "from" => "/one/", - "to" => "two", - "global" => "true" + 'filename' => f.path, + 'from' => '/one/', + 'to' => 'two', + 'global' => 'true' } command = ReplaceCommand.from_hash(hash, {}) assert_equal("two\ntwo\ntwo\n", command.replaced_text) ensure f.unlink - end def test_replace_with_env - source = "123" + source = '123' - f = Tempfile.new("test") + f = Tempfile.new('test') f.write source f.close hash = { - "filename" => f.path, - "from" => "123", - "to" => "hello $hellos" + 'filename' => f.path, + 'from' => '123', + 'to' => 'hello $hellos' } - command = ReplaceCommand.from_hash(hash, {"hello" => "world"}) - assert_equal("hello worlds", command.replaced_text) - + command = ReplaceCommand.from_hash(hash, { 'hello' => 'world' }) + assert_equal('hello worlds', command.replaced_text) ensure f.unlink end def test_parse + source = <<~SCR + this { + is a test + } + SCR - source = <<SCR -this { -is a test -} -SCR - - f = Tempfile.new("test") + f = Tempfile.new('test') f.write source f.close hash = { - "filename" => f.path, - "from" => "/this[^\}]+\}/m", - "to" => "hello world" + 'filename' => f.path, + 'from' => "/this[^\}]+\}/m", + 'to' => 'hello world' } command = ReplaceCommand.from_hash(hash, {}) - assert_equal("hello world", command.replaced_text.strip) + assert_equal('hello world', command.replaced_text.strip) ensure f.unlink end end end