1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Remove now unused code.

This commit is contained in:
Norman Clarke 2012-05-29 00:08:51 -03:00
parent f0e16d2ebd
commit a148068b25
2 changed files with 0 additions and 76 deletions

View file

@ -437,38 +437,6 @@ MSG
ruby1_8? ? c[0] : c.ord
end
# Flattens the first `n` nested arrays in a cross-version manner.
#
# @param arr [Array] The array to flatten
# @param n [Fixnum] The number of levels to flatten
# @return [Array] The flattened array
def flatten(arr, n)
return arr.flatten(n)
return arr if n == 0
arr.inject([]) {|res, e| e.is_a?(Array) ? res.concat(flatten(e, n - 1)) : res << e}
end
# Returns the hash code for a set in a cross-version manner.
# Aggravatingly, this is order-dependent in Ruby 1.8.6.
#
# @param set [Set]
# @return [Fixnum] The order-independent hashcode of `set`
def set_hash(set)
return set.hash
set.map {|e| e.hash}.uniq.sort.hash
end
# Tests the hash-equality of two sets in a cross-version manner.
# Aggravatingly, this is order-dependent in Ruby 1.8.6.
#
# @param set1 [Set]
# @param set2 [Set]
# @return [Boolean] Whether or not the sets are hashcode equal
def set_eql?(set1, set2)
return set1.eql?(set2)
set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
end
# Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
# This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
# before being evaluated.

View file

@ -87,50 +87,6 @@ class UtilTest < MiniTest::Unit::TestCase
assert_equal(98, ord("bar"))
end
def test_flatten
assert_equal([1, 2, 3], flatten([1, 2, 3], 0))
assert_equal([1, 2, 3], flatten([1, 2, 3], 1))
assert_equal([1, 2, 3], flatten([1, 2, 3], 2))
assert_equal([[1, 2], 3], flatten([[1, 2], 3], 0))
assert_equal([1, 2, 3], flatten([[1, 2], 3], 1))
assert_equal([1, 2, 3], flatten([[1, 2], 3], 2))
assert_equal([[[1], 2], [3], 4], flatten([[[1], 2], [3], 4], 0))
assert_equal([[1], 2, 3, 4], flatten([[[1], 2], [3], 4], 1))
assert_equal([1, 2, 3, 4], flatten([[[1], 2], [3], 4], 2))
end
def test_set_hash
assert(set_hash(Set[1, 2, 3]) == set_hash(Set[3, 2, 1]))
assert(set_hash(Set[1, 2, 3]) == set_hash(Set[1, 2, 3]))
s1 = Set[]
s1 << 1
s1 << 2
s1 << 3
s2 = Set[]
s2 << 3
s2 << 2
s2 << 1
assert(set_hash(s1) == set_hash(s2))
end
def test_set_eql
assert(set_eql?(Set[1, 2, 3], Set[3, 2, 1]))
assert(set_eql?(Set[1, 2, 3], Set[1, 2, 3]))
s1 = Set[]
s1 << 1
s1 << 2
s1 << 3
s2 = Set[]
s2 << 3
s2 << 2
s2 << 1
assert(set_eql?(s1, s2))
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"))