local assert = require("luassert") local scraper = require("scraper").module_doc local get_doc_from_page = scraper.get_doc_from_page describe("Scrap documentation", function() it("should return a valid AST for an empty module", function() local ast , nodes = get_doc_from_page("", "empty") assert.same(ast, { children = { { children = {}, name = "Signal", token = "enum", } }, name = "Empty", token = "module", }) assert.same(nodes, {}) end) it("should produce Variable and `property::` Signal nodes", function() local ast = get_doc_from_page([[

Object properties

馃敆 value number 路 1 signal

Constraints:

Default value : 0
Negative allowed : true
]], "property_signal") assert.same(ast, { children = { { children = { { name = "property::value", token = "identifier", }, }, name = "Signal", token = "enum", }, { name = "value", types = { "number" }, token = "variable", } }, name = "Property_signal", token = "module", }) end) it("should produce Enum nodes when an Object Property type is a String with constraints", function() local ast = get_doc_from_page([[

Object properties

馃敆 horizontal_fit_policy string 路 1 signal
Default value : "auto"
Valid values:
"auto" : Honor the resize variable and preserve the aspect ratio.
"none" : Do not resize at all.
"fit" : Resize to the widget width.
]], "property_enum") assert.same(ast, { children = { { children = { { name = "property::horizontal_fit_policy", token = "identifier", }, }, name = "Signal", token = "enum", }, { children = { { name = "auto", token = "identifier", }, { name = "none", token = "identifier", }, { name = "fit", token = "identifier", }, }, name = "Horizontal_fit_policy", token = "enum", }, { name = "horizontal_fit_policy", types = { "Horizontal_fit_policy" }, token = "variable", }, }, name = "Property_enum", token = "module", }) end) it("should produce a `string` typed Variable node when a String Property has no constraint", function() local ast = get_doc_from_page([[

Object properties

馃敆 markup string 路 1 signal
string
]], "property_string") assert.same(ast, { children = { { children = { { name = "property::markup", token = "identifier", }, }, name = "Signal", token = "enum", }, { name = "markup", types = { "string" }, token = "variable", } }, name = "Property_string", token = "module", }) end) it("should produce Signal nodes", function() local ast = get_doc_from_page([[

Signals

馃敆 widget::layout_changed 路 Inherited from wibox.widget.base
馃敆 widget::redraw_needed 路 Inherited from wibox.widget.base
]], "signal") assert.same(ast, { children = { { children = { { name = "widget::layout_changed", token = "identifier", }, { name = "widget::redraw_needed", token = "identifier", }, }, name = "Signal", token = "enum", }, }, name = "Signal", token = "module", }) end) end)