Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Aug 1, 2024
1 parent 8009017 commit 5bb7b8b
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 127 deletions.
9 changes: 3 additions & 6 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"diagnostics": {
"runtime": {
"version": "LuaJIT"
}
},
"runtime.version": "LuaJIT",
"workspace.library": [
"/usr/local/share/nvim/runtime/lua",
"~/.local/share/nvim/lazy/nvim-cmp",
"${3rd}/luv/library",
"${3rd}/luassert/library"
"${3rd}/luassert/library",
"${3rd}/busted/library"
]
}
17 changes: 9 additions & 8 deletions tests/queries/astro_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/astro/index.astro")

describe("queries astro:", function()
runner:classes(4)
runner:ranges({
local spec = {
name = "astro",
provider = "treesitter",
file = "tests/queries/astro/index.astro",
ranges = {
{ 4, 17, 4, 42 },
{ 6, 12, 6, 26 },
{ 7, 14, 7, 41 },
{ 9, 33, 9, 43 },
})
end)
},
}

require("tests.queries.runner").test(spec)
41 changes: 0 additions & 41 deletions tests/queries/common.lua

This file was deleted.

17 changes: 9 additions & 8 deletions tests/queries/css_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/css/style.css")

describe("queries css:", function()
runner:classes(2)
runner:ranges({
local spec = {
name = "css",
provider = "treesitter",
file = "tests/queries/css/style.css",
ranges = {
{ 5, 9, 5, 34 },
{ 9, 9, 10, 37 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/heex_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/heex/index.html.heex")

describe("queries heex:", function()
runner:classes(3)
runner:ranges({
local spec = {
name = "heex",
provider = "treesitter",
file = "tests/queries/heex/index.html.heex",
ranges = {
{ 0, 12, 0, 27 },
{ 1, 13, 1, 20 },
{ 2, 12, 5, 4 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/html_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/html/index.html")

describe("queries html:", function()
runner:classes(2)
runner:ranges({
local spec = {
name = "html",
provider = "treesitter",
file = "tests/queries/html/index.html",
ranges = {
{ 10, 14, 10, 47 },
{ 11, 16, 11, 39 },
})
end)
},
}

require("tests.queries.runner").test(spec)
18 changes: 10 additions & 8 deletions tests/queries/htmldjango_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/html/index.html", "htmldjango")

describe("queries htmldjango:", function()
runner:classes(2)
runner:ranges({
local spec = {
name = "html",
provider = "treesitter",
file = "tests/queries/html/index.html",
filetype = "htmldjango",
ranges = {
{ 10, 14, 10, 47 },
{ 11, 16, 11, 39 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/php_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/php/index.php")

describe("queries php:", function()
runner:classes(2)
runner:ranges({
local spec = {
name = "php",
provider = "treesitter",
file = "tests/queries/php/index.php",
ranges = {
{ 10, 14, 10, 47 },
{ 11, 16, 11, 39 },
})
end)
},
}

require("tests.queries.runner").test(spec)
36 changes: 36 additions & 0 deletions tests/queries/runner.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local M = {}

local assert = require("luassert")
local classes = require("tailwind-tools.classes")

---@class TestSpec
---@field name string
---@field provider "treesitter" | "luapattern"
---@field file string
---@field filetype? string
---@field ranges number[][]

---@param spec TestSpec
M.test = function(spec)
describe(string.format("query %s (%s):", spec.name, spec.provider), function()
assert.same(1, vim.fn.filereadable(spec.file), spec.file .. " is not readable")

vim.cmd.edit(spec.file)
vim.bo.filetype = spec.filetype or vim.bo.filetype

local ranges = assert(classes.get_ranges(0), "Expected range list, got nil")

it(
"Should get class count",
function() assert.same(#ranges, #spec.ranges, "Mismatched class count") end
)

it("Should get ranges", function()
for i, range in pairs(ranges) do
assert.same(range, spec.ranges[i], "Mismatched range (index = " .. i .. ")")
end
end)
end)
end

return M
17 changes: 9 additions & 8 deletions tests/queries/svelte_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/svelte/test.svelte")

describe("queries svelte:", function()
runner:classes(3)
runner:ranges({
local spec = {
name = "svelte",
provider = "treesitter",
file = "tests/queries/svelte/test.svelte",
ranges = {
{ 4, 12, 4, 26 },
{ 5, 14, 5, 41 },
{ 8, 17, 8, 27 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/tsx_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/tsx/Component.tsx")

describe("queries tsx:", function()
runner:classes(3)
runner:ranges({
local spec = {
name = "tsx",
provider = "treesitter",
file = "tests/queries/tsx/Component.tsx",
ranges = {
{ 6, 19, 7, 55 },
{ 9, 24, 9, 47 },
{ 13, 33, 13, 45 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/twig_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/twig/test.twig")

describe("queries twig:", function()
runner:classes(3)
runner:ranges({
local spec = {
name = "twig",
provider = "treesitter",
file = "tests/queries/twig/test.twig",
ranges = {
{ 0, 12, 0, 26 },
{ 1, 14, 1, 41 },
{ 4, 17, 4, 27 },
})
end)
},
}

require("tests.queries.runner").test(spec)
17 changes: 9 additions & 8 deletions tests/queries/vue_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local common = require("tests.queries.common")
local runner = common.Runner:new("tests/queries/vue/test.vue")

describe("queries vue:", function()
runner:classes(3)
runner:ranges({
local spec = {
name = "vue",
provider = "treesitter",
file = "tests/queries/vue/test.vue",
ranges = {
{ 1, 14, 1, 28 },
{ 2, 16, 2, 43 },
{ 4, 39, 4, 49 },
})
end)
},
}

require("tests.queries.runner").test(spec)

0 comments on commit 5bb7b8b

Please sign in to comment.