1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Proudly presenting excellent test coverage for HAML.

C0 is at 99.0%... all except for one experimental feature.

So, now any changes have something to be tested against which should be a fairly strong background.

Now, the only problem left is that whitespace active areas get fucked. That's not a good thing. Once we get a 
philosophical stance on such subjects, then we shall figure crap out about what that all means.



git-svn-id: svn://hamptoncatlin.com/haml/trunk@13 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
hcatlin 2006-08-06 03:18:54 +00:00
parent ff323de099
commit ad712a6d7e
5 changed files with 75 additions and 30 deletions

View file

@ -1,6 +1,8 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
desc 'Default: run unit tests.'
task :default => :test

View file

@ -1,4 +1,4 @@
require 'haml'
require 'haml_helpers'
require 'haml/engine'
require 'haml/helpers'
ActionView::Base.register_template_handler("haml", HAML::TemplateEngine)
ActionView::Base.register_template_handler("haml", HAML::Engine)

View file

@ -1,6 +1,10 @@
require File.dirname(__FILE__) + '/helpers'
module HAML
class TemplateEngine
class Engine
attr_accessor :base
include HAMLHelpers
@ -25,8 +29,6 @@ module HAML
@happy_land.set_locals(locals)
#breakpoint
#main loop handling line reading
#and interpretation
template.each_line do |line|
@ -48,7 +50,7 @@ module HAML
when '='
add template_eval(line[1, line.length])
else
add line
add line.strip
end
end
end
@ -59,7 +61,7 @@ module HAML
def add(line)
return nil if line.nil?
line.each_line { |me| add_single(me) }
line.to_s.each_line { |me| add_single(me) }
end
def add_single(line = "")
@ -110,7 +112,7 @@ module HAML
end
def render_comment(line)
add "<!-- #{line} -->"
add "<!-- #{line[1..line.length].strip} -->"
end
def render_tag(line)
@ -130,12 +132,11 @@ module HAML
value = template_eval(value)
one_line_tag(tag_name, value.to_s, attributes) if value != false
else
print_tag(tag_name, value, attributes)
print_tag(tag_name, value.to_s.strip, attributes)
end
end
end
def parse_attributes(list)
attributes = {}
list.scan(/([#.])([-a-zA-Z_()]+)/).each do |type, property|
@ -166,6 +167,8 @@ module HAML
end
class HappyLand #:nodoc
include HAMLHelpers
def initialize(base, hash_of_assigns, hash_of_locals = {})
base.instance_variables.each do |key|
value = base.instance_eval(key)

View file

@ -1,8 +1,48 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/haml/engine'
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'rubygems'
require 'action_view'
class HamlTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
def setup
ActionView::Base.register_template_handler("haml", HAML::Engine)
@base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/")
@engine = HAML::Engine.new(@base)
end
def load_result(name)
@result = ""
File.new(File.dirname(__FILE__) + "/results/" + name + ".xhtml").each_line { |l| @result += l}
@result
end
def assert_renders_correctly(name)
assert_equal(load_result(name), @base.render(name))
end
# Make sure our little environment builds
def test_build_stub
assert_not_nil(@engine)
assert_equal(HAML::Engine, @engine.class)
end
def test_empty_render
assert_equal("", @engine.render(""))
end
def test_renderings
assert_renders_correctly("very_basic")
assert_renders_correctly("standard")
assert_renders_correctly("helpers")
end
def test_instance_variables
@base.instance_eval("@content_for_layout = 'Hampton'")
@base.instance_eval("@assigns['last_name'] = 'Catlin'")
#make sure to reload!
@engine = HAML::Engine.new(@base)
assert_equal("<div class='author'>Hampton Catlin</div>\n", @engine.render(".author= @content_for_layout + ' ' + @last_name"))
end
end