From bcf3146864262ef2d3c877beba3e222b5c73780d Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 29 May 2024 12:37:18 -0500 Subject: [PATCH] test: add tests for the `templ` filetype Closes #179 --- sample/index.templ | 13 ++++++++ tests/minimal_init.lua | 1 + tests/specs/close_slash_tag_spec.lua | 36 ++++++++++++++++++++ tests/specs/closetag_spec.lua | 36 ++++++++++++++++++++ tests/specs/renametag_spec.lua | 49 ++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 sample/index.templ diff --git a/sample/index.templ b/sample/index.templ new file mode 100644 index 0000000..3e82265 --- /dev/null +++ b/sample/index.templ @@ -0,0 +1,13 @@ +package main + +templ hello(name string) { +
Hello, { name }
+} + +templ foo(name string) { +
+ @hello(name) + + +
+} diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index 15f0aab..1c9701d 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -73,6 +73,7 @@ function M.setup_treesitter() "php", "glimmer", "rescript", + "templ", "embedded_template", }, }) diff --git a/tests/specs/close_slash_tag_spec.lua b/tests/specs/close_slash_tag_spec.lua index 17cd315..3a749cd 100644 --- a/tests/specs/close_slash_tag_spec.lua +++ b/tests/specs/close_slash_tag_spec.lua @@ -163,6 +163,42 @@ local data = { before = [[<%= ]], after = [[<%=
]], }, + { + name = "19 templ close tag after inputting /", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[/]], + before = [[
<| ]], + after = [[
|]], + }, + { + name = "20 templ close tag after inputting /", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[/]], + before = [[
<| ]], + after = [[
|]], + }, + { + name = "21 templ don't close tag when no opening tag is found", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[/>]], + before = [[
<|
]], + after = [[
|
]], + }, + { + name = "22 templ not close inside quote", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[/]], + before = [[
]], + after = [[
]], + }, } local autotag = require("nvim-ts-autotag") diff --git a/tests/specs/closetag_spec.lua b/tests/specs/closetag_spec.lua index 1b954b9..a48ee15 100644 --- a/tests/specs/closetag_spec.lua +++ b/tests/specs/closetag_spec.lua @@ -201,6 +201,42 @@ local data = { before = [[<%= ]], after = [[<%=
| %> ]], }, + { + name = "21 templ close tag", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[>]], + before = [[|
]], + }, + { + name = "22 templ close tag", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[>]], + before = [[
|
]], + }, + { + name = "23 templ not close tag on close tag", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[>]], + before = [[
aaaa
|]], + }, + { + name = "24 templ not close on input tag", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[>]], + before = [[| ]], + }, } local autotag = require("nvim-ts-autotag") diff --git a/tests/specs/renametag_spec.lua b/tests/specs/renametag_spec.lua index 924fc76..60f914b 100644 --- a/tests/specs/renametag_spec.lua +++ b/tests/specs/renametag_spec.lua @@ -302,6 +302,55 @@ local data = { }, after = [[<%=
%>]], }, + { + name = "templ rename open tag", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[ciwlala]], + before = [[ dsadsa
]], + after = [[ dsadsa ]], + }, + { + name = "templ rename open tag with attr", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[ciwlala]], + before = [[ dsadsa
]], + after = [[ dsadsa ]], + }, + { + name = "templ rename close tag with attr", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[ciwlala]], + before = [[
dsadsa ]], + after = [[ dsadsa ]], + }, + { + name = "templ not rename close tag on char <", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 10, + key = [[i<]], + before = [[
dsadsa |/button> ]], + after = [[
dsadsa <|/button> ]], + }, + { + + name = "templ not rename close tag with not valid", + filepath = "./sample/index.templ", + filetype = "templ", + linenr = 11, + key = [[ciwlala]], + before = { + [[]], + }, + after = [[