chore(spec): defined expected with type safety
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details

This commit is contained in:
Aire-One 2023-05-08 23:48:08 +02:00
parent 6d647cd9bc
commit f324e9e303
1 changed files with 29 additions and 18 deletions

View File

@ -1,5 +1,6 @@
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
@ -17,7 +18,9 @@ describe("Scrap documentation", function()
name = "Empty", name = "Empty",
token = "module", token = "module",
}) })
assert.same(nodes, {}) local expected <const>: Node = {}
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 +60,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 +80,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 +154,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 +192,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 +213,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 +233,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 +272,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 +299,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 +331,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 +350,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 +417,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 +444,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 +602,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 +612,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)