2006-10-14 23:50:07 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2006-09-29 18:52:04 +00:00
|
|
|
require 'test/unit'
|
2006-09-29 18:39:13 +00:00
|
|
|
require File.dirname(__FILE__) + '/../lib/haml/helpers'
|
2006-09-12 04:14:21 +00:00
|
|
|
|
2006-09-29 18:39:13 +00:00
|
|
|
class HelperTest < Test::Unit::TestCase
|
2006-09-12 04:14:21 +00:00
|
|
|
include Haml::Helpers
|
2006-08-08 13:42:19 +00:00
|
|
|
|
2006-11-08 03:27:37 +00:00
|
|
|
def render(text, options = {})
|
|
|
|
Haml::Engine.new(text, options).to_html
|
|
|
|
end
|
|
|
|
|
2006-11-06 03:01:04 +00:00
|
|
|
def test_flatten
|
|
|
|
assert_equal(flatten("FooBar"), "FooBar")
|
2006-09-29 18:39:13 +00:00
|
|
|
|
2006-11-06 03:01:04 +00:00
|
|
|
assert_equal(flatten("Foo\rBar"), "FooBar")
|
2006-09-29 18:39:13 +00:00
|
|
|
|
2006-11-06 03:01:04 +00:00
|
|
|
assert_equal(flatten("Foo\nBar"), "Foo
Bar")
|
2006-09-29 18:39:13 +00:00
|
|
|
|
2006-11-06 03:01:04 +00:00
|
|
|
assert_equal(flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"),
|
|
|
|
"Hello
World!
YOU ARE FLAT?
OMGZ!")
|
2006-08-08 21:38:50 +00:00
|
|
|
end
|
|
|
|
|
2006-09-29 18:39:13 +00:00
|
|
|
def test_list_of_should_render_correctly
|
2006-09-19 14:13:49 +00: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-08 03:27:37 +00: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 13:42:19 +00:00
|
|
|
end
|