Added a cool helper that I just like adding to the language. Also, started checking line-by-line instead of as

gigantic strings when dealing with testing the templates.



git-svn-id: svn://hamptoncatlin.com/haml/trunk@14 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
hcatlin 2006-08-06 04:25:31 +00:00
parent ad712a6d7e
commit 7e1be5b6be
2 changed files with 17 additions and 1 deletions

View File

@ -4,4 +4,11 @@ module HAMLHelpers
def flatten(input)
input.gsub(/\n/, '&#x000A').gsub(/\r/, '')
end
def tupleize(first, second)
second = second.reverse
first.collect do |f|
[f, second.pop]
end
end
end

View File

@ -5,6 +5,8 @@ require 'rubygems'
require 'action_view'
class HamlTest < Test::Unit::TestCase
include HAMLHelpers
def setup
ActionView::Base.register_template_handler("haml", HAML::Engine)
@base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/")
@ -18,7 +20,10 @@ class HamlTest < Test::Unit::TestCase
end
def assert_renders_correctly(name)
assert_equal(load_result(name), @base.render(name))
tupleize(load_result(name).scan(/\n/), @base.render(name).scan(/\n/)).each do |pair|
#test each line to make sure it matches... (helps with error messages to do them seperately)
assert_equal(pair.first, pair.last)
end
end
# Make sure our little environment builds
@ -31,6 +36,10 @@ class HamlTest < Test::Unit::TestCase
assert_equal("", @engine.render(""))
end
def test_tuple_helper
assert_equal(tupleize([1,2,3], [4,5,6]), [[1,4],[2,5],[3,6]])
end
def test_renderings
assert_renders_correctly("very_basic")
assert_renders_correctly("standard")