diff --git a/spec/scraper/module_doc_spec.tl b/spec/scraper/module_doc_spec.tl index b347cd4..4d07db1 100644 --- a/spec/scraper/module_doc_spec.tl +++ b/spec/scraper/module_doc_spec.tl @@ -280,4 +280,272 @@ describe("Scrap documentation", function() token = "module", }) end) + + it("should produce Function nodes", function() + local ast = get_doc_from_page([[ +

+ Static module functions +

+
+
+ 🔗 + awesome.kill + (pid, sig) + -> boolean + +
+
+ Send a signal to a process. +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + +
NameType(s)Description
pid + integer + + Process identifier. 0 and negative values have special meaning. See + man 3 kill. +
sig + integer + + Signal number. See + awesome.unix_signal + for a list of signals. +
+

Returns:

+
    + boolean + true if the signal was successfully sent, else false +
+
+
+ ]], "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 = get_doc_from_page([[ + --

+ -- Static module functions + --

+ --
+ --
+ -- 🔗 + -- awful.screen.focused + -- {[args]} + -- -> nil or screen + -- + --
+ --
+ --

Parameters:

+ -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + --
NameType(s)DescriptionDefault value
argsOptional + -- table + -- Undefined
clientOptional + -- boolean + -- + -- Use the client screen instead of the mouse screen. + -- + -- false + --
mouseOptional + -- boolean + -- Use the mouse screen + -- true + --
+ --

Returns:

+ --
    + -- optional + -- screen + -- The focused screen object, or + -- nil + -- in case no screen is present currently. + --
+ --
+ --
+ -- ]], "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 , other_nodes = get_doc_from_page([[ +

+ Static module functions +

+
+
+ 🔗 + client.instances + () + -> integer + +
+
+ Get the number of instances. +

Returns:

+
    + integer + The number of client objects alive. +
+ +
+
+ ]], "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)