// https://github.com/phoenixframework/tree-sitter-heex/tree/6603380caf806b3e6c7f0bf61627bb47023d79f1/test/corpus #![cfg(feature = "phoenix_heex")] use super::*; // ============================================================================ // text.txt // ============================================================================ #[test] fn plain_text() { html_opts!( [extension.phoenix_heex], "Hello World!\n", "

Hello World!

\n", ); } // ============================================================================ // comments.txt // ============================================================================ #[test] fn comments() { html_opts!( [extension.phoenix_heex], concat!( "I am some text!\n", "<%# Look a comment! %>\n", "I am more some text!\n", ), concat!( "

I am some text!\n", "<%# Look a comment! %>\n", "I am more some text!

\n", ), ); } #[test] fn empty_comments() { html_opts!( [extension.phoenix_heex], concat!("I am some text!\n", "<%# %>\n", "I am more some text!\n",), concat!( "

I am some text!\n", "<%# %>\n", "I am more some text!

\n", ), ); } #[test] fn multi_line_comments() { html_opts!( [extension.phoenix_heex], concat!( "<%# I\n", " AM\n", " A\n", " COMMENT\n", "%>\n", "and some text!\n", ), concat!( "<%# I\n", " AM\n", " A\n", " COMMENT\n", "%>\n", "

and some text!

\n", ), ); } #[test] fn elixir_comments() { html_opts!( [extension.phoenix_heex], concat!("<%= foo\n", " # |> bar()\n", " |> baz() %>\n",), concat!("<%= foo\n", " # |> bar()\n", " |> baz() %>\n",), ); } #[test] fn html_comments() { html_opts_i( concat!( "

I am some text!

\n", "\n", "

I am more some text!

\n", ), concat!( "

I am some text!

\n", "\n", "

I am more some text!

\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn empty_html_comments() { html_opts_i( concat!( "

I am some text!

\n", "\n", "

I am more some text!

\n", ), concat!( "

I am some text!

\n", "\n", "

I am more some text!

\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn new_style_multi_line_comments() { html_opts!( [extension.phoenix_heex], concat!( "<%!--\n", " Where'd the directive go?\n", " <%= @x %>\n", "--%>\n", ), concat!( "<%!--\n", " Where'd the directive go?\n", " <%= @x %>\n", "--%>\n", ), ); } #[test] fn empty_new_style_multi_line_comments() { html_opts!([extension.phoenix_heex], "<%!-- --%>\n", "<%!-- --%>\n",); } // ============================================================================ // expressions.txt // ============================================================================ #[test] fn simple_expression() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn single_empty_tuple() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn nested_empty_tuples() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn interpolation() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn many_openings_and_closings() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn interpolation_inside_body() { html_opts_i( concat!( "
\n", " { @message }\n", " {@message}\n", " {\"#{1}\"}\n", "
\n", ), concat!( "
\n", " { @message }\n", " {@message}\n", " {\"#{1}\"}\n", "
\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } // ============================================================================ // directives.txt // ============================================================================ #[test] fn if_expression_spread_between_multiple_directives() { html_opts!( [extension.phoenix_heex], concat!("<%= if true do %>\n", " <%= @x %>\n", "<% end %>\n",), concat!("<%= if true do %>\n", " <%= @x %>\n", "<% end %>\n",), ); } #[test] fn case_expression_spread_between_multiple_directives() { html_opts!( [extension.phoenix_heex], concat!( "<%= case @x do %>\n", " <%= ^x -> %>X, <%= x %>\n", " <%= _ -> %>Not X\n", "<% end %>\n", ), concat!( "<%= case @x do %>\n", " <%= ^x -> %>X, <%= x %>\n", " <%= _ -> %>Not X\n", "<% end %>\n", ), ); } // ============================================================================ // components.txt // ============================================================================ #[test] fn component() { html_opts!( [extension.phoenix_heex], concat!("\n", "\n",), concat!("\n", "\n",), ); } #[test] fn self_closing_component() { html_opts!( [extension.phoenix_heex], "\n", "\n", ); } #[test] fn nested_components() { html_opts!( [extension.phoenix_heex], concat!( "\n", " \n", " \n", " \n", "\n", ), concat!( "\n", " \n", " \n", " \n", "\n", ), ); } #[test] fn function_with_module_remote_component() { html_opts!( [extension.phoenix_heex], "\n", "\n", ); } #[test] fn function_without_remote_component() { html_opts!( [extension.phoenix_heex], "<.btn text=\"Save\" />\n", "<.btn text=\"Save\" />\n", ); } #[test] fn simple_example() { html_opts_i( concat!( "
\n", " \n", " <.some_local_func_component attr1=\"some string\" />\n", "
\n", ), concat!( "
\n", " \n", " <.some_local_func_component attr1=\"some string\" />\n", "
\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } // ============================================================================ // slots.txt // ============================================================================ #[test] fn named_slots() { html_opts!( [extension.phoenix_heex], concat!( "<.modal>\n", " <:header>\n", " This is the top of the modal.\n", " \n", " This is the content of the modal.\n", "\n", ), concat!( "<.modal>\n", " <:header>\n", " This is the top of the modal.\n", " \n", " This is the content of the modal.\n", "\n", ), ); } #[test] fn named_slots_with_attributes() { html_opts!( [extension.phoenix_heex], concat!( "<.modal>\n", " <:header key={@value}>\n", " \n", "\n", ), concat!( "<.modal>\n", " <:header key={@value}>\n", " \n", "\n", ), ); } #[test] fn self_closing_slot_does_not_error() { html_opts!( [extension.phoenix_heex], concat!("<.modal>\n", " <:header />\n", "\n",), concat!("<.modal>\n", " <:header />\n", "\n",), ); } // ============================================================================ // special_attributes.txt // ============================================================================ #[test] fn component_special_attribute_let() { html_opts!( [extension.phoenix_heex], concat!( "<.form :let={f}>\n", " <%= text_input f, :text %>\n", " <%= submit \"Submit\" %>\n", "\n", ), concat!( "<.form :let={f}>\n", " <%= text_input f, :text %>\n", " <%= submit \"Submit\" %>\n", "\n", ), ); } #[test] fn slot_special_attribute_let() { html_opts!( [extension.phoenix_heex], concat!( "<.func>\n", " <:slot :let={foo}>\n", " <%= foo %>\n", " \n", "\n", ), concat!( "<.func>\n", " <:slot :let={foo}>\n", " <%= foo %>\n", " \n", "\n", ), ); } #[test] fn tag_special_attribute_for() { html_opts_i( concat!( "
\n", " <%= item %>\n", "
\n", ), concat!( "
\n", " <%= item %>\n", "
\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn self_closing_tag_special_attribute_for() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn self_closing_tag_special_attribute_for_no_space() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn component_special_attribute_for() { html_opts!( [extension.phoenix_heex], concat!( "<.component :for={item <- @items}>\n", " <%= item %>\n", "\n", ), concat!( "<.component :for={item <- @items}>\n", " <%= item %>\n", "\n", ), ); } #[test] fn self_closing_component_special_attribute_for() { html_opts!( [extension.phoenix_heex], "<.component :for={item <- @items}/>\n", "<.component :for={item <- @items}/>\n", ); } #[test] fn slot_special_attribute_for() { html_opts!( [extension.phoenix_heex], concat!( "<.component>\n", " <:slot :for={item <- @items}>\n", " <%= item %>\n", " \n", "\n", ), concat!( "<.component>\n", " <:slot :for={item <- @items}>\n", " <%= item %>\n", " \n", "\n", ), ); } #[test] fn self_closing_slot_special_attribute_for() { html_opts!( [extension.phoenix_heex], concat!( "<.component>\n", " <:slot :for={item <- @items} />\n", "\n", ), concat!( "<.component>\n", " <:slot :for={item <- @items} />\n", "\n", ), ); } #[test] fn tag_special_attribute_stream() { html_opts_i( concat!( "
\n", " <%= item %>\n", "
\n", ), concat!( "
\n", " <%= item %>\n", "
\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn tag_special_attribute_if() { html_opts_i( concat!("
\n", " <%= @item %>\n", "
\n",), concat!("
\n", " <%= @item %>\n", "
\n",), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn self_closing_tag_special_attribute_if() { html_opts_i( "
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn component_special_attribute_if() { html_opts!( [extension.phoenix_heex], concat!( "<.component :if={@expression}>\n", " <%= @expression %>\n", "\n", ), concat!( "<.component :if={@expression}>\n", " <%= @expression %>\n", "\n", ), ); } #[test] fn self_closing_component_special_attribute_if() { html_opts!( [extension.phoenix_heex], "<.component :if={@expression} />\n", "<.component :if={@expression} />\n", ); } #[test] fn slot_special_attribute_if() { html_opts!( [extension.phoenix_heex], concat!( "<.component>\n", " <:slot :if={@expression}>\n", " <%= @expression %>\n", " \n", "\n", ), concat!( "<.component>\n", " <:slot :if={@expression}>\n", " <%= @expression %>\n", " \n", "\n", ), ); } #[test] fn self_closing_slot_special_attribute_if() { html_opts!( [extension.phoenix_heex], concat!( "<.component>\n", " <:slot :if={@expression} />\n", "\n", ), concat!( "<.component>\n", " <:slot :if={@expression} />\n", "\n", ), ); } // ============================================================================ // tags.txt // ============================================================================ #[test] fn html_tag() { html_opts_i( concat!("
\n", "
\n",), concat!("
\n", "
\n",), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn html_self_closing_tag() { html_opts_i("
\n", "
\n", true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }); } #[test] fn html_nested_tags() { html_opts_i( concat!( "
\n", "
\n", "
\n", "
\n", "
\n", ), concat!( "
\n", "
\n", "
\n", "
\n", "
\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn doctype() { html_opts_i( concat!( "\n", "\n", "\n", " \n", " <%= @inner_content %>\n", " \n", "\n", ), concat!( "\n", "\n", " \n", " <%= @inner_content %>\n", " \n", "\n", ), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } #[test] fn tag_name_with_hyphen() { html_opts_i( concat!("\n", "\n",), concat!("\n", "\n",), true, |opts| { opts.extension.phoenix_heex = true; opts.render.r#unsafe = true; }, ); } // ============================================================================ // attributes.txt // ============================================================================ #[test] fn unquoted_attribute() { html_opts!( [extension.phoenix_heex], "\n", "\n", ); } #[test] fn boolean_attribute() { html_opts!( [extension.phoenix_heex], "