=\"some <%= value %> foo\">"))
- assert_equal s(:document,
- s(:tag, nil,
+ assert_equal s(
+ :document,
+ s(
+ :tag,
+ nil,
s(:tag_name, "div"),
- s(:tag_attributes,
- s(:attribute,
+ s(
+ :tag_attributes,
+ s(
+ :attribute,
s(:attribute_name, "data-", s(:erb, s(:indicator, "="), nil, s(:code, " foo "), nil)),
s(:equal),
- s(:attribute_value,
+ s(
+ :attribute_value,
s(:quote, "\""),
"some ",
s(:erb, s(:indicator, "="), nil, s(:code, " value "), nil),
" foo",
- s(:quote, "\""),),)),
- nil)), tree.ast
+ s(:quote, "\""),
+ ),
+ ),
+ ),
+ nil,
+ ),
+ ),
+ tree.ast
end
test "consume text nodes" do
tree = Parser.new(buffer("here is <%= some %> text"))
- assert_equal s(:document,
- s(:text,
+ assert_equal s(
+ :document,
+ s(
+ :text,
"here is ",
s(:erb, s(:indicator, "="), nil, s(:code, " some "), nil),
- " text")), tree.ast
+ " text",
+ ),
+ ),
+ tree.ast
end
test "javascript template parsing works" do
tree = Parser.new(buffer("here is <%= some %> text"), template_language: :javascript)
- assert_equal s(:document,
- s(:text,
+ assert_equal s(
+ :document,
+ s(
+ :text,
"here is ",
s(:erb, s(:indicator, "="), nil, s(:code, " some "), nil),
- " text")), tree.ast
+ " text",
+ ),
+ ),
+ tree.ast
end
test "javascript template does not consume html tags" do
tree = Parser.new(buffer("
/>"), template_language: :javascript)
- assert_equal s(:document,
- s(:text,
+ assert_equal s(
+ :document,
+ s(
+ :text,
"
")), tree.ast
+ " />",
+ ),
+ ),
+ tree.ast
end
test "lodash template parsing works" do
tree = Parser.new(buffer('
'), template_language: :lodash)
- assert_equal s(:document,
- s(:tag,
+ assert_equal s(
+ :document,
+ s(
+ :tag,
nil,
s(:tag_name, "div"),
- s(:tag_attributes,
- s(:attribute,
+ s(
+ :tag_attributes,
+ s(
+ :attribute,
s(:attribute_name, "class"),
s(:equal),
- s(:attribute_value,
+ s(
+ :attribute_value,
s(:quote, "\""),
s(:lodash, s(:indicator, "="), s(:code, " foo ")),
- s(:quote, "\"")))),
- nil)), tree.ast
+ s(:quote, "\""),
+ ),
+ ),
+ ),
+ nil,
+ ),
+ ),
+ tree.ast
end
test "nodes are all nested under document" do
@@ -256,25 +363,36 @@ class ParserTest < ActiveSupport::TestCase
HTML
- assert_equal s(:document,
+ assert_equal s(
+ :document,
s(:text, "some text\n"),
s(:comment, " a comment "),
- s(:text,
+ s(
+ :text,
"\nsome more text\n",
s(:erb, s(:indicator, "="), nil, s(:code, " an erb tag "), s(:trim)),
- "\n"),
- s(:tag,
+ "\n",
+ ),
+ s(
+ :tag,
nil,
s(:tag_name, "div"),
- s(:tag_attributes,
- s(:attribute,
+ s(
+ :tag_attributes,
+ s(
+ :attribute,
s(:attribute_name, "class"),
s(:equal),
- s(:attribute_value, s(:quote, "\""), "foo", s(:quote, "\"")))),
- nil),
+ s(:attribute_value, s(:quote, "\""), "foo", s(:quote, "\"")),
+ ),
+ ),
+ nil,
+ ),
s(:text, "\n content\n"),
s(:tag, s(:solidus), s(:tag_name, "div"), nil, nil),
- s(:text, "\n"),), tree.ast
+ s(:text, "\n"),
+ ),
+ tree.ast
end
end
end
diff --git a/test/better_html/test_helper/safe_erb/tag_interpolation_test.rb b/test/better_html/test_helper/safe_erb/tag_interpolation_test.rb
index 2036ac1..43edff3 100644
--- a/test/better_html/test_helper/safe_erb/tag_interpolation_test.rb
+++ b/test/better_html/test_helper/safe_erb/tag_interpolation_test.rb
@@ -63,7 +63,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "name", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -77,13 +77,13 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "bar", errors[0].location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors[0].message
+ errors[0].message,
)
assert_equal "baz", errors[1].location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors[1].message
+ errors[1].message,
)
end
@@ -96,7 +96,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -123,7 +123,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "bar", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -178,7 +178,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe.to_json.html_safe", errors[1].location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors[1].message
+ errors[1].message,
)
end
@@ -223,7 +223,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "raw unsafe.to_json", errors[1].location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors[1].message
+ errors[1].message,
)
end
@@ -236,7 +236,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors[0].location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors[0].message
+ errors[0].message,
)
end
@@ -249,7 +249,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -262,7 +262,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -283,7 +283,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -296,7 +296,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
@@ -309,7 +309,7 @@ class TagInterpolationTest < ActiveSupport::TestCase
assert_equal "unsafe", errors.first.location.source
assert_equal(
"erb interpolation in javascript attribute must be wrapped in safe helper such as '(...).to_json'",
- errors.first.message
+ errors.first.message,
)
end
diff --git a/test/better_html/tokenizer/html_erb_test.rb b/test/better_html/tokenizer/html_erb_test.rb
index 8cf22d5..f3fb6a2 100644
--- a/test/better_html/tokenizer/html_erb_test.rb
+++ b/test/better_html/tokenizer/html_erb_test.rb
@@ -13,7 +13,8 @@ class HtmlErbTest < ActiveSupport::TestCase
assert_attributes ({
type: :text,
loc: { begin_pos: 0, end_pos: 14, source: "just some text" },
- }), scanner.tokens[0]
+ }),
+ scanner.tokens[0]
end
test "statement" do
@@ -74,7 +75,7 @@ class HtmlErbTest < ActiveSupport::TestCase
scanner.tokens[5]
assert_attributes(
{ type: :attribute_quoted_value, loc: { begin_pos: 12, end_pos: 24, source: "your store’s" } },
- scanner.tokens[6]
+ scanner.tokens[6],
)
assert_attributes ({ type: :attribute_quoted_value_end, loc: { begin_pos: 24, end_pos: 25, source: "'" } }),
scanner.tokens[7]
diff --git a/test/better_html/tokenizer/html_lodash_test.rb b/test/better_html/tokenizer/html_lodash_test.rb
index 3e07e74..ce25256 100644
--- a/test/better_html/tokenizer/html_lodash_test.rb
+++ b/test/better_html/tokenizer/html_lodash_test.rb
@@ -76,10 +76,21 @@ class HtmlLodashTest < ActiveSupport::TestCase
test "parses out html correctly" do
scanner = HtmlLodash.new(buffer('
'))
assert_equal 12, scanner.tokens.size
- assert_equal [:tag_start, :tag_name, :whitespace, :attribute_name,
- :equal, :attribute_quoted_value_start,
- :lodash_begin, :indicator, :code, :lodash_end,
- :attribute_quoted_value_end, :tag_end,], scanner.tokens.map(&:type)
+ assert_equal [
+ :tag_start,
+ :tag_name,
+ :whitespace,
+ :attribute_name,
+ :equal,
+ :attribute_quoted_value_start,
+ :lodash_begin,
+ :indicator,
+ :code,
+ :lodash_end,
+ :attribute_quoted_value_end,
+ :tag_end,
+ ],
+ scanner.tokens.map(&:type)
assert_equal ["<", "div", " ", "class", "=", "\"", "[%", "=", " foo ", "%]", "\"", ">"],
scanner.tokens.map(&:loc).map(&:source)
end
diff --git a/test/dummy/config.ru b/test/dummy/config.ru
index 097cb7b..89bfd0b 100644
--- a/test/dummy/config.ru
+++ b/test/dummy/config.ru
@@ -2,5 +2,5 @@
# This file is used by Rack-based servers to start the application.
-require ::File.expand_path("../config/environment", __FILE__)
+require File.expand_path("../config/environment", __FILE__)
run Rails.application
diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb
index bdd9a47..f7012f3 100644
--- a/test/dummy/config/environments/production.rb
+++ b/test/dummy/config/environments/production.rb
@@ -74,7 +74,7 @@
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
- config.log_formatter = ::Logger::Formatter.new
+ config.log_formatter = Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb
index d0f0d3b..4b63f28 100644
--- a/test/dummy/config/initializers/backtrace_silencers.rb
+++ b/test/dummy/config/initializers/backtrace_silencers.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb
index aa7435f..dc84742 100644
--- a/test/dummy/config/initializers/inflections.rb
+++ b/test/dummy/config/initializers/inflections.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb
index 6e1d16f..be6fedc 100644
--- a/test/dummy/config/initializers/mime_types.rb
+++ b/test/dummy/config/initializers/mime_types.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
diff --git a/test/html_tokenizer/parser_test.rb b/test/html_tokenizer/parser_test.rb
index 7c1aeb0..bce1f88 100644
--- a/test/html_tokenizer/parser_test.rb
+++ b/test/html_tokenizer/parser_test.rb
@@ -533,17 +533,20 @@ def test_attribute_with_mutlibyte_characters
assert_equal(data.join, @parser.document)
assert_equal(data.join.size, @parser.document_length)
assert_equal(data.join.size, @parser.column_number)
- assert_equal([
- [:tag_start, 0, 1, "<"],
- [:tag_name, 1, 4, "div"],
- [:whitespace, 4, 5, " "],
- [:attribute_name, 5, 10, "title"],
- [:equal, 10, 11, "="],
- [:attribute_quoted_value_start, 11, 12, "'"],
- [:attribute_quoted_value, 12, 24, "your store’s"],
- [:attribute_quoted_value_end, 24, 25, "'"],
- [:tag_end, 25, 26, ">"],
- ], tokens)
+ assert_equal(
+ [
+ [:tag_start, 0, 1, "<"],
+ [:tag_name, 1, 4, "div"],
+ [:whitespace, 4, 5, " "],
+ [:attribute_name, 5, 10, "title"],
+ [:equal, 10, 11, "="],
+ [:attribute_quoted_value_start, 11, 12, "'"],
+ [:attribute_quoted_value, 12, 24, "your store’s"],
+ [:attribute_quoted_value_end, 24, 25, "'"],
+ [:tag_end, 25, 26, ">"],
+ ],
+ tokens,
+ )
end
def test_valid_syntaxes
diff --git a/test/html_tokenizer/tokenizer_test.rb b/test/html_tokenizer/tokenizer_test.rb
index f50c25b..1bfded8 100644
--- a/test/html_tokenizer/tokenizer_test.rb
+++ b/test/html_tokenizer/tokenizer_test.rb
@@ -5,12 +5,18 @@
module HtmlTokenizer
class TokenizerTest < Minitest::Test
def test_closing_tag_without_start_is_text
- assert_equal([
- [:text, ">"],
- ], tokenize(">"))
- assert_equal([
- [:tag_start, "<"], [:tag_name, "foo"], [:tag_end, ">"], [:text, ">"],
- ], tokenize("
>"))
+ assert_equal(
+ [
+ [:text, ">"],
+ ],
+ tokenize(">"),
+ )
+ assert_equal(
+ [
+ [:tag_start, "<"], [:tag_name, "foo"], [:tag_end, ">"], [:text, ">"],
+ ],
+ tokenize(">"),
+ )
end
def test_tokenize_text
@@ -19,45 +25,64 @@ def test_tokenize_text
end
def test_namespace_tag_name_multipart
- assert_equal([
- [:tag_start, "<"], [:tag_name, "foo:"], [:tag_name, "bar"],
- ], tokenize(""],
- ], tokenize(""))
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "!DOCTYPE"],
+ [:whitespace, " "],
+ [:attribute_name, "html"],
+ [:tag_end, ">"],
+ ],
+ tokenize(""),
+ )
end
def test_tokenize_multiple_elements
- assert_equal([
- [:tag_start, "<"], [:tag_name, "div"], [:tag_end, ">"],
- [:text, " bla "],
- [:tag_start, "<"], [:tag_name, "strong"], [:tag_end, ">"],
- ], tokenize(" bla
"))
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:tag_end, ">"],
+ [:text, " bla "],
+ [:tag_start, "<"],
+ [:tag_name, "strong"],
+ [:tag_end, ">"],
+ ],
+ tokenize(" bla
"),
+ )
end
def test_tokenize_complex_doctype
text = ''
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "!DOCTYPE"],
- [:whitespace, " "],
- [:attribute_name, "html"],
- [:whitespace, " "],
- [:attribute_name, "PUBLIC"],
- [:whitespace, " "],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "-//W3C//DTD XHTML 1.0 Transitional//EN"],
- [:attribute_quoted_value_end, "\""],
- [:whitespace, " "],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"],
- [:attribute_quoted_value_end, "\""],
- [:tag_end, ">"],
- ], tokenize(text))
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "!DOCTYPE"],
+ [:whitespace, " "],
+ [:attribute_name, "html"],
+ [:whitespace, " "],
+ [:attribute_name, "PUBLIC"],
+ [:whitespace, " "],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "-//W3C//DTD XHTML 1.0 Transitional//EN"],
+ [:attribute_quoted_value_end, "\""],
+ [:whitespace, " "],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"],
+ [:attribute_quoted_value_end, "\""],
+ [:tag_end, ">"],
+ ],
+ tokenize(text),
+ )
end
def test_tokenize_html_comment
@@ -70,11 +95,16 @@ def test_tokenize_comment_with_newlines
EOF
- assert_equal([
- [:text, " "], [:comment_start, ""], [:text, "\n"],
- ], result)
+ assert_equal(
+ [
+ [:text, " "],
+ [:comment_start, ""],
+ [:text, "\n"],
+ ],
+ result,
+ )
end
def test_tokenize_cdata_section
@@ -84,26 +114,57 @@ def test_tokenize_cdata_section
def test_tokenizer_cdata_regression
result = tokenize("")
- assert_equal([[:cdata_start, ""],], result)
+ assert_equal(
+ [
+ [:cdata_start, ""],
+ ],
+ result,
+ )
end
def test_tokenizer_cdata_context
result = tokenize("<")
- assert_equal([[:cdata_start, ""], [:tag_start, "<"],], result)
+ assert_equal(
+ [
+ [:cdata_start, ""],
+ [:tag_start, "<"],
+ ],
+ result,
+ )
end
def test_tokenizer_comment_regression
result = tokenize("")
- assert_equal([[:comment_start, ""],], result)
+ assert_equal(
+ [
+ [:comment_start, ""],
+ ],
+ result,
+ )
end
def test_tokenizer_parse_tag_after_comment_regression
result = tokenize(" ")
- assert_equal([[:comment_start, ""],
- [:text, " "], [:tag_start, "<"], [:tag_name, "li"], [:tag_end, ">"],], result)
+ assert_equal(
+ [
+ [:comment_start, ""],
+ [:text, " "],
+ [:tag_start, "<"],
+ [:tag_name, "li"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_basic_tag
@@ -128,8 +189,10 @@ def test_tokenize_tag_multipart_name
def test_tokenize_tag_name_ending_with_slash
result = tokenize("")
- assert_equal([[:tag_start, "<"], [:tag_name, "div"], [:solidus, "/"], [:attribute_name, "1"], [:tag_end, ">"]],
- result)
+ assert_equal(
+ [[:tag_start, "<"], [:tag_name, "div"], [:solidus, "/"], [:attribute_name, "1"], [:tag_end, ">"]],
+ result,
+ )
end
def test_tokenize_empty_tag
@@ -149,262 +212,353 @@ def test_tokenize_end_tag
def test_tokenize_tag_attribute_with_double_quote
result = tokenize('
')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value_end, "\""],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value_end, "\""],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_unquoted_attributes_separated_with_solidus
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_unquoted_value, "1/bar=2"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_unquoted_value, "1/bar=2"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_quoted_attributes_separated_with_solidus
result = tokenize('
')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "1"],
- [:attribute_quoted_value_end, "\""],
- [:solidus, "/"],
- [:attribute_name, "bar"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "2"],
- [:attribute_quoted_value_end, "\""],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "1"],
+ [:attribute_quoted_value_end, "\""],
+ [:solidus, "/"],
+ [:attribute_name, "bar"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "2"],
+ [:attribute_quoted_value_end, "\""],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_tag_attribute_without_space
result = tokenize('
')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value_end, "\""],
- [:attribute_name, "baz"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value_end, "\""],
+ [:attribute_name, "baz"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_multipart_unquoted_attribute
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_unquoted_value, "bar"],
- [:attribute_unquoted_value, "baz"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_unquoted_value, "bar"],
+ [:attribute_unquoted_value, "baz"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_quoted_attribute_separately
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "'"],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value_end, "'"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "'"],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value_end, "'"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_quoted_attribute_in_multiple_parts
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "'"],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value, "baz"],
- [:attribute_quoted_value_end, "'"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "'"],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value, "baz"],
+ [:attribute_quoted_value_end, "'"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_tag_attribute_with_single_quote
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "'"],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value_end, "'"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "'"],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value_end, "'"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_tag_attribute_with_no_quotes
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "div"], [:whitespace, " "],
- [:attribute_name, "foo"], [:equal, "="], [:attribute_unquoted_value, "bla"], [:whitespace, " "],
- [:attribute_name, "bar"], [:equal, "="], [:attribute_unquoted_value, "blo"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_unquoted_value, "bla"],
+ [:whitespace, " "],
+ [:attribute_name, "bar"],
+ [:equal, "="],
+ [:attribute_unquoted_value, "blo"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_double_equals
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "div"], [:whitespace, " "],
- [:attribute_name, "foo"], [:equal, "="], [:attribute_unquoted_value, "blabar=blo"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_unquoted_value, "blabar=blo"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_closing_tag
result = tokenize('
')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "foo"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "bar"],
- [:attribute_quoted_value_end, "\""],
- [:whitespace, " "],
- [:solidus, "/"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "foo"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "bar"],
+ [:attribute_quoted_value_end, "\""],
+ [:whitespace, " "],
+ [:solidus, "/"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_script_tag
result = tokenize("")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "script"], [:tag_end, ">"],
- [:text, "foo "], [:text, "
bar"],
- [:tag_start, "<"], [:solidus, "/"], [:tag_name, "script"], [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "script"],
+ [:tag_end, ">"],
+ [:text, "foo "],
+ [:text, " bar"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "script"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_textarea_tag
result = tokenize("")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "textarea"], [:tag_end, ">"],
- [:text, "hello"],
- [:tag_start, "<"], [:solidus, "/"], [:tag_name, "textarea"], [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "textarea"],
+ [:tag_end, ">"],
+ [:text, "hello"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "textarea"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_style_tag
result = tokenize("")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "style"], [:tag_end, ">"],
- [:text, "
"],
- [:tag_start, "<"], [:solidus, "/"], [:tag_name, "style"], [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "style"],
+ [:tag_end, ">"],
+ [:text, "
"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "style"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_script_containing_html
result = tokenize('')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "script"],
- [:whitespace, " "],
- [:attribute_name, "type"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "text/html"],
- [:attribute_quoted_value_end, "\""],
- [:tag_end, ">"],
- [:text, "foo "],
- [:text, "
bar"],
- [:tag_start, "<"],
- [:solidus, "/"],
- [:tag_name, "script"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "script"],
+ [:whitespace, " "],
+ [:attribute_name, "type"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "text/html"],
+ [:attribute_quoted_value_end, "\""],
+ [:tag_end, ">"],
+ [:text, "foo "],
+ [:text, " bar"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "script"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_end_of_tag_on_newline
- data = ["\
+ data = [
+ "\
",]
+ ",
+ "",
+ ">",
+ ]
result = tokenize(*data)
- assert_equal([
- [:text, " "],
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "define"],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "{credential_96_credential1: new Shopify.ProviderCredentials()}"],
- [:attribute_quoted_value_end, "\""],
- [:whitespace, "\n "],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:text, " "],
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "define"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "{credential_96_credential1: new Shopify.ProviderCredentials()}"],
+ [:attribute_quoted_value_end, "\""],
+ [:whitespace, "\n "],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_multi_part_attribute_name
result = tokenize("
")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "div"], [:whitespace, " "],
- [:attribute_name, "data-"], [:attribute_name, "shipping"], [:attribute_name, "-type"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "data-"],
+ [:attribute_name, "shipping"],
+ [:attribute_name, "-type"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_tokenize_attribute_name_with_space_before_equal
result = tokenize('
GST/HST')
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "a"],
- [:whitespace, " "],
- [:attribute_name, "href"],
- [:whitespace, " "],
- [:equal, "="],
- [:attribute_quoted_value_start, "\""],
- [:attribute_quoted_value, "http://www.cra-arc.gc.ca/tx/bsnss/tpcs/gst-tps/menu-eng.html"],
- [:attribute_quoted_value_end, "\""],
- [:tag_end, ">"],
- [:text, "GST/HST"],
- [:tag_start, "<"],
- [:solidus, "/"],
- [:tag_name, "a"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "a"],
+ [:whitespace, " "],
+ [:attribute_name, "href"],
+ [:whitespace, " "],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "\""],
+ [:attribute_quoted_value, "http://www.cra-arc.gc.ca/tx/bsnss/tpcs/gst-tps/menu-eng.html"],
+ [:attribute_quoted_value_end, "\""],
+ [:tag_end, ">"],
+ [:text, "GST/HST"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "a"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_raise_in_block
@@ -421,32 +575,43 @@ def test_raise_in_block
def test_tokenize_end_of_script_regression
result = tokenize("")
- assert_equal([
- [:tag_start, "<"], [:tag_name, "script"], [:tag_end, ">"],
- [:text, "<"],
- [:tag_start, "<"], [:solidus, "/"], [:tag_name, "script"], [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "script"],
+ [:tag_end, ">"],
+ [:text, "<"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "script"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
def test_html_with_mutlibyte_characters
data = "
foo
"
result = tokenize(data)
- assert_equal([
- [:tag_start, "<"],
- [:tag_name, "div"],
- [:whitespace, " "],
- [:attribute_name, "title"],
- [:equal, "="],
- [:attribute_quoted_value_start, "'"],
- [:attribute_quoted_value, "your store’s"],
- [:attribute_quoted_value_end, "'"],
- [:tag_end, ">"],
- [:text, "foo"],
- [:tag_start, "<"],
- [:solidus, "/"],
- [:tag_name, "div"],
- [:tag_end, ">"],
- ], result)
+ assert_equal(
+ [
+ [:tag_start, "<"],
+ [:tag_name, "div"],
+ [:whitespace, " "],
+ [:attribute_name, "title"],
+ [:equal, "="],
+ [:attribute_quoted_value_start, "'"],
+ [:attribute_quoted_value, "your store’s"],
+ [:attribute_quoted_value_end, "'"],
+ [:tag_end, ">"],
+ [:text, "foo"],
+ [:tag_start, "<"],
+ [:solidus, "/"],
+ [:tag_name, "div"],
+ [:tag_end, ">"],
+ ],
+ result,
+ )
end
private