diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2011-03-19 16:03:13 +0900 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2011-03-20 00:47:33 +0900 |
commit | d3a2ab840916f055f724c6c2cc5702cfccf160cd (patch) | |
tree | 17a0a00092281905847e3c606957adc27812060d | |
parent | 648fd262097dfa64dd17fcea048969ffc081c808 (diff) | |
download | erubis-d3a2ab840916f055f724c6c2cc5702cfccf160cd.tar.gz |
[enhance] change untabify code on 'testutil.rb' to support Rubinius
-rw-r--r-- | test/testutil.rb | 21 |
1 files 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 |