diff --git a/test/hamlit/engine/old_attribute_test.rb b/test/hamlit/engine/old_attribute_test.rb new file mode 100644 index 00000000..1aa0e8ad --- /dev/null +++ b/test/hamlit/engine/old_attribute_test.rb @@ -0,0 +1,399 @@ +describe Hamlit::Engine do + include RenderAssertion + + describe 'old attributes' do + it 'renders attributes' do + assert_render(<<-HAML, <<-HTML) + %span{class: 'foo'} bar + HAML + bar + HTML + end + + it 'renders attributes' do + assert_render(<<-HAML, <<-HTML) + %span{ data: 2 } bar + HAML + bar + HTML + end + + it 'renders attributes' do + assert_render(<<-'HAML', <<-HTML) + %span{ :class => 'foo' } bar + HAML + bar + HTML + end + + it 'renders attributes' do + assert_render(<<-'HAML', <<-HTML) + %span{ :class => 'foo', id: 'bar' } bar + HAML + bar + HTML + end + + it 'renders attributes' do + assert_render(<<-'HAML', <<-HTML) + %span{ :'data-disable' => true } bar + HAML + bar + HTML + end + + it 'accepts method call including comma' do + assert_render(<<-'HAML', <<-HTML) + %body{ class: "#{"ab".gsub(/a/, 'b')}", data: { confirm: 'really?', disable: true }, id: 'c'.gsub(/c/, 'a') } + HAML + + HTML + end + + it 'accepts tag content' do + assert_render(<<-'HAML', <<-HTML) + %span{ class: 'foo' } bar + HAML + bar + HTML + end + + it 'renders multi-byte chars as static attribute value' do + assert_render(<<-'HAML', <<-HTML) + %img{ alt: 'こんにちは' } + HAML + こんにちは + HTML + end + + it 'sorts static attributes by name' do + assert_render(<<-HAML, <<-HTML) + %span{ :foo => "bar", :hoge => "piyo"} + %span{ :hoge => "piyo", :foo => "bar"} + HAML + + + HTML + end + + describe 'runtime attributes' do + it 'renders runtime hash attribute' do + assert_render(<<-'HAML', <<-HTML) + - hash = { foo: 'bar' } + %span{ hash } + HAML + + HTML + end + + it 'renders multiples hashes' do + assert_render(<<-'HAML', <<-HTML) + - h1 = { a: 'b' } + - h2 = { c: 'd' } + - h3 = { e: 'f' } + %span{ h1, h2, h3 } + HAML + + HTML + end + + it 'renders multiples hashes and literal hash' do + assert_render(<<-'HAML', <<-HTML) + - h1 = { a: 'b' } + - h2 = { c: 'd' } + - h3 = { e: 'f' } + %span{ h1, h2, h3, g: 'h', i: 'j' } + HAML + + HTML + end + end + + describe 'joinable attributes' do + it 'joins class with a space' do + assert_render(<<-'HAML', <<-HTML) + - val = ['a', 'b', 'c'] + %p{ class: val } + %p{ class: %w[a b c] } + %p{ class: ['a', 'b', 'c'] } + HAML +

+

+

+ HTML + end + + it 'joins attribute class and element class' do + assert_render(<<-HAML, <<-HTML, compatible_only: :haml) + .foo{ class: ['bar'] } + .foo{ class: ['bar', 'foo'] } + .foo{ class: ['bar', nil] } + .foo{ class: ['bar', 'baz'] } + HAML +
+
+
+
+ HTML + end + + it 'joins id with an underscore' do + assert_render(<<-'HAML', <<-HTML) + - val = ['a', 'b', 'c'] + %p{ id: val } + %p{ id: %w[a b c] } + %p{ id: ['a', 'b', 'c'] } + HAML +

+

+

+ HTML + end + + it 'does not join others' do + assert_render(<<-'HAML', <<-HTML) + %a{ data: { value: [count: 1] } } + HAML + + HTML + end + end + + describe 'deletable attributes' do + it 'deletes attributes whose value is nil or false' do + assert_render(<<-'HAML', <<-HTML) + - hash = { checked: false } + %input{ hash } + %input{ checked: false } + %input{ checked: nil } + - checked = nil + %input{ checked: checked } + - checked = false + %input{ checked: checked } + HAML + + + + + + HTML + end + + it 'deletes some limited attributes with dynamic value' do + assert_render(<<-'HAML', <<-HTML) + - val = false + #foo.bar{ autofocus: val } + #foo.bar{ checked: val } + #foo.bar{ data: { disabled: val } } + #foo.bar{ disabled: val } + #foo.bar{ formnovalidate: val } + #foo.bar{ multiple: val } + #foo.bar{ readonly: val } + #foo.bar{ required: val } + HAML +
+
+
+
+
+
+
+
+ HTML + end + + it 'does not delete non-boolean attributes, for optimization' do + skip + assert_render(<<-'HAML', <<-HTML, compatible_only: []) + / wontfix: Non-boolean attributes are not escaped for optimization. + - val = false + %a{ href: val } + - val = nil + %a{ href: val } + + / Boolean attributes are escaped correctly. + - val = false + %a{ disabled: val } + - val = nil + %a{ disabled: val } + HAML + + + + + + + HTML + end + end + + describe 'html escape' do + it 'escapes attribute values on static attributes' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :faml) + %a{title: "'"} + %a{title: "'\""} + %a{href: '/search?foo=bar&hoge='} + HAML + + + + HTML + end + + it 'escapes attribute values on dynamic attributes' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :faml) + - title = "'\"" + - href = '/search?foo=bar&hoge=' + %a{title: title} + %a{href: href} + HAML + + + HTML + end + + it 'escapes attribute values on hash attributes' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :faml) + - title = { title: "'\"" } + - href = { href: '/search?foo=bar&hoge=' } + %a{ title } + %a{ href } + HAML + + + HTML + end + end + + describe 'nested attributes' do + it 'renders data attribute by hash' do + assert_render(<<-'HAML', <<-HTML) + - hash = { bar: 'baz' } + %span.foo{ data: hash } + HAML + + HTML + end + + it 'renders true attributes' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml) + %span{ data: { disable: true } } bar + HAML + bar + HTML + end + + it 'renders nested hash whose value is variable' do + assert_render(<<-'HAML', <<-HTML) + - hash = { disable: true } + %span{ data: hash } bar + HAML + bar + HTML + end + + it 'changes an underscore in a nested key to a hyphen' do + assert_render(<<-'HAML', <<-HTML) + %div{ data: { raw_src: 'foo' } } + HAML +
+ HTML + end + + it 'changes an underscore in a nested dynamic attribute' do + assert_render(<<-'HAML', <<-HTML) + - hash = { raw_src: 'foo' } + %div{ data: hash } + HAML +
+ HTML + end + end + + describe 'element class with attribute class' do + it 'does not generate double classes' do + assert_render(<<-HAML, <<-HTML) + .item{ class: 'first' } + HAML +
+ HTML + end + + it 'does not generate double classes for a variable' do + assert_render(<<-HAML, <<-HTML) + - val = 'val' + .element{ class: val } + HAML +
+ HTML + end + + it 'does not generate double classes for hash attributes' do + assert_render(<<-HAML, <<-HTML) + - hash = { class: 'val' } + .element{ hash } + HAML +
+ HTML + end + end + + describe 'element id with attribute id' do + it 'does not generate double ids' do + assert_render(<<-HAML, <<-HTML) + #item{ id: 'first' } + HAML +
+ HTML + end + + it 'does not generate double ids for a variable' do + assert_render(<<-HAML, <<-HTML) + - val = 'first' + #item{ id: val } + HAML +
+ HTML + end + + it 'does not generate double ids for hash attributes' do + assert_render(<<-HAML, <<-HTML) + - hash = { id: 'first' } + #item{ hash } + HAML +
+ HTML + end + + it 'does not generate double ids and classes for hash attributes' do + assert_render(<<-HAML, <<-HTML) + - hash = { id: 'first', class: 'foo' } + #item.bar{ hash } + HAML +
+ HTML + end + end + + if RUBY_VERSION >= "2.2.0" + describe 'Ruby 2.2 syntax' do + it 'renders static attributes' do + assert_render(<<-HAML, <<-HTML) + %meta{ content: 'IE=edge', 'http-equiv': 'X-UA-Compatible' } + HAML + + HTML + end + + it 'renders dynamic attributes' do + assert_render(<<-HAML, <<-HTML) + - hash = { content: 'IE=edge' } + %meta{ hash, 'http-equiv': 'X-UA-Compatible' } + HAML + + HTML + end + end + end + end +end diff --git a/test/hamlit/engine/script_test.rb b/test/hamlit/engine/script_test.rb new file mode 100644 index 00000000..18d335c6 --- /dev/null +++ b/test/hamlit/engine/script_test.rb @@ -0,0 +1,124 @@ +describe Hamlit::Engine do + include RenderAssertion + + describe 'script' do + it 'renders one-line script' do + assert_render(<<-HAML, <<-HTML) + = 1 + 2 + %span= 3 * 4 + HAML + 3 + 12 + HTML + end + + it 'renders one-line script with comment' do + skip + assert_render(<<-HAML, <<-HTML) + = # comment_only + = '#' + "#" # = 3 # + = ['#', + "#"] # comment + HAML + + ## + ["#", "#"] + HTML + end + + it 'renders multi-lines script' do + assert_render(<<-HAML, <<-HTML) + %span + = 1 + 2 + 4 / 2 + %a= 3 - 4 + HAML + + 3 + 4 / 2 + -1 + + HTML + end + + it 'renders block script' do + skip + assert_render(<<-HAML, <<-HTML) + = 3.times do |i| + = i + 4 + HAML + 0 + 1 + 2 + 34 + HTML + end + + it 'renders tag internal block script' do + skip + assert_render(<<-HAML, <<-HTML) + %span + = 1.times do |i| + = i + HAML + + 0 + 1 + HTML + end + + it 'renders block and a variable with spaces' do + assert_render(<<-HAML, <<-HTML) + - 1.times do | i | + = i + HAML + 0 + HTML + end + + it 'accepts a continuing script' do + assert_render(<<-HAML, <<-HTML) + - def foo(a, b); a + b; end + = foo(1, + 2) + HAML + 3 + HTML + end + + it 'renders !=' do + skip + assert_render(<<-HAML, <<-HTML.rstrip, escape_html: true) + != '<"&>' + != '<"&>'.tap do |str| + -# no operation + HAML + <"&> + <"&> + HTML + end + + it 'renders &=' do + skip + assert_render(<<-HAML, <<-HTML.rstrip, escape_html: false) + &= '<"&>' + &= '<"&>'.tap do |str| + -# no operation + HAML + <"&> + <"&> + HTML + end + + it 'regards ~ operator as =' do + skip + assert_render(<<-'HAML', <<-HTML) + ~ "hello\nworld" + HAML + <code>hello + world</code> + HTML + end + end +end diff --git a/test/hamlit/engine/silent_script_test.rb b/test/hamlit/engine/silent_script_test.rb new file mode 100644 index 00000000..1086b16b --- /dev/null +++ b/test/hamlit/engine/silent_script_test.rb @@ -0,0 +1,216 @@ +describe Hamlit::Engine do + include RenderAssertion + + describe 'silent script' do + it 'renders nothing' do + assert_render(<<-HAML, <<-HTML) + - nil + - 3 + - 'foo' + HAML + HTML + end + + it 'renders silent script' do + assert_render(<<-HAML, <<-HTML) + - foo = 3 + - bar = 2 + = foo + bar + HAML + 5 + HTML + end + + it 'renders nested block' do + assert_render(<<-HAML, <<-HTML) + - 2.times do |i| + = i + 2 + - 3.upto(4).each do |i| + = i + HAML + 0 + 1 + 2 + 3 + 4 + HTML + end + + it 'renders if' do + assert_render(<<-HAML, <<-HTML) + - if true + ok + HAML + ok + HTML + end + + it 'renders if-else' do + assert_render(<<-HAML, <<-HTML) + - if true + ok + - else + ng + + - if false + ng + + - else + ok + HAML + ok + ok + HTML + end + + it 'renders nested if-else' do + assert_render(<<-'HAML', <<-HTML) + %span + - if false + ng + - else + ok + HAML + + ok + + HTML + end + + it 'renders empty elsif statement' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml) + %span + - if false + - elsif false + HAML + + + HTML + end + + it 'renders empty else statement' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml) + %span + - if false + ng + - else + HAML + + + HTML + end + + it 'renders empty when statement' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml) + %span + - case + - when false + HAML + + + HTML + end + + it 'accept if inside if-else' do + assert_render(<<-'HAML', <<-HTML) + - if false + - if true + ng + - else + ok + HAML + ok + HTML + end + + it 'renders if-elsif' do + assert_render(<<-HAML, <<-HTML) + - if false + - elsif true + ok + + - if false + - elsif false + - else + ok + HAML + ok + ok + HTML + end + + it 'renders case-when' do + assert_render(<<-'HAML', <<-HTML) + - case 'foo' + - when /\Ao/ + ng + - when /\Af/ + ok + - else + ng + HAML + ok + HTML + end + + it 'renders case-when with multiple candidates' do + assert_render(<<-'HAML', <<-HTML) + - case 'a' + - when 'a', 'b' + ok + HAML + ok + HTML + end + + it 'renders begin-rescue' do + assert_render(<<-'HAML', <<-HTML) + - begin + - raise 'error' + - rescue + hello + - ensure + world + HAML + hello + world + HTML + end + + it 'renders rescue with error' do + assert_render(<<-'HAML', <<-HTML) + - begin + - raise 'error' + - rescue RuntimeError => e + hello + HAML + hello + HTML + end + + it 'joins a next line if a current line ends with ","' do + skip + assert_render("- foo = [', \n ']\n= foo", <<-HTML, compatible_only: :haml) + [", "] + HTML + end + + it 'accepts illegal indent in continuing code' do + assert_render(<<-HAML, <<-HTML) + %span + %div + - def foo(a, b); a + b; end + - num = foo(1, + 2) + = num + HAML + +
+ 3 +
+
+ HTML + end + end +end diff --git a/test/hamlit/engine/tag_test.rb b/test/hamlit/engine/tag_test.rb new file mode 100644 index 00000000..59e96119 --- /dev/null +++ b/test/hamlit/engine/tag_test.rb @@ -0,0 +1,303 @@ +describe Hamlit::Engine do + include RenderAssertion + + describe 'tag' do + it 'renders one-line tag' do + assert_render(<<-HAML, <<-HTML) + %span hello + HAML + hello + HTML + end + + it 'accepts multi-line =' do + assert_render(<<-HAML, <<-HTML) + %span= 'hello'.gsub('hell', + '') + HAML + o + HTML + end + + it 'renders multi-line tag' do + skip + assert_render(<<-HAML, <<-HTML) + %span + hello + HAML + + hello + + HTML + end + + it 'renders a nested tag' do + assert_render(<<-HAML, <<-HTML) + %span + %b + hello + %i + %small world + HAML + + + hello + + + world + + + HTML + end + + it 'renders multi-line texts' do + assert_render(<<-HAML, <<-HTML) + %span + %b + hello + world + HAML + + + hello + world + + + HTML + end + + it 'skips empty lines' do + assert_render(<<-HAML, <<-HTML) + %span + + %b + + hello + + HAML + + + hello + + + HTML + end + + it 'renders classes' do + assert_render(<<-HAML, <<-HTML) + %span.foo-1.bar_A hello + HAML + hello + HTML + end + + it 'renders ids only last one' do + assert_render(<<-HAML, <<-HTML) + %span#Bar_0#bar- + hello + HAML + + hello + + HTML + end + + it 'renders ids and classes' do + assert_render(<<-HAML, <<-HTML) + %span#a.b#c.d hello + HAML + hello + HTML + end + + it 'renders implicit div tag starting with id' do + assert_render(<<-HAML, <<-HTML) + #hello.world + HAML +
+ HTML + end + + it 'renders implicit div tag starting with class' do + assert_render(<<-HAML, <<-HTML) + .world#hello + foo + HAML +
+ foo +
+ HTML + end + + it 'renders large-case tag' do + assert_render(<<-HAML, <<-HTML) + %SPAN + foo + HAML + + foo + + HTML + end + + it 'renders h1 tag' do + assert_render(<<-HAML, <<-HTML) + %h1 foo + HAML +

foo

+ HTML + end + + it 'renders tag including hyphen or underscore' do + assert_render(<<-HAML, <<-HTML) + %-_ foo + HAML + <-_>foo + HTML + end + + it 'does not render silent script just after a tag' do + assert_render(<<-HAML, <<-HTML) + %span- raise 'a' + HAML + raise 'a' + HTML + end + + it 'renders a text just after attributes' do + assert_render(<<-HAML, <<-HTML) + %span{a: 2}a + HAML + a + HTML + end + + it 'strips a text' do + assert_render(<<-HAML, <<-HTML) + %span foo + HAML + foo + HTML + end + + it 'ignores spaces after tag' do + assert_render("%span \n a", <<-HTML) + + a + + HTML + end + + it 'parses self-closing tag' do + assert_render(<<-HAML, <<-HTML, format: :xhtml) + %div/ + %div + HAML +
+
+ HTML + end + + describe 'whitespace removal' do + it 'removes outer whitespace by >' do + assert_render(<<-HAML, <<-HTML) + %span> a + %span b + %span c + %span> + d + %span + e + %span f + HAML + ab + c + d + + e + + f + HTML + end + + it 'removes outer whitespace by > from inside of block' do + skip + assert_render(<<-HAML, <<-HTML) + %span a + - if true + %span> + b + %span + c + HAML + a + b + + c + + HTML + end + + it 'removes whitespaces inside block script' do + skip + assert_render(<<-HAML, <<-HTML) + %span< + = 2.times do + = 'foo' + %span> bar + HAML + foofoo2bar + HTML + end + + it 'removes whitespace inside script inside silent script' do + skip + assert_render(<<-HAML, <<-HTML) + .bar< + - 3.times do + = 'foo' + HAML +
foofoofoo
+ HTML + end + + it 'removes whitespace inside script recursively' do + skip + assert_render(<<-HAML, <<-HTML) + .foo< + - 1.times do + = 2.times do + - 2.times do + = 1.times do + = 'bar' + HAML +
bar1bar1bar1bar12
+ HTML + end + + it 'does not remove whitespace after string interpolation' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :faml) + %div< + #{'hello'} + world + HAML +
hello + world
+ HTML + end + + it 'removes whitespace inside script inside silent script' do + skip + assert_render(<<-HAML, <<-HTML, compatible_only: :faml) + .bar< + - 1.times do + = '1' + = '2' + HAML +
1 + 2
+ HTML + end + end + end +end diff --git a/test/hamlit/engine/text_test.rb b/test/hamlit/engine/text_test.rb new file mode 100644 index 00000000..b773885d --- /dev/null +++ b/test/hamlit/engine/text_test.rb @@ -0,0 +1,249 @@ +describe Hamlit::Engine do + include RenderAssertion + + describe 'text' do + it 'renders string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML) + #{ "a#{3}a" }a" #{["1", 2]} b " ! + a#{{ a: 3 }} + + HAML + a3aa" ["1", 2] b " ! + a{:a=>3} + + HTML + end + + it 'renders . or # which is not continued by tag name' do + skip + assert_render(<<-HAML, <<-HTML, error_with: [:haml, :faml]) + . + .* + .. + # + #+ + ## + HAML + . + .* + .. + # + #+ + ## + HTML + end + + it 'escapes all operators by backslash' do + assert_render(<<-'HAML', <<-HTML) + = 'a' + - + \= 'a' + \- + HAML + a + = 'a' + - + HTML + end + + it 'renders == operator' do + skip + assert_render(<<-'HAML', <<-HTML) + === + == = + == + == #{''} + HAML + = + = + + <a> + HTML + end + + it 'renders !== operator' do + skip + assert_render(<<-'HAML', <<-HTML) + == #{''} + !== #{''} + !=== + !== = + HAML + <a> + + = + = + HTML + end + + it 'leaves empty spaces after backslash' do + skip + expect(render_string('\ a')).to eq(" a\n") + end + + it 'renders spaced - properly' do + assert_render(<<-HAML, <<-'HTML') + %div + foo + .test - bar + .test - baz + HAML +
+ foo +
- bar
+
- baz
+
+ HTML + end + + describe 'inline operator' do + it 'renders ! operator' do + assert_render(<<-'HAML', <<-'HTML') + %span!#{''} + %span! #{''} + ! #{''} + HAML + + + + HTML + end + + it 'renders & operator' do + assert_render(<<-'HAML', <<-'HTML') + %span& #{''} + %span&#{''} + & #{''} + HAML + <nyaa> + <nyaa> + <nyaa> + HTML + end + + it 'renders !, & operator right before a non-space character' do + assert_render(<<-'HAML', <<-'HTML', compatible_only: :haml) +   + \  + !hello + \!hello + HAML +   +   + !hello + !hello + HTML + end + + it 'renders &, ! operator inside a tag' do + assert_render(<<-HAML, <<-HTML) + %span   + %span  + %span& nbsp; + %span !hello + %span!hello + %span! hello + HAML +   + nbsp; + nbsp; + !hello + hello + hello + HTML + end + + it 'does not accept backslash operator' do + assert_render(<<-'HAML', <<-'HTML') + %span\ foo + HAML + \ foo + HTML + end + + it 'renders != operator' do + assert_render(<<-'HAML', <<-'HTML') + %span!= '' + HAML + + HTML + end + + it 'renders !== operator' do + assert_render(<<-'HAML', <<-'HTML') + %span!==#{''} + %span!== #{''} + !==#{''} + !== #{''} + HAML + + + + + HTML + end + + it 'renders &= operator' do + skip + assert_render(<<-'HAML', <<-'HTML', escape_html: false) + %span&= '' + HAML + <nyaa> + HTML + end + + it 'renders &== operator' do + assert_render(<<-'HAML', <<-'HTML') + &=== + &== = + &== #{'

'} + HAML + = + = + <p> + HTML + end + + it 'renders ~ operator' do + assert_render(<<-HAML, <<-HTML, escape_html: false) + %span~ 1 + HAML + 1 + HTML + end + end + + describe 'string interpolation' do + specify { assert_render('#{}', "\n") } + specify { assert_render('1#{}', "1\n") } + specify { assert_render('1#{2}', "12\n") } + specify { assert_render('}#{1}', "}1\n") } + specify { assert_render('#{1}2', "12\n") } + specify { assert_render('1#{ "2#{3}4" }5', "12345\n") } + specify { assert_render('#{1}2#{3}4#{5}6#{7}8#{9}', "123456789\n") } + specify { assert_render(%q{'"!@$%^&*|=#{1}1#{1}2}, %Q{'"!@$%^&*|=1112\n}) } + specify { assert_render('あ#{1}', "あ1\n") } + specify { assert_render('あ#{"い"}う', "あいう\n") } + specify { skip; assert_render('a#{""}c', "a<b>c\n") } + end + + describe 'illegal inputs' do + it 'rejects an invalid tag' do + skip + expect { render_string(<<-HAML.unindent) }. + % a + HAML + to raise_error(Hamlit::SyntaxError, 'Invalid tag: "% a".') + end + + it 'rejects an invalid tag' do + skip + expect { render_string(<<-HAML.unindent) }. + %.foo + HAML + to raise_error(Hamlit::SyntaxError, 'Invalid tag: "%.foo".') + end + end + end +end diff --git a/test/hamlit/filters/coffee_test.rb b/test/hamlit/filters/coffee_test.rb new file mode 100644 index 00000000..97b294bb --- /dev/null +++ b/test/hamlit/filters/coffee_test.rb @@ -0,0 +1,65 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders coffee filter' do + skip + assert_render(<<-HAML, <<-HTML) + :coffee + foo = -> + alert('hello') + HAML + + HTML + end + + it 'renders coffeescript filter' do + skip + assert_render(<<-HAML, <<-HTML) + :coffee + foo = -> + alert('hello') + HAML + + HTML + end + + it 'renders coffeescript filter' do + skip + assert_render(<<-'HAML', <<-HTML) + :coffee + foo = -> + alert("#{'<&>'}") + HAML + + HTML + end + end +end diff --git a/test/hamlit/filters/css_test.rb b/test/hamlit/filters/css_test.rb new file mode 100644 index 00000000..595abc1b --- /dev/null +++ b/test/hamlit/filters/css_test.rb @@ -0,0 +1,37 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders css' do + skip + assert_render(<<-HAML, <<-HTML) + :css + .foo { + width: 100px; + } + HAML + + HTML + end + + it 'parses string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML) + :css + .foo { + content: "#{'<&>'}"; + } + HAML + + HTML + end + end +end diff --git a/test/hamlit/filters/erb_test.rb b/test/hamlit/filters/erb_test.rb new file mode 100644 index 00000000..ae5335ae --- /dev/null +++ b/test/hamlit/filters/erb_test.rb @@ -0,0 +1,19 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders erb filter' do + skip + assert_render(<<-HAML, <<-HTML, compatible_only: [], error_with: :faml) + :erb + <% if true %> + ok + <% else %> + ng + <% end %> + HAML + ok + HTML + end + end +end diff --git a/test/hamlit/filters/javascript_test.rb b/test/hamlit/filters/javascript_test.rb new file mode 100644 index 00000000..5dcc08ed --- /dev/null +++ b/test/hamlit/filters/javascript_test.rb @@ -0,0 +1,88 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'just renders script tag for empty filter' do + skip + assert_render(<<-HAML, <<-HTML, compatible_only: []) + before + :javascript + after + HAML + before + + after + HTML + end + + it 'compiles javascript filter' do + assert_render(<<-HAML, <<-HTML) + before + :javascript + alert('hello'); + after + HAML + before + + after + HTML + end + + it 'accepts illegal indentation' do + skip + assert_render(<<-HAML, <<-HTML, compatible_only: :faml) + :javascript + if { + alert('hello'); + } + :javascript + if { + alert('hello'); + } + HAML + + + HTML + end + + it 'accepts illegal indentation' do + skip + assert_render(<<-HAML, <<-HTML) + :javascript + if { + alert('a'); + } + HAML + + HTML + end + + it 'parses string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML) + :javascript + var a = "#{'<&>'}"; + HAML + + HTML + end + end +end diff --git a/test/hamlit/filters/less_test.rb b/test/hamlit/filters/less_test.rb new file mode 100644 index 00000000..8171c298 --- /dev/null +++ b/test/hamlit/filters/less_test.rb @@ -0,0 +1,41 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders less filter' do + skip + assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml) + :less + .users_controller { + .show_action { + margin: 10px; + padding: 20px; + } + } + HAML + + HTML + end + + it 'parses string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml) + :less + .foo { + content: "#{'<&>'}"; + } + HAML + + HTML + end + end +end diff --git a/test/hamlit/filters/markdown_test.rb b/test/hamlit/filters/markdown_test.rb new file mode 100644 index 00000000..7b922003 --- /dev/null +++ b/test/hamlit/filters/markdown_test.rb @@ -0,0 +1,34 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders markdown filter' do + skip + assert_render(<<-HAML, <<-HTML) + :markdown + # Hamlit + Yet another haml implementation + HAML +

Hamlit

+ +

Yet another haml implementation

+ HTML + end + + it 'renders markdown filter with string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML, compatible_only: :faml) + - project = '' + :markdown + # #{project} + #{'<&>'} + Yet another haml implementation + HAML +

+ +

<&> + Yet another haml implementation

+ HTML + end + end +end diff --git a/test/hamlit/filters/plain_test.rb b/test/hamlit/filters/plain_test.rb new file mode 100644 index 00000000..8df5f4c6 --- /dev/null +++ b/test/hamlit/filters/plain_test.rb @@ -0,0 +1,17 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders plain filter' do + assert_render(<<-'HAML', <<-HTML, compatible_only: :haml) + :plain + あ + #{'い'} + HAML + あ + い + + HTML + end + end +end diff --git a/test/hamlit/filters/ruby_test.rb b/test/hamlit/filters/ruby_test.rb new file mode 100644 index 00000000..8ec8ba85 --- /dev/null +++ b/test/hamlit/filters/ruby_test.rb @@ -0,0 +1,26 @@ +describe Hamlit::Filters do + include RenderAssertion + + it 'renders ruby filter' do + skip + assert_render(<<-HAML, <<-HTML) + :ruby + hello + HAML + hello + HTML + end + + it 'renders ruby filter' do + skip + assert_render(<<-'HAML', <<-HTML) + :ruby + hash = { + a: "#{'<&>'}", + } + = hash[:a] + HAML + <&> + HTML + end +end diff --git a/test/hamlit/filters/sass_test.rb b/test/hamlit/filters/sass_test.rb new file mode 100644 index 00000000..c82bc401 --- /dev/null +++ b/test/hamlit/filters/sass_test.rb @@ -0,0 +1,37 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders sass filter' do + skip + assert_render(<<-HAML, <<-HTML) + :sass + .users_controller + .show_action + margin: 10px + padding: 20px + HAML + + HTML + end + + it 'renders sass filter with string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML) + :sass + .users_controller + .show_action + content: "#{'<&>'}" + HAML + + HTML + end + end +end diff --git a/test/hamlit/filters/scss_test.rb b/test/hamlit/filters/scss_test.rb new file mode 100644 index 00000000..b6253fae --- /dev/null +++ b/test/hamlit/filters/scss_test.rb @@ -0,0 +1,41 @@ +describe Hamlit::Filters do + include RenderAssertion + + describe '#compile' do + it 'renders scss filter' do + skip + assert_render(<<-HAML, <<-HTML) + :scss + .users_controller { + .show_action { + margin: 10px; + padding: 20px; + } + } + HAML + + HTML + end + + it 'parses string interpolation' do + skip + assert_render(<<-'HAML', <<-HTML) + :scss + .users_controller { + .show_action { + content: "#{'<&>'}"; + } + } + HAML + + HTML + end + end +end