2006-10-14 19:50:07 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2006-09-29 14:52:04 -04:00
|
|
|
require 'test/unit'
|
2006-09-29 14:39:13 -04:00
|
|
|
require File.dirname(__FILE__) + '/../lib/haml/helpers'
|
2006-09-12 00:14:21 -04:00
|
|
|
|
2006-09-29 14:39:13 -04:00
|
|
|
class HelperTest < Test::Unit::TestCase
|
2006-09-12 00:14:21 -04:00
|
|
|
include Haml::Helpers
|
2006-08-08 09:42:19 -04:00
|
|
|
|
2006-11-07 22:27:37 -05:00
|
|
|
def render(text, options = {})
|
|
|
|
Haml::Engine.new(text, options).to_html
|
|
|
|
end
|
|
|
|
|
2006-11-05 22:01:04 -05:00
|
|
|
def test_flatten
|
|
|
|
assert_equal(flatten("FooBar"), "FooBar")
|
2006-09-29 14:39:13 -04:00
|
|
|
|
2006-11-05 22:01:04 -05:00
|
|
|
assert_equal(flatten("Foo\rBar"), "FooBar")
|
2006-09-29 14:39:13 -04:00
|
|
|
|
2006-11-05 22:01:04 -05:00
|
|
|
assert_equal(flatten("Foo\nBar"), "Foo
Bar")
|
2006-09-29 14:39:13 -04:00
|
|
|
|
2006-11-05 22:01:04 -05:00
|
|
|
assert_equal(flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"),
|
|
|
|
"Hello
World!
YOU ARE FLAT?
OMGZ!")
|
2006-08-08 17:38:50 -04:00
|
|
|
end
|
|
|
|
|
2006-09-29 14:39:13 -04:00
|
|
|
def test_list_of_should_render_correctly
|
2006-09-19 10:13:49 -04:00
|
|
|
assert_equal("<li>1</li>\n<li>2</li>", (list_of([1, 2]) { |i| i.to_s}))
|
|
|
|
assert_equal("<li>1</li>", (list_of([[1]]) { |i| i.first}))
|
|
|
|
end
|
2006-11-07 22:27:37 -05:00
|
|
|
|
|
|
|
def test_buffer_access
|
|
|
|
assert(render("= buffer") =~ /#<Haml::Buffer:0x[a-z0-9]+>/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tabs
|
|
|
|
assert_equal(render("foo\n- tab_up\nbar\n- tab_down\nbaz"), "foo\n bar\nbaz\n")
|
|
|
|
end
|
2006-08-08 09:42:19 -04:00
|
|
|
end
|