spec(module_doc): add "Static module functions" tests
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-05 00:41:02 +02:00
parent 9165e98db3
commit 5e6ceb7e04
1 changed files with 268 additions and 0 deletions

View File

@ -280,4 +280,272 @@ describe("Scrap documentation", function()
token = "module",
})
end)
it("should produce Function nodes", function()
local ast <const> = get_doc_from_page([[
<h2 class="section-header">
<a name="Static_module_functions"></a>Static module functions
</h2>
<dl class="function">
<dt>
<a class="copy-link js-copy-link" name="kill" href="#kill">🔗</a>
<strong
><span class="function_modname">awesome.</span>kill
<span class="function_args"> <b>(</b>pid, sig<b>)</b></span></strong
>
<span class="proptype"
><span class="summary_type"> -&gt;&nbsp;boolean</span></span
>
<span class="baseclass"> </span>
</dt>
<dd>
Send a signal to a process.
<h3>Parameters:</h3>
<table class="see_also">
<tbody>
<tr class="param_header">
<th>Name</th>
<th></th>
<th>Type(s)</th>
<th>Description</th>
</tr>
<tr>
<td><span class="parameter">pid</span></td>
<td></td>
<td>
<span class="types"><span class="type">integer</span></span>
</td>
<td class="see_also_description">
Process identifier. 0 and negative values have special meaning. See
<code>man 3 kill</code>.
</td>
</tr>
<tr>
<td><span class="parameter">sig</span></td>
<td></td>
<td>
<span class="types"><span class="type">integer</span></span>
</td>
<td class="see_also_description">
Signal number. See
<a href="../core_components/awesome.html#unix_signal"
>awesome.unix_signal</a
>
for a list of signals.
</td>
</tr>
</tbody>
</table>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
true if the signal was successfully sent, else false
</ol>
</dd>
</dl>
]], "awesome") -- The module name must be the same as the module name in the doc
assert.same(ast, {
children = {
{
children = {},
name = "Signal",
token = "enum",
},
{
parameters = {
{
types = { "integer" },
name = "pid",
token = "variable",
},
{
types = { "integer" },
name = "sig",
token = "variable",
},
},
return_types = { "boolean" },
name = "kill",
token = "function",
}
},
name = "Awesome",
token = "module",
})
end)
-- TODO : Fix the code then come back to this test, the current implementation is incomplete
-- it("should produce a Record node when the function parameter is a table", function()
-- local ast <const> = get_doc_from_page([[
-- <h2 class="section-header">
-- <a name="Static_module_functions"></a>Static module functions
-- </h2>
-- <dl class="function">
-- <dt>
-- <a
-- class="copy-link js-copy-link"
-- name="awful.screen.focused"
-- href="#awful.screen.focused"
-- >🔗</a
-- >
-- <strong
-- >awful.screen.focused
-- <span class="function_named_args"><b>{</b>[args]<b>}</b></span></strong
-- >
-- <span class="proptype"
-- ><span class="summary_type"> -&gt;&nbsp;nil <i>or</i> screen</span></span
-- >
-- <span class="baseclass"> </span>
-- </dt>
-- <dd>
-- <h3>Parameters:</h3>
-- <table class="see_also">
-- <tbody>
-- <tr class="param_header">
-- <th>Name</th>
-- <th></th>
-- <th>Type(s)</th>
-- <th>Description</th>
-- <th>Default value</th>
-- </tr>
-- <tr>
-- <td><span class="parameter">args</span></td>
-- <td><span class="chips">Optional</span></td>
-- <td>
-- <span class="types"><span class="type">table</span></span>
-- </td>
-- <td class="see_also_description"></td>
-- <td><span class="not_applicable">Undefined</span></td>
-- </tr>
-- <tr class="see_also_sublist">
-- <td><span class="parameter">client</span></td>
-- <td><span class="chips">Optional</span></td>
-- <td>
-- <span class="types"><span class="type">boolean</span></span>
-- </td>
-- <td class="see_also_description">
-- Use the client screen instead of the mouse screen.
-- </td>
-- <td>
-- <span class="default_value"><code>false</code></span>
-- </td>
-- </tr>
-- <tr class="see_also_sublist">
-- <td><span class="parameter">mouse</span></td>
-- <td><span class="chips">Optional</span></td>
-- <td>
-- <span class="types"><span class="type">boolean</span></span>
-- </td>
-- <td class="see_also_description">Use the mouse screen</td>
-- <td>
-- <span class="default_value"><code>true</code></span>
-- </td>
-- </tr>
-- </tbody>
-- </table>
-- <h3>Returns:</h3>
-- <ol>
-- <span class="types"
-- >optional
-- <a class="type" href="../core_components/screen.html#screen"
-- >screen</a
-- ></span
-- >
-- The focused screen object, or
-- <code>nil</code>
-- in case no screen is present currently.
-- </ol>
-- </dd>
-- </dl>
-- ]], "awful.screen")
-- print(require("inspect")(ast))
-- assert.same(ast, {
-- children = {
-- {
-- children = {},
-- name = "Signal",
-- token = "enum",
-- },
-- {
-- parameters = {
-- {
-- children = {
-- {
-- types = { "boolean" },
-- name = "client",
-- token = "variable",
-- },
-- {
-- types = { "boolean" },
-- name = "mouse",
-- token = "variable",
-- },
-- },
-- name = "Args",
-- token = "record",
-- },
-- {
-- types = { "Focused_Args" },
-- name = "args",
-- token = "variable",
-- },
-- },
-- return_types = { "screen" },
-- name = "focused",
-- token = "function",
-- },
-- },
-- name = "Screen",
-- token = "module",
-- })
-- 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([[
<h2 class="section-header">
<a name="Static_module_functions"></a>Static module functions
</h2>
<dl class="function">
<dt>
<a class="copy-link js-copy-link" name="instances" href="#instances">🔗</a>
<strong
><span class="function_modname">client.</span>instances
<span class="function_args"> <b>(</b><b>)</b></span></strong
>
<span class="proptype"
><span class="summary_type"> -&gt;&nbsp;integer</span></span
>
<span class="baseclass"> </span>
</dt>
<dd>
Get the number of instances.
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">integer</span></span>
The number of client objects alive.
</ol>
<span id="item826" class="hide_extra"> </span>
</dd>
</dl>
]], "awful.client")
assert.same(ast, {
children = {
{
children = {},
name = "Signal",
token = "enum",
},
},
name = "Client",
token = "module",
})
assert.same(other_nodes, {
{
parameters = {},
return_types = { "integer" },
name = "client.instances",
token = "function",
}
})
end)
end)