Skip to content

Commit

Permalink
test: add tests for the templ filetype
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
PriceHiller committed May 29, 2024
1 parent e907a7e commit bcf3146
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sample/index.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

templ hello(name string) {
<div class="">Hello, { name }</div>
}

templ foo(name string) {
<div>
@hello(name)


</div>
}
1 change: 1 addition & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function M.setup_treesitter()
"php",
"glimmer",
"rescript",
"templ",
"embedded_template",
},
})
Expand Down
36 changes: 36 additions & 0 deletions tests/specs/close_slash_tag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,42 @@ local data = {
before = [[<%= <div| %>]],
after = [[<%= <div/| %> ]],
},
{
name = "19 templ close tag after inputting /",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div><| ]],
after = [[<div></div>|]],
},
{
name = "20 templ close tag after inputting /",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div clas="laa"><| ]],
after = [[<div clas="laa"></div>|]],
},
{
name = "21 templ don't close tag when no opening tag is found",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/>]],
before = [[<div><|</div> ]],
after = [[<div></>|</div>]],
},
{
name = "22 templ not close inside quote",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div class="aa|"> </div> ]],
after = [[<div class="aa/|"> </div> ]],
},
}

local autotag = require("nvim-ts-autotag")
Expand Down
36 changes: 36 additions & 0 deletions tests/specs/closetag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,42 @@ local data = {
before = [[<%= <div| %>]],
after = [[<%= <div>| %> ]],
},
{
name = "21 templ close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div| ]],
after = [[<div>|</div>]],
},
{
name = "22 templ close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div clas="laa"| ]],
after = [[<div clas="laa">|</div>]],
},
{
name = "23 templ not close tag on close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div>aa</div| ]],
after = [[<div>aa</div>|]],
},
{
name = "24 templ not close on input tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<input| ]],
after = [[<input>| ]],
},
}

local autotag = require("nvim-ts-autotag")
Expand Down
49 changes: 49 additions & 0 deletions tests/specs/renametag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,55 @@ local data = {
},
after = [[<%= <div></lala|> %>]],
},
{
name = "templ rename open tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<di|v> dsadsa </div> ]],
after = [[<lala|> dsadsa </lala> ]],
},
{
name = "templ rename open tag with attr",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<di|v class="lla"> dsadsa </div> ]],
after = [[<lala| class="lla"> dsadsa </lala|> ]],
},
{
name = "templ rename close tag with attr",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<div class="lla"> dsadsa </di|v> ]],
after = [[<lala class="lla"> dsadsa </lal|a> ]],
},
{
name = "templ not rename close tag on char <",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[i<]],
before = [[<div class="lla"> dsadsa |/button> ]],
after = [[<div class="lla"> dsadsa <|/button> ]],
},
{

name = "templ not rename close tag with not valid",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 11,
key = [[ciwlala]],
before = {
[[<di|v class="lla" ]],
[[ dsadsa </div>]],
},
after = [[<lala class="lla" ]],
},
}

local autotag = require("nvim-ts-autotag")
Expand Down

0 comments on commit bcf3146

Please sign in to comment.