From 7e1be5b6be5cddeb5ec8b9447e15c082e4db5122 Mon Sep 17 00:00:00 2001 From: hcatlin Date: Sun, 6 Aug 2006 04:25:31 +0000 Subject: [PATCH] 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 --- lib/haml/helpers.rb | 7 +++++++ test/haml_test.rb | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb index f73f94af..9687669f 100644 --- a/lib/haml/helpers.rb +++ b/lib/haml/helpers.rb @@ -4,4 +4,11 @@ module HAMLHelpers def flatten(input) input.gsub(/\n/, ' ').gsub(/\r/, '') end + + def tupleize(first, second) + second = second.reverse + first.collect do |f| + [f, second.pop] + end + end end diff --git a/test/haml_test.rb b/test/haml_test.rb index 1dd3c00e..34e0866c 100644 --- a/test/haml_test.rb +++ b/test/haml_test.rb @@ -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")