Skip to content

Commit

Permalink
Merge pull request #1 from kei-s/cosme_test
Browse files Browse the repository at this point in the history
Cosme test
  • Loading branch information
ydah authored Jul 26, 2023
2 parents d2a1614 + 7704e64 commit c8c7c60
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 118 deletions.
214 changes: 141 additions & 73 deletions test/embedded/minify/javascript_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,125 +4,193 @@

class JavascriptTest < TestSlim
def test_render_with_javascript
source = "
javascript:
$(function() {});
alert('hello')
p Hi
"
assert_html %{<script>$(function() {});\nalert('hello')</script><p>Hi</p>}, source
source = <<~SLIM
javascript:
$(function() {});
alert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>$(function() {});
alert('hello')</script><p>Hi</p>
HTML
end

def test_render_with_javascript_and_comment
source = "
javascript:
// some comment
$(function() {});// some comment
// "" or ''
// '' or ""
alert('// argument')
p Hi
"
assert_html %{<script>\n$(function() {});\nalert('// argument')</script><p>Hi</p>}, source
source = <<~SLIM
javascript:
// some comment
$(function() {});// some comment
// "" or ''
// '' or ""
alert('// argument')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>
$(function() {});
alert('// argument')</script><p>Hi</p>
HTML
end

def test_render_with_javascript_and_multiline_comment
source = "
javascript:
/*
multiline
comment
*/
$(function() {});
alert('hello')
p Hi
"
assert_html %{<script>\n$(function() {});\nalert('hello')</script><p>Hi</p>}, source
source = <<~SLIM
javascript:
/*
multiline
comment
*/
$(function() {});
alert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>
$(function() {});
alert('hello')</script><p>Hi</p>
HTML
end

def test_render_with_javascript_and_singleline_comment
source = '
javascript:
/* comment */
$(function() {});
/* ... * comment / */
/* ... * comment / */alert("/* argument */")/*... * comment /*/
/* comment */alert("/* argument */")/*comment*/
p Hi
'
assert_html %{<script>\n$(function() {});\nalert(\"/* argument */\")\nalert(\"/* argument */\")</script><p>Hi</p>}, source
source = <<~SLIM
javascript:
/* comment */
$(function() {});
/* ... * comment / */
/* ... * comment / */alert("/* argument */")/*... * comment /*/
/* comment */alert("/* argument */")/*comment*/
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>
$(function() {});
alert("/* argument */")
alert("/* argument */")</script><p>Hi</p>
HTML
end

def test_render_with_javascript_empty_attributes
source = "
javascript ():
alert('hello')
"
source = <<~SLIM
javascript ():
alert('hello')
SLIM
assert_html %{<script>alert('hello')</script>}, source
end

def test_render_with_javascript_attribute
source = %q{
javascript [class = "myClass"]:
alert('hello')
}
assert_html %{<script class=\"myClass\">alert('hello')</script>}, source
source = <<~SLIM
javascript [class = "myClass"]:
alert('hello')
SLIM
assert_html %{<script class="myClass">alert('hello')</script>}, source
end

def test_render_with_javascript_multiple_attributes
source = %q{
javascript { class = "myClass" id="myId" other-attribute = 'my_other_attribute' } :
alert('hello')
}
assert_html %{<script class=\"myClass\" id=\"myId\" other-attribute=\"my_other_attribute\">alert('hello')</script>},
source = <<~SLIM
javascript { class = "myClass" id="myId" other-attribute = 'my_other_attribute' } :
alert('hello')
SLIM
assert_html %{<script class="myClass" id="myId" other-attribute="my_other_attribute">alert('hello')</script>},
source
end

def test_render_with_javascript_with_tabs
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
assert_html "<script>$(function() {});\nalert('hello')</script><p>Hi</p>", source
source = <<~SLIM
javascript:
\t$(function() {});
\talert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>$(function() {});
alert('hello')</script><p>Hi</p>
HTML
end

def test_render_with_javascript_including_variable
source = %q{
- func = "alert('hello');"
javascript:
$(function() { #{func} });
}
source = <<~'SLIM'
- func = "alert('hello');"
javascript:
$(function() { #{func} });
SLIM
assert_html "<script>$(function() { alert(&#39;hello&#39;); });</script>", source
end

def test_render_with_javascript_with_explicit_html_comment
Slim::Engine.with_options(js_wrapper: :comment) do
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
assert_html "<script><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
source = <<~SLIM
javascript:
\t$(function() {});
\talert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script><!--
$(function() {});
alert('hello')
//--></script><p>Hi</p>
HTML
end
end

def test_render_with_javascript_with_explicit_cdata_comment
Slim::Engine.with_options(js_wrapper: :cdata) do
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
assert_html "<script>\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
source = <<~SLIM
javascript:
\t$(function() {});
\talert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>
//<![CDATA[
$(function() {});
alert('hello')
//]]>
</script><p>Hi</p>
HTML
end
end

def test_render_with_javascript_with_format_xhtml_comment
Slim::Engine.with_options(js_wrapper: :guess, format: :xhtml) do
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
assert_html "<script>\n//<![CDATA[\n$(function() {});\nalert('hello')\n//]]>\n</script><p>Hi</p>", source
source = <<~SLIM
javascript:
\t$(function() {});
\talert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script>
//<![CDATA[
$(function() {});
alert('hello')
//]]>
</script><p>Hi</p>
HTML
end
end

def test_render_with_javascript_with_format_html_comment
Slim::Engine.with_options(js_wrapper: :guess, format: :html) do
source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
assert_html "<script><!--\n$(function() {});\nalert('hello')\n//--></script><p>Hi</p>", source
source = <<~SLIM
javascript:
\t$(function() {});
\talert('hello')
p Hi
SLIM
assert_html <<~HTML.chomp, source
<script><!--
$(function() {});
alert('hello')
//--></script><p>Hi</p>
HTML
end
end
end
101 changes: 56 additions & 45 deletions test/embedded/minify/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,76 @@

class TagTest < TestSlim
def test_render_with_css
source = %q{
css:
h1 { color: blue }
}
assert_html "<style>h1 { color: blue }</style>", source
source = <<~SLIM
css:
h1 { color: blue }
SLIM
assert_html "<style>h1 { color: blue }</style>", source
end

def test_render_with_css_empty_attributes
source = %q{
css []:
h1 { color: blue }
}
assert_html "<style>h1 { color: blue }</style>", source
source = <<~SLIM
css []:
h1 { color: blue }
SLIM
assert_html "<style>h1 { color: blue }</style>", source
end

def test_render_with_css_attribute
source = %q{
css scoped = "true":
h1 { color: blue }
}
assert_html "<style scoped=\"true\">h1 { color: blue }</style>", source
source = <<~SLIM
css scoped = "true":
h1 { color: blue }
SLIM
assert_html %{<style scoped="true">h1 { color: blue }</style>}, source
end

def test_render_with_css_multiple_attributes
source = %q{
css class="myClass" scoped = "true" :
h1 { color: blue }
}
assert_html "<style class=\"myClass\" scoped=\"true\">h1 { color: blue }</style>", source
source = <<~SLIM
css class="myClass" scoped = "true" :
h1 { color: blue }
SLIM
assert_html %{<style class="myClass" scoped="true">h1 { color: blue }</style>}, source
end

def test_render_with_css_and_comment
source = %q{
css:
/* comment */
h1 {
/* comment * / */font-family: "/*foo*/", '/*bar*/';/** /comment */
color: blue;
/* comment */
}
}
assert_html "<style>\nh1 {\n font-family: \"/*foo*/\", '/*bar*/';\n color: blue;\n}</style>", source
source = <<~SLIM
css:
/* comment */
h1 {
/* comment * / */font-family: "/*foo*/", '/*bar*/';/** /comment */
color: blue;
/* comment */
}
SLIM
assert_html <<~HTML.chomp, source
<style>
h1 {
font-family: "/*foo*/", '/*bar*/';
color: blue;
}</style>
HTML
end

def test_render_with_css_and_multiple_comment
source = %q{
css:
/*
multiline
comment
*/
h1 {
color: blue;
/*
multiline
comment
*/
}
}
assert_html "<style>\nh1 {\n color: blue;\n}</style>", source
source = <<~SLIM
css:
/*
multiline
comment
*/
h1 {
color: blue;
/*
multiline
comment
*/
}
SLIM
assert_html <<~HTML.chomp, source
<style>
h1 {
color: blue;
}</style>
HTML
end
end

0 comments on commit c8c7c60

Please sign in to comment.