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