spec(module_doc): fix and refactor
Fix the tests by adding the new keys from `"module"` tokens. We now use a `test` function to make the `it` easier to write/read.
This commit is contained in:
parent
78d50c7541
commit
c5430c59b7
|
@ -4,10 +4,19 @@ local scraper = require("scraper.module_doc")
|
|||
|
||||
local get_doc_from_page = scraper.get_doc_from_page
|
||||
|
||||
local function test(html: string, module_path: string, expected_ast: Node, expected_other_nodes: { Node } | nil): function()
|
||||
return function()
|
||||
local ast <const>, other_nodes <const> = get_doc_from_page(html, module_path)
|
||||
assert.same(expected_ast, ast)
|
||||
assert.same(expected_other_nodes or {}, other_nodes)
|
||||
end
|
||||
end
|
||||
|
||||
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")
|
||||
local expected <const>: Node = {
|
||||
it("should return a valid AST for an empty module", test(
|
||||
"",
|
||||
"empty",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -16,14 +25,13 @@ describe("Scrap documentation", function()
|
|||
}
|
||||
},
|
||||
name = "Empty",
|
||||
module_path = "empty",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
assert.same({}, nodes)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce Variable and `property::` Signal nodes", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce Variable and `property::` Signal nodes", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Object_properties"></a>Object properties
|
||||
</h2>
|
||||
|
@ -58,8 +66,9 @@ describe("Scrap documentation", function()
|
|||
</span>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "property_signal")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"property_signal",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {
|
||||
|
@ -78,13 +87,13 @@ describe("Scrap documentation", function()
|
|||
}
|
||||
},
|
||||
name = "Property_signal",
|
||||
module_path = "property_signal",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce Enum nodes when an Object Property type is a String with constraints", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce Enum nodes when an Object Property type is a String with constraints", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Object_properties"></a>Object properties
|
||||
</h2>
|
||||
|
@ -152,8 +161,9 @@ describe("Scrap documentation", function()
|
|||
</span>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "property_enum")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"property_enum",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {
|
||||
|
@ -190,13 +200,13 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Property_enum",
|
||||
module_path = "property_enum",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce a `string` typed Variable node when a String Property has no constraint", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce a `string` typed Variable node when a String Property has no constraint", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Object_properties"></a>Object properties
|
||||
</h2>
|
||||
|
@ -211,8 +221,9 @@ describe("Scrap documentation", function()
|
|||
<span class="property_type">string</span>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "property_string")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"property_string",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {
|
||||
|
@ -231,13 +242,13 @@ describe("Scrap documentation", function()
|
|||
}
|
||||
},
|
||||
name = "Property_string",
|
||||
module_path = "property_string",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should provide a Function node with the `self` as the first positional parameter", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should provide a Function node with the `self` as the first positional parameter", test(
|
||||
[[
|
||||
<h2 class="section-header"><a name="Object_methods"></a>Object methods</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
@ -270,8 +281,9 @@ describe("Scrap documentation", function()
|
|||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "awful.tag")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"awful.tag",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -297,13 +309,13 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Tag",
|
||||
module_path = "awful.tag",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce Signal nodes", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce Signal nodes", test(
|
||||
[[
|
||||
<h2 class="section-header"><a name="Signals"></a>Signals</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
@ -329,8 +341,9 @@ describe("Scrap documentation", function()
|
|||
</dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
]], "signal")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"signal",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {
|
||||
|
@ -348,13 +361,13 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Signal",
|
||||
module_path = "signal",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce Function nodes", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce Function nodes", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Static_module_functions"></a>Static module functions
|
||||
</h2>
|
||||
|
@ -415,8 +428,9 @@ describe("Scrap documentation", function()
|
|||
</ol>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "awesome") -- The module name must be the same as the module name in the doc
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"awesome", -- The module name must be the same as the module name in the doc
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -442,13 +456,13 @@ describe("Scrap documentation", function()
|
|||
}
|
||||
},
|
||||
name = "Awesome",
|
||||
module_path = "awesome",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should produce a Record node when a function parameter is a named-parameter-table", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should produce a Record node when a function parameter is a named-parameter-table", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Static_module_functions"></a>Static module functions
|
||||
</h2>
|
||||
|
@ -529,8 +543,9 @@ describe("Scrap documentation", function()
|
|||
</ol>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "awful.screen")
|
||||
assert.same(ast, {
|
||||
]],
|
||||
"awful.screen",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -567,12 +582,13 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Screen",
|
||||
module_path = "awful.screen",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
})
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should go back to a table typed parameter when the record is empty", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should go back to a table typed parameter when the record is empty", test(
|
||||
[[
|
||||
<h2 class="section-header "><a name="Static_module_functions"></a>Static module functions</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
@ -624,8 +640,9 @@ describe("Scrap documentation", function()
|
|||
</ol>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "gears.table")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"gears.table",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -656,13 +673,13 @@ describe("Scrap documentation", function()
|
|||
}
|
||||
},
|
||||
name = "Table",
|
||||
module_path = "gears.table",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should go back to a table typed parameter when the record is empty and it's the last parameter", function()
|
||||
local ast <const> = get_doc_from_page([[
|
||||
it("should go back to a table typed parameter when the record is empty and it's the last parameter", test(
|
||||
[[
|
||||
<h2 class="section-header"><a name="Object_methods"></a>Object methods</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
@ -720,8 +737,9 @@ describe("Scrap documentation", function()
|
|||
</ol>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "awful.client")
|
||||
local expected <const>: Node = {
|
||||
]],
|
||||
"awful.client",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -747,13 +765,13 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Client",
|
||||
module_path = "awful.client",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
assert.same(expected, ast)
|
||||
end)
|
||||
}))
|
||||
|
||||
it("should return Function nodes with the `other_nodes` list when the function module name doesn't match the module name", function()
|
||||
local ast <const>, other_nodes <const> = get_doc_from_page([[
|
||||
it("should return Function nodes with the `other_nodes` list when the function module name doesn't match the module name", test(
|
||||
[[
|
||||
<h2 class="section-header">
|
||||
<a name="Static_module_functions"></a>Static module functions
|
||||
</h2>
|
||||
|
@ -779,8 +797,9 @@ describe("Scrap documentation", function()
|
|||
<span id="item826" class="hide_extra"> </span>
|
||||
</dd>
|
||||
</dl>
|
||||
]], "awful.client")
|
||||
local expected_ast <const>: Node = {
|
||||
]],
|
||||
"awful.client",
|
||||
{
|
||||
children = {
|
||||
{
|
||||
children = {},
|
||||
|
@ -789,17 +808,16 @@ describe("Scrap documentation", function()
|
|||
},
|
||||
},
|
||||
name = "Client",
|
||||
module_path = "awful.client",
|
||||
dependencies = {},
|
||||
token = "module",
|
||||
}
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue