require 'runit/testcase' require 'runit/cui/testrunner' require 'rrb/scriptfile' require 'stringio' class TestFunction < RUNIT::TestCase BEFORE_REPLACE = <<'EOS' # comment class Rename def method_1( x, y ) zz = 3 zz.upto(6) do |zzz| print zzz*3, "\n" end print zz**4, zz**5 end end EOS AFTER_REPLACE = <<'EOS' # comment class Rename def method_1( x, y ) c = 3 c.upto(6) do |zzz| print zzz*3, "\n" end print c**4, c**5 end end EOS REPLACE_INFO = [ RRB::Replacer.new( 5, 6, 'zz', 'c' ), RRB::Replacer.new( 6, 6, 'zz', 'c' ), RRB::Replacer.new( 9, 12, 'zz', 'c' ), RRB::Replacer.new( 9, 19, 'zz', 'c' ), ] def test_replace_str assert_equals( AFTER_REPLACE, RRB.replace_str( BEFORE_REPLACE, REPLACE_INFO) ) end def test_expand_tabs assert_equals( " "*8 + "heke" , RRB.expand_tabs("\theke") ) assert_equals( " "*12 + "heke\n", RRB.expand_tabs("\t heke\n") ) assert_equals( " "*16, RRB.expand_tabs( "\t\t")) assert_equals( " "*16, RRB.expand_tabs( "\t \t")) assert_equals( "heke\t\n", RRB.expand_tabs( "heke\t\n" ) ) end BEFORE_REINDENT1 = <