# frozen_string_literal: true require_relative "../test_helper" module Lexer class ERBTest < Minitest::Spec include SnapshotUtils test "erb <% %>" do assert_lexed_snapshot(%(<% 'hello world' %>)) end test "erb <%= %>" do assert_lexed_snapshot(%(<%= "hello world" %>)) end test "erb <%- %>" do assert_lexed_snapshot(%(<%- "Test" %>)) end test "erb <%- -%>" do assert_lexed_snapshot(%(<%- "Test" -%>)) end test "erb <%# %>" do assert_lexed_snapshot(%(<%# "Test" %>)) end test "erb <%% %%>" do assert_lexed_snapshot(%(<%% "Test" %%>)) end test "erb <%%= %%>" do assert_lexed_snapshot(%(<%%= "Test" %%>)) end test "erb <% =%>" do assert_lexed_snapshot(%(<% "Test" =%>)) end test "erb <%= =%>" do assert_lexed_snapshot(%(<%= "Test" =%>)) end test "erb output inside HTML attribute value" do assert_lexed_snapshot(%(
)) end test "erb output inside HTML attribute value with value before" do assert_lexed_snapshot(%(
">
)) end test "erb output inside HTML attribute value with value before and after" do assert_lexed_snapshot(%(
cursor-pointer">
)) end test "erb output inside HTML attribute value with value and after" do assert_lexed_snapshot(%(
bg-black">
)) end test "multi-line erb content" do assert_lexed_snapshot(<<~HTML) <%= hello %> HTML end test "multi-line erb content with complex ruby" do assert_lexed_snapshot(<<~HTML) <%= if condition "value1" else "value2" end %> HTML end test "multi-line erb silent tag" do assert_lexed_snapshot(<<~HTML) <% x = 1 y = 2 %> HTML end test "erb tag followed by literal closing delimiter" do assert_lexed_snapshot(%(<% content %> %>)) end test "erb <%%>" do assert_lexed_snapshot(%(<%%>)) end test "erb tag closed with > instead of %>" do assert_lexed_snapshot(%(

<%= title >

)) end test "erb tag closed with % instead of %>" do assert_lexed_snapshot(%(

<%= title %

)) end test "erb tag closed with -% instead of -%>" do assert_lexed_snapshot(%(

<%= title -%

)) end test "erb tag closed with =% instead of =%>" do assert_lexed_snapshot(%(

<%= title =%

)) end test "erb escaped tag closed with %% instead of %%>" do assert_lexed_snapshot(%(

<%% title %%

)) end test "erb tag closed with a space between % and >" do assert_lexed_snapshot(%(

<%= title % >

)) end test "erb tag without any closing delimiter before a closing html tag" do assert_lexed_snapshot(%(

<%= title

)) end test "erb tag keeps greater-than comparison in the ruby" do assert_lexed_snapshot(%(

<%= count > 10 >

)) end test "erb tag with no recoverable closing delimiter" do assert_lexed_snapshot(%(<%= items.select { |item| item.size > 3 )) end test "erb tag with a configured opener" do assert_lexed_snapshot(%(<%graphql query { users { id } } %>), erb_openers: ["graphql"]) end test "erb tag with a configured opener that is not configured" do assert_lexed_snapshot(%(<%graphql query { users { id } } %>)) end test "erb tag sharing a prefix with a configured opener" do assert_lexed_snapshot(%(<%graphql_helper %>), erb_openers: ["graphql"]) end test "erb tag with a configured symbol opener" do assert_lexed_snapshot(%(<%? maybe %>), erb_openers: ["?"]) end test "erb <%== %>" do assert_lexed_snapshot(%(<%== "hello world" %>)) end test "erb delimiter inside a single quoted Ruby string" do assert_lexed_snapshot(%(<% x = '<%' %><%= x %>)) end test "erb delimiter inside a double quoted Ruby string" do assert_lexed_snapshot(%(<% x = "<%" %><%= x %>)) end test "erb delimiter inside a Ruby string in an output tag" do assert_lexed_snapshot(%(<%= '<%' %>)) end test "erb tag missing its closing delimiter before another erb tag" do assert_lexed_snapshot(%(<% users.each do |user| %\n

x

\n<% end %>)) end end end