2012-05-01 11:09:15 -04:00
|
|
|
require 'test_helper'
|
2009-03-26 00:42:22 -04:00
|
|
|
|
2013-05-23 08:41:27 -04:00
|
|
|
class UtilTest < MiniTest::Unit::TestCase
|
2009-03-26 00:42:22 -04:00
|
|
|
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
|
|
|
|
|
2009-11-11 17:30:11 -05:00
|
|
|
def test_silence_warnings
|
|
|
|
old_stderr, $stderr = $stderr, StringIO.new
|
|
|
|
warn "Out"
|
|
|
|
assert_equal("Out\n", $stderr.string)
|
|
|
|
silence_warnings {warn "In"}
|
2010-03-29 23:01:16 -04:00
|
|
|
assert_equal("Out\n", $stderr.string)
|
|
|
|
ensure
|
|
|
|
$stderr = old_stderr
|
|
|
|
end
|
|
|
|
|
2009-10-25 16:24:22 -04:00
|
|
|
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'"))
|
2010-05-15 05:55:01 -04:00
|
|
|
assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle {}'"))
|
2009-10-25 16:24:22 -04:00
|
|
|
end
|
|
|
|
|
2013-02-08 10:23:34 -05:00
|
|
|
def test_check_encoding_does_not_destoy_the_given_string
|
2013-05-23 00:33:39 -04:00
|
|
|
string_with_bom = File.read(File.dirname(__FILE__) + '/templates/with_bom.haml', :encoding => Encoding::UTF_8)
|
2013-02-08 10:23:34 -05:00
|
|
|
original = string_with_bom.dup
|
|
|
|
check_encoding(string_with_bom)
|
|
|
|
assert_equal(original, string_with_bom)
|
|
|
|
end
|
2009-03-26 00:42:22 -04:00
|
|
|
end
|