From 1658f91b3fd16924e15af95a4ebf160546258d47 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 23 Mar 2015 00:32:40 +0900 Subject: [PATCH] Convert haml-spec into rspec --- Rakefile | 2 +- haml-spec/ruby_haml_test.rb | 2 +- spec/haml-spec/Rakefile | 41 ++ spec/haml-spec/ruby_haml_spec.rb | 1070 ++++++++++++++++++++++++++++++ 4 files changed, 1113 insertions(+), 2 deletions(-) create mode 100644 spec/haml-spec/Rakefile create mode 100644 spec/haml-spec/ruby_haml_spec.rb diff --git a/Rakefile b/Rakefile index cd227dc4..d7806b2f 100644 --- a/Rakefile +++ b/Rakefile @@ -20,7 +20,7 @@ end namespace :haml do desc 'Run Haml Spec' task :spec do - system('cd haml-spec && rake spec') + system('bundle exec rspec --pattern spec/haml-spec/**{,/\*/\*\*\}/\*_spec.rb') end end diff --git a/haml-spec/ruby_haml_test.rb b/haml-spec/ruby_haml_test.rb index a446c0a9..557854df 100644 --- a/haml-spec/ruby_haml_test.rb +++ b/haml-spec/ruby_haml_test.rb @@ -1,4 +1,4 @@ -$:.unshift File.expand_path('../../../lib', __FILE__) +$:.unshift File.expand_path('../../lib', __FILE__) require "rubygems" require "minitest/autorun" diff --git a/spec/haml-spec/Rakefile b/spec/haml-spec/Rakefile new file mode 100644 index 00000000..9e606c9d --- /dev/null +++ b/spec/haml-spec/Rakefile @@ -0,0 +1,41 @@ +$:.unshift File.expand_path('../../../lib', __FILE__) + +require 'json' + +desc 'Convert tests.json into rspec tests' +task :convert do + tests = [] + + contexts = JSON.parse(File.read(File.expand_path('../../../haml-spec/tests.json', __FILE__))) + contexts.each do |context| + context[1].each_with_index do |(name, test), index| + tests << { + name: "#{name} (#{context[0]})", + html: test['html'], + haml: test['haml'], + locals: test['locals'], + config: test['config'], + } + end + end + + spec = "describe 'haml-spec' do\n" + spec += tests.map { |test| + options = Hash[(test[:config] || {}).map {|x, y| [x.to_sym, y]}] + + spec = " specify %q{#{test[:name]}} do\n" + spec += " html = %q{#{test[:html]}}\n" + spec += " haml = %q{#{test[:haml]}}\n" + spec += " locals = Hash[#{test[:locals] || {}}.map {|x, y| [x.to_sym, y]}]\n" + spec += " options = #{options}\n" + spec += " options[:format] = '#{options[:format]}'\n" if options.key?(:format) + spec += " engine = Hamlit::Template.new(options) { haml }\n" + spec += " result = engine.render(Object.new, locals)\n" + spec += " expect(result.strip).to eq(html)\n" + spec += " end\n" + }.join("\n") + spec += "end\n" + File.write('ruby_haml_spec.rb', spec) +end + +task default: :convert diff --git a/spec/haml-spec/ruby_haml_spec.rb b/spec/haml-spec/ruby_haml_spec.rb new file mode 100644 index 00000000..2c70b56f --- /dev/null +++ b/spec/haml-spec/ruby_haml_spec.rb @@ -0,0 +1,1070 @@ +describe 'haml-spec' do + specify %q{an XHTML XML prolog (headers)} do + html = %q{} + haml = %Q{!!! XML} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an XHTML default (transitional) doctype (headers)} do + html = %q{} + haml = %Q{!!!} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an XHTML 1.1 doctype (headers)} do + html = %q{} + haml = %Q{!!! 1.1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an XHTML 1.2 mobile doctype (headers)} do + html = %q{} + haml = %Q{!!! mobile} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an XHTML 1.1 basic doctype (headers)} do + html = %q{} + haml = %Q{!!! basic} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an XHTML 1.0 frameset doctype (headers)} do + html = %q{} + haml = %Q{!!! frameset} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 5 doctype with XHTML syntax (headers)} do + html = %q{} + haml = %Q{!!! 5} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 5 XML prolog (silent) (headers)} do + html = %q{} + haml = %Q{!!! XML} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 5 doctype (headers)} do + html = %q{} + haml = %Q{!!!} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 4 XML prolog (silent) (headers)} do + html = %q{} + haml = %Q{!!! XML} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html4"} + options[:format] = 'html4' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 4 default (transitional) doctype (headers)} do + html = %q{} + haml = %Q{!!!} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html4"} + options[:format] = 'html4' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 4 frameset doctype (headers)} do + html = %q{} + haml = %Q{!!! frameset} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html4"} + options[:format] = 'html4' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an HTML 4 strict doctype (headers)} do + html = %q{} + haml = %Q{!!! strict} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html4"} + options[:format] = 'html4' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a simple Haml tag (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a self-closing tag (XHTML) (basic Haml tags and CSS)} do + html = %q{} + haml = %Q{%meta} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a self-closing tag (HTML4) (basic Haml tags and CSS)} do + html = %q{} + haml = %Q{%meta} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html4"} + options[:format] = 'html4' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a self-closing tag (HTML5) (basic Haml tags and CSS)} do + html = %q{} + haml = %Q{%meta} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a self-closing tag ('/' modifier + XHTML) (basic Haml tags and CSS)} do + html = %q{} + haml = %Q{%zzz/} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a self-closing tag ('/' modifier + HTML5) (basic Haml tags and CSS)} do + html = %q{} + haml = %Q{%zzz/} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with a CSS class (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p.class1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with multiple CSS classes (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p.class1.class2} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with a CSS id (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p#id1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with multiple CSS id's (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p#id1#id2} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with a class followed by an id (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p.class1#id1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with an id followed by a class (basic Haml tags and CSS)} do + html = %q{

} + haml = %Q{%p#id1.class1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an implicit div with a CSS id (basic Haml tags and CSS)} do + html = %q{
} + haml = %Q{#id1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an implicit div with a CSS class (basic Haml tags and CSS)} do + html = %q{
} + haml = %Q{.class1} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{multiple simple Haml tags (basic Haml tags and CSS)} do + html = %q{
+
+

+
+
} + haml = %Q{%div + %div + %p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with colons (tags with unusual HTML characters)} do + html = %q{} + haml = %Q{%ns:tag} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with underscores (tags with unusual HTML characters)} do + html = %q{} + haml = %Q{%snake_case} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with dashes (tags with unusual HTML characters)} do + html = %q{} + haml = %Q{%dashed-tag} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with camelCase (tags with unusual HTML characters)} do + html = %q{} + haml = %Q{%camelCase} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with PascalCase (tags with unusual HTML characters)} do + html = %q{} + haml = %Q{%PascalCase} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an all-numeric class (tags with unusual CSS identifiers)} do + html = %q{
} + haml = %Q{.123} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a class with underscores (tags with unusual CSS identifiers)} do + html = %q{
} + haml = %Q{.__} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a class with dashes (tags with unusual CSS identifiers)} do + html = %q{
} + haml = %Q{.--} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Inline content simple tag (tags with inline content)} do + html = %q{

hello

} + haml = %Q{%p hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Inline content tag with CSS (tags with inline content)} do + html = %q{

hello

} + haml = %Q{%p.class1 hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Inline content multiple simple tags (tags with inline content)} do + html = %q{
+
+

text

+
+
} + haml = %Q{%div + %div + %p text} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Nested content simple tag (tags with nested content)} do + html = %q{

+ hello +

} + haml = %Q{%p + hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Nested content tag with CSS (tags with nested content)} do + html = %q{

+ hello +

} + haml = %Q{%p.class1 + hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Nested content multiple simple tags (tags with nested content)} do + html = %q{
+
+

+ text +

+
+
} + haml = %Q{%div + %div + %p + text} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style one attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(a='b')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style multiple attributes (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(a='b' c='d')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style attributes separated with newlines (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(a='b' + c='d')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style interpolated attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(a="#{var}")} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style 'class' as an attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(class='class1')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag with a CSS class and 'class' as an attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p.class2(class='class1')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag with 'id' as an attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(id='1')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag with a CSS id and 'id' as an attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p#id(id='1')} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag with a variable attribute (tags with HTML-style attributes)} do + html = %q{

} + haml = %Q{%p(class=var)} + locals = Hash[{"var"=>"hello"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag with a CSS class and 'class' as a variable attribute (tags with HTML-style attributes)} do + html = %q{
} + haml = %Q{.hello(class=var)} + locals = Hash[{"var"=>"world"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{HTML-style tag multiple CSS classes (sorted correctly) (tags with HTML-style attributes)} do + html = %q{
} + haml = %Q{.z(class=var)} + locals = Hash[{"var"=>"a"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style one attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{:a => 'b'}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style attributes hash with whitespace (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{ :a => 'b' }} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style interpolated attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{:a =>"#{var}"}} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style multiple attributes (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{ :a => 'b', 'c' => 'd' }} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style attributes separated with newlines (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{ :a => 'b', + 'c' => 'd' }} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style 'class' as an attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{:class => 'class1'}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with a CSS class and 'class' as an attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p.class2{:class => 'class1'}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with 'id' as an attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{:id => '1'}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with a CSS id and 'id' as an attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p#id{:id => '1'}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with a CSS id and a numeric 'id' as an attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p#id{:id => 1}} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with a variable attribute (tags with Ruby-style attributes)} do + html = %q{

} + haml = %Q{%p{:class => var}} + locals = Hash[{"var"=>"hello"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag with a CSS class and 'class' as a variable attribute (tags with Ruby-style attributes)} do + html = %q{
} + haml = %Q{.hello{:class => var}} + locals = Hash[{"var"=>"world"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{Ruby-style tag multiple CSS classes (sorted correctly) (tags with Ruby-style attributes)} do + html = %q{
} + haml = %Q{.z{:class => var}} + locals = Hash[{"var"=>"a"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an inline silent comment (silent comments)} do + html = %q{} + haml = %Q{-# hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a nested silent comment (silent comments)} do + html = %q{} + haml = %Q{-# + hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a multiply nested silent comment (silent comments)} do + html = %q{} + haml = %Q{-# + %div + foo} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a multiply nested silent comment with inconsistent indents (silent comments)} do + html = %q{} + haml = %Q{-# + %div + foo} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{an inline markup comment (markup comments)} do + html = %q{} + haml = %Q{/ comment} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a nested markup comment (markup comments)} do + html = %q{} + haml = %Q{/ + comment + comment2} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a conditional comment (conditional comments)} do + html = %q{} + haml = %Q{/[if IE] + %p a} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in an 'escaped' filter (internal filters)} do + html = %q{<&">} + haml = %Q{:escaped + <&">} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'preserve' filter (internal filters)} do + html = %q{hello +

} + haml = %Q{:preserve + hello + +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'plain' filter (internal filters)} do + html = %q{hello +

} + haml = %Q{:plain + hello + +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'css' filter (XHTML) (internal filters)} do + html = %q{ +

} + haml = %Q{:css + hello + +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'javascript' filter (XHTML) (internal filters)} do + html = %q{ +

} + haml = %Q{:javascript + a(); +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'css' filter (HTML) (internal filters)} do + html = %q{ +

} + haml = %Q{:css + hello + +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{content in a 'javascript' filter (HTML) (internal filters)} do + html = %q{ +

} + haml = %Q{:javascript + a(); +%p} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{interpolation inside inline content (Ruby-style interpolation)} do + html = %q{

value

} + haml = %Q{%p #{var}} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{no interpolation when escaped (Ruby-style interpolation)} do + html = %q{

#{var}

} + haml = %Q{%p \#{var}} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{interpolation when the escape character is escaped (Ruby-style interpolation)} do + html = %q{

\value

} + haml = %Q{%p \\#{var}} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{interpolation inside filtered content (Ruby-style interpolation)} do + html = %q{value interpolated: value} + haml = %Q{:plain + #{var} interpolated: #{var}} + locals = Hash[{"var"=>"value"}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{code following '&=' (HTML escaping)} do + html = %q{<"&>} + haml = %Q{&= '<"&>'} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{code following '=' when escape_haml is set to true (HTML escaping)} do + html = %q{<"&>} + haml = %Q{= '<"&>'} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:escape_html=>"true"} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{code following '!=' when escape_haml is set to true (HTML escaping)} do + html = %q{<"&>} + haml = %Q{!= '<"&>'} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:escape_html=>"true"} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{boolean attribute with XHTML (boolean attributes)} do + html = %q{} + haml = %Q{%input(checked=true)} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"xhtml"} + options[:format] = 'xhtml' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{boolean attribute with HTML (boolean attributes)} do + html = %q{} + haml = %Q{%input(checked=true)} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {:format=>"html5"} + options[:format] = 'html5' + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{following the '~' operator (whitespace preservation)} do + html = %q{Foo +
Bar
Baz
} + haml = %Q{~ "Foo\n
Bar\nBaz
"} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{inside a textarea tag (whitespace preservation)} do + html = %q{} + haml = %Q{%textarea + hello + hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{inside a pre tag (whitespace preservation)} do + html = %q{
hello
+hello
} + haml = %Q{%pre + hello + hello} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with '>' appended and inline content (whitespace removal)} do + html = %q{
  • hello
  • world
  • again
  • } + haml = %Q{%li hello +%li> world +%li again} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with '>' appended and nested content (whitespace removal)} do + html = %q{
  • hello
  • + world +
  • again
  • } + haml = %Q{%li hello +%li> + world +%li again} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end + + specify %q{a tag with '<' appended (whitespace removal)} do + html = %q{

    hello +world

    } + haml = %Q{%p< + hello + world} + locals = Hash[{}.map {|x, y| [x.to_sym, y]}] + options = {} + engine = Hamlit::Template.new(options) { haml } + result = engine.render(Object.new, locals) + expect(result.strip).to eq(html) + end +end