Remove some dead code from Haml::Util
This commit is contained in:
parent
53b9e21607
commit
2dbfcb7d58
|
@ -14,38 +14,6 @@ module Haml
|
|||
module Util
|
||||
extend self
|
||||
|
||||
# Computes the powerset of the given array.
|
||||
# This is the set of all subsets of the array.
|
||||
#
|
||||
# @example
|
||||
# powerset([1, 2, 3]) #=>
|
||||
# Set[Set[], Set[1], Set[2], Set[3], Set[1, 2], Set[2, 3], Set[1, 3], Set[1, 2, 3]]
|
||||
# @param arr [Enumerable]
|
||||
# @return [Set<Set>] The subsets of `arr`
|
||||
def powerset(arr)
|
||||
arr.inject([Set.new].to_set) do |powerset, el|
|
||||
new_powerset = Set.new
|
||||
powerset.each do |subset|
|
||||
new_powerset << subset
|
||||
new_powerset << subset + [el]
|
||||
end
|
||||
new_powerset
|
||||
end
|
||||
end
|
||||
|
||||
# Returns information about the caller of the previous method.
|
||||
#
|
||||
# @param entry [String] An entry in the `#caller` list, or a similarly formatted string
|
||||
# @return [[String, Fixnum, (String, nil)]] An array containing the filename, line, and method name of the caller.
|
||||
# The method name may be nil
|
||||
def caller_info(entry = caller[1])
|
||||
info = entry.scan(/^(.*?):(-?.*?)(?::.*`(.+)')?$/).first
|
||||
info[1] = info[1].to_i
|
||||
# This is added by Rubinius to designate a block, but we don't care about it.
|
||||
info[2].sub!(/ \{\}\Z/, '') if info[2]
|
||||
info
|
||||
end
|
||||
|
||||
# Silence all output to STDERR within a block.
|
||||
#
|
||||
# @yield A block in which no output will be printed to STDERR
|
||||
|
|
|
@ -3,18 +3,6 @@ require 'test_helper'
|
|||
class UtilTest < Haml::TestCase
|
||||
include Haml::Util
|
||||
|
||||
def test_powerset
|
||||
assert_equal([[].to_set].to_set,
|
||||
powerset([]))
|
||||
assert_equal([[].to_set, [1].to_set].to_set,
|
||||
powerset([1]))
|
||||
assert_equal([[].to_set, [1].to_set, [2].to_set, [1, 2].to_set].to_set,
|
||||
powerset([1, 2]))
|
||||
assert_equal([[].to_set, [1].to_set, [2].to_set, [3].to_set,
|
||||
[1, 2].to_set, [2, 3].to_set, [1, 3].to_set, [1, 2, 3].to_set].to_set,
|
||||
powerset([1, 2, 3]))
|
||||
end
|
||||
|
||||
def test_silence_warnings
|
||||
old_stderr, $stderr = $stderr, StringIO.new
|
||||
warn "Out"
|
||||
|
@ -25,15 +13,6 @@ class UtilTest < Haml::TestCase
|
|||
$stderr = old_stderr
|
||||
end
|
||||
|
||||
def test_caller_info
|
||||
assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle'"))
|
||||
assert_equal(["/tmp/foo.rb", 12, nil], caller_info("/tmp/foo.rb:12"))
|
||||
assert_equal(["(haml)", 12, "blah"], caller_info("(haml):12: in `blah'"))
|
||||
assert_equal(["", 12, "boop"], caller_info(":12: in `boop'"))
|
||||
assert_equal(["/tmp/foo.rb", -12, "fizzle"], caller_info("/tmp/foo.rb:-12: in `fizzle'"))
|
||||
assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle {}'"))
|
||||
end
|
||||
|
||||
def test_check_encoding_does_not_destoy_the_given_string
|
||||
string_with_bom = File.read(File.dirname(__FILE__) + '/templates/with_bom.haml', :encoding => Encoding::UTF_8)
|
||||
original = string_with_bom.dup
|
||||
|
|
Loading…
Reference in New Issue