From d3a2ab840916f055f724c6c2cc5702cfccf160cd Mon Sep 17 00:00:00 2001 From: makoto kuwata Date: Sat, 19 Mar 2011 16:03:13 +0900 Subject: [enhance] change untabify code on 'testutil.rb' to support Rubinius --- test/testutil.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/testutil.rb b/test/testutil.rb index 92aafcc..6f3df9c 100644 --- a/test/testutil.rb +++ b/test/testutil.rb @@ -30,11 +30,7 @@ class Test::Unit::TestCase s = $' end # untabify - unless options[:tabify] == false - s = s.split(/^/).inject('') do |sb, line| - sb << line.gsub(/([^\t]{8})|([^\t]*)\t/n) { [$+].pack("A8") } - end - end + s = _untabify(s) unless options[:tabify] == false # load yaml document testdata_list = [] YAML.load_documents(s) do |ydoc| @@ -93,4 +89,19 @@ class Test::Unit::TestCase end + def self._untabify(str, width=8) + return str if str.nil? + list = str.split(/\t/, -1) # if 2nd arg is negative then split() doesn't remove tailing empty strings + last = list.pop + sb = '' + list.each do |s| + column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length + n = width - (column % width) + sb << s << (' ' * n) + end + sb << last if last + return sb + end + + end -- cgit v1.2.1