chore(spec): defined expected with type safety

This commit is contained in:
Aire-One 2023-05-08 23:48:08 +02:00
parent ba51f09e47
commit 008985d5ea
1 changed files with 30 additions and 20 deletions

View File

@ -1,12 +1,13 @@
local assert = require("luassert")
local scraper = require("scraper").module_doc
local type Node = require("types.Node")
local scraper = require("scraper.module_doc")
local get_doc_from_page = scraper.get_doc_from_page
describe("Scrap documentation", function()
it("should return a valid AST for an empty module", function()
local ast <const>, nodes <const> = get_doc_from_page("", "empty")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {},
@ -16,8 +17,9 @@ describe("Scrap documentation", function()
},
name = "Empty",
token = "module",
})
assert.same(nodes, {})
}
assert.same(expected, ast)
assert.same({}, nodes)
end)
it("should produce Variable and `property::` Signal nodes", function()
@ -57,7 +59,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "property_signal")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {
@ -77,7 +79,8 @@ describe("Scrap documentation", function()
},
name = "Property_signal",
token = "module",
})
}
assert.same(expected, ast)
end)
it("should produce Enum nodes when an Object Property type is a String with constraints", function()
@ -150,7 +153,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "property_enum")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {
@ -188,7 +191,8 @@ describe("Scrap documentation", function()
},
name = "Property_enum",
token = "module",
})
}
assert.same(expected, ast)
end)
it("should produce a `string` typed Variable node when a String Property has no constraint", function()
@ -208,7 +212,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "property_string")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {
@ -228,7 +232,8 @@ describe("Scrap documentation", function()
},
name = "Property_string",
token = "module",
})
}
assert.same(expected, ast)
end)
it("should provide a Function node with the `self` as the first positional parameter", function()
@ -266,7 +271,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "awful.tag")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {},
@ -293,7 +298,8 @@ describe("Scrap documentation", function()
},
name = "Tag",
token = "module",
})
}
assert.same(expected, ast)
end)
it("should produce Signal nodes", function()
@ -324,7 +330,7 @@ describe("Scrap documentation", function()
<dd></dd>
</dl>
]], "signal")
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {
@ -343,7 +349,8 @@ describe("Scrap documentation", function()
},
name = "Signal",
token = "module",
})
}
assert.same(expected, ast)
end)
it("should produce Function nodes", function()
@ -409,7 +416,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "awesome") -- The module name must be the same as the module name in the doc
assert.same(ast, {
local expected <const>: Node = {
children = {
{
children = {},
@ -436,7 +443,8 @@ describe("Scrap documentation", function()
},
name = "Awesome",
token = "module",
})
}
assert.same(expected, ast)
end)
-- TODO : Fix the code then come back to this test, the current implementation is incomplete
@ -593,7 +601,7 @@ describe("Scrap documentation", function()
</dd>
</dl>
]], "awful.client")
assert.same(ast, {
local expected_ast <const>: Node = {
children = {
{
children = {},
@ -603,14 +611,16 @@ describe("Scrap documentation", function()
},
name = "Client",
token = "module",
})
assert.same(other_nodes, {
}
assert.same(expected_ast, ast)
local expected_other_nodes <const>: { Node } = {
{
parameters = {},
return_types = { "integer" },
name = "client.instances",
token = "function",
}
})
}
assert.same(expected_other_nodes, other_nodes)
end)
end)