Skip to content

Commit

Permalink
Tests to show the issue in #69
Browse files Browse the repository at this point in the history
  • Loading branch information
patbenatar committed Jan 16, 2021
1 parent 0361775 commit ec94e38
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions spec/lib/rbexy/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def component_class(name, template)
]
end

it "tokenizes tags within a {..} block" do
it "tokenizes tags within a { .. } block" do
subject = Rbexy::Lexer.new(Rbexy::Template.new("{3.times { <p>Hello</p> }}"), Rbexy::ComponentResolver.new)
expect(subject.tokenize).to eq [
[:OPEN_EXPRESSION],
Expand All @@ -438,7 +438,24 @@ def component_class(name, template)
]
end

it "tokenizes tags within a {|var|..} block" do
it "tokenizes tags within a {..} block (does not care about inner whitespace)" do
subject = Rbexy::Lexer.new(Rbexy::Template.new("{3.times {<p>Hello</p>}}"), Rbexy::ComponentResolver.new)
expect(subject.tokenize).to eq [
[:OPEN_EXPRESSION],
[:EXPRESSION_BODY, "3.times {"],
[:OPEN_TAG_DEF],
[:TAG_DETAILS, { name: "p", type: :html }],
[:CLOSE_TAG_DEF],
[:TEXT, "Hello"],
[:OPEN_TAG_END],
[:TAG_NAME, "p"],
[:CLOSE_TAG_END],
[:EXPRESSION_BODY, "}"],
[:CLOSE_EXPRESSION],
]
end

it "tokenizes tags within a { |var| .. } block" do
subject = Rbexy::Lexer.new(Rbexy::Template.new("{3.times { |n| <p>Hello</p> }}"), Rbexy::ComponentResolver.new)
expect(subject.tokenize).to eq [
[:OPEN_EXPRESSION],
Expand All @@ -455,6 +472,23 @@ def component_class(name, template)
]
end

it "tokenizes tags within a {|var|..} block (does not care about inner whitespace)" do
subject = Rbexy::Lexer.new(Rbexy::Template.new("{3.times {|n|<p>Hello</p>}}"), Rbexy::ComponentResolver.new)
expect(subject.tokenize).to eq [
[:OPEN_EXPRESSION],
[:EXPRESSION_BODY, "3.times {|n|"],
[:OPEN_TAG_DEF],
[:TAG_DETAILS, { name: "p", type: :html }],
[:CLOSE_TAG_DEF],
[:TEXT, "Hello"],
[:OPEN_TAG_END],
[:TAG_NAME, "p"],
[:CLOSE_TAG_END],
[:EXPRESSION_BODY, "}"],
[:CLOSE_EXPRESSION],
]
end

it "doesn't try to parse tags within %q(...) string notation" do
template_string = <<-RBX.strip_heredoc.strip
<div attr={%q(
Expand Down

0 comments on commit ec94e38

Please sign in to comment.