diff --git a/Rakefile b/Rakefile index 6a877d84..44f59821 100644 --- a/Rakefile +++ b/Rakefile @@ -17,4 +17,11 @@ namespace :rails do end end -task default: [:spec, 'rails:spec'] +namespace :haml do + desc 'Run Haml Spec' + task :spec do + system('cd spec/haml-spec && rake spec') + end +end + +task default: [:spec, 'rails:spec', 'haml:spec'] diff --git a/lib/hamlit/parser.rb b/lib/hamlit/parser.rb index 477eb0d6..a08b3175 100644 --- a/lib/hamlit/parser.rb +++ b/lib/hamlit/parser.rb @@ -1,3 +1,4 @@ +require 'strscan' require 'temple' require 'hamlit/parser/utils' diff --git a/spec/haml-spec/Rakefile b/spec/haml-spec/Rakefile new file mode 100644 index 00000000..66df6866 --- /dev/null +++ b/spec/haml-spec/Rakefile @@ -0,0 +1,6 @@ +desc 'Run haml-spec' +task :spec do + system('ruby ruby_haml_test.rb') +end + +task default: :spec diff --git a/spec/haml-spec/lua_haml_spec.lua b/spec/haml-spec/lua_haml_spec.lua deleted file mode 100644 index c8458d8f..00000000 --- a/spec/haml-spec/lua_haml_spec.lua +++ /dev/null @@ -1,38 +0,0 @@ -local dir = require 'pl.dir' -local haml = require 'haml' -local json = require 'json' -local path = require 'pl.path' -local telescope = require 'telescope' -local assert = assert -local describe = telescope.describe -local getinfo = debug.getinfo -local it = telescope.it -local open = io.open -local pairs = pairs - -module('hamlspec') - -local function get_tests(filename) - local me = path.abspath(getinfo(1).source:match("@(.*)$")) - return path.join(path.dirname(me), filename) -end - -local json_file = get_tests("tests.json") -local file = assert(open(json_file)) -local input = file:read '*a' -file:close() - -local contexts = json.decode(input) - -describe("LuaHaml", function() - for context, expectations in pairs(contexts) do - describe("When handling " .. context, function() - for name, exp in pairs(expectations) do - it(("should correctly render %s"):format(name), function() - local engine = haml.new(exp.config) - assert_equal(engine:render(exp.haml, exp.locals), exp.html) - end) - end - end) - end -end) \ No newline at end of file diff --git a/spec/haml-spec/perl_haml_test.pl b/spec/haml-spec/perl_haml_test.pl deleted file mode 100644 index 9c44b459..00000000 --- a/spec/haml-spec/perl_haml_test.pl +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use Test::More 'no_plan'; -use Text::Haml; -use FindBin; -use JSON 'from_json'; - -our $VERSION = 0.990101; - -my $tests; - -open FILE, "< $FindBin::Bin/tests.json" or die $!; -$tests = from_json(join("\n", )); -close FILE; - -while (my ($section_name, $section) = each %$tests) { - diag $section_name; - - while (my ($test_name, $test) = each %$section) { - is( Text::Haml->new(%{$test->{config}}, vars_as_subs => 1) - ->render($test->{haml}, %{$test->{locals}}), - $test->{html}, $test_name - ); - } -} -__END__ - -=head1 NAME - -perl_haml_test.pl - Text::Haml spec tests runner - -=head1 SYNOPSIS - - $ perl perl_haml_test.pl - - # conditional comments - ok 1 - a conditional comment - # tags with nested content - ok 2 - a tag with CSS - - ... - - ok 81 - an inline comment - ok 82 - a nested comment - 1..82 - -=head1 DESCRIPTION - -This file is a part of Haml spec tests envorinment. It tests Perl -implementation using . - -=head1 DEPENDENCIES - -=over - - * Text::Haml (available via CPAN or http://github.com/vti/text-haml) - * JSON (available on CPAN) - * Test::More (included in Perl core) - * FindBin (included in Perl core) - -=back - -=head1 SEE ALSO - -L - -=head1 AUTHOR - -Viacheslav Tykhanovskyi, C. - -=head1 COPYRIGHT AND LICENSE - -Copyright (C) 2009, Viacheslav Tykhanovskyi - -This program is free software, you can redistribute it and/or modify it under -the terms of the Artistic License version 2.0. - -=cut diff --git a/spec/haml-spec/ruby_haml_test.rb b/spec/haml-spec/ruby_haml_test.rb index 4774da1f..94778922 100644 --- a/spec/haml-spec/ruby_haml_test.rb +++ b/spec/haml-spec/ruby_haml_test.rb @@ -1,7 +1,9 @@ +$:.unshift File.expand_path('../../../lib', __FILE__) + require "rubygems" require "minitest/autorun" require "json" -require "haml" +require "hamlit" class HamlTest < MiniTest::Unit::TestCase contexts = JSON.parse(File.read(File.dirname(__FILE__) + "/tests.json")) @@ -13,7 +15,7 @@ class HamlTest < MiniTest::Unit::TestCase locals = Hash[(test["locals"] || {}).map {|x, y| [x.to_sym, y]}] options = Hash[(test["config"] || {}).map {|x, y| [x.to_sym, y]}] options[:format] = options[:format].to_sym if options.key?(:format) - engine = Haml::Engine.new(haml, options) + engine = Hamlit::Template.new { haml } result = engine.render(Object.new, locals) assert_equal html, result.strip