Skip to content

Commit

Permalink
[enhance] change untabify code on 'testutil.rb' to support Rubinius
Browse files Browse the repository at this point in the history
  • Loading branch information
kwatch committed Mar 19, 2011
1 parent 648fd26 commit d3a2ab8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/testutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def self.load_yaml_datafile(filename, options={}, &block) # :nodoc:
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|
Expand Down Expand Up @@ -93,4 +89,19 @@ def self.post_definition
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

0 comments on commit d3a2ab8

Please sign in to comment.