From c5430c59b798f516bc8e31ae6992dae924b0abee Mon Sep 17 00:00:00 2001 From: Aire-One Date: Sun, 21 May 2023 20:42:32 +0200 Subject: [PATCH] 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. --- spec/scraper/module_doc_spec.tl | 466 +++++++++++++++++--------------- 1 file changed, 242 insertions(+), 224 deletions(-) diff --git a/spec/scraper/module_doc_spec.tl b/spec/scraper/module_doc_spec.tl index b56b53d..d563fd4 100644 --- a/spec/scraper/module_doc_spec.tl +++ b/spec/scraper/module_doc_spec.tl @@ -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 , other_nodes = 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 , nodes = get_doc_from_page("", "empty") - local expected : Node = { + it("should return a valid AST for an empty module", test( + "", + "empty", + { children = { { children = {}, @@ -16,50 +25,50 @@ 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 = get_doc_from_page([[ -

- Object properties -

-
-
- 馃敆 - value - number - 路 1 signal -
-
-

Constraints:

- - - - - - - - - - -
- - Default value - - : 0
- - Negative allowed - - : true
-
-
-
- ]], "property_signal") - local expected : Node = { + it("should produce Variable and `property::` Signal nodes", test( + [[ +

+ Object properties +

+
+
+ 馃敆 + value + number + 路 1 signal +
+
+

Constraints:

+ + + + + + + + + + +
+ + Default value + + : 0
+ + Negative allowed + + : true
+
+
+
+ ]], + "property_signal", + { children = { { children = { @@ -78,82 +87,83 @@ 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 = get_doc_from_page([[ + it("should produce Enum nodes when an Object Property type is a String with constraints", test( + [[

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.
-
-
+
+ 馃敆 + 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") - local expected : Node = { + ]], + "property_enum", + { children = { { children = { @@ -190,29 +200,30 @@ 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 = get_doc_from_page([[ -

- Object properties -

-
-
- 馃敆 - markup - string - 路 1 signal -
-
- string -
-
- ]], "property_string") - local expected : Node = { + it("should produce a `string` typed Variable node when a String Property has no constraint", test( + [[ +

+ Object properties +

+
+
+ 馃敆 + markup + string + 路 1 signal +
+
+ string +
+
+ ]], + "property_string", + { children = { { children = { @@ -231,47 +242,48 @@ 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 = get_doc_from_page([[ -

Object methods

-
-
- 馃敆 - :swap (tag2) - - -
-
-

Parameters:

- - - - - - - - - - - - - - - -
NameType(s)Description
tag2 - tag - The second tag
-
-
- ]], "awful.tag") - local expected : Node = { + it("should provide a Function node with the `self` as the first positional parameter", test( + [[ +

Object methods

+
+
+ 馃敆 + :swap (tag2) + + +
+
+

Parameters:

+ + + + + + + + + + + + + + + +
NameType(s)Description
tag2 + tag + The second tag
+
+
+ ]], + "awful.tag", + { children = { { children = {}, @@ -297,15 +309,15 @@ 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 = get_doc_from_page([[ -

Signals

-
+ it("should produce Signal nodes", test( + [[ +

Signals

+
路 Inherited from wibox.widget.base
-
- ]], "signal") - local expected : 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 = get_doc_from_page([[ + it("should produce Function nodes", test( + [[

Static module functions

@@ -415,8 +428,9 @@ describe("Scrap documentation", function() - ]], "awesome") -- The module name must be the same as the module name in the doc - local expected : 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 = get_doc_from_page([[ + it("should produce a Record node when a function parameter is a named-parameter-table", test( + [[

Static module functions

@@ -529,8 +543,9 @@ describe("Scrap documentation", function() - ]], "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 = get_doc_from_page([[ + it("should go back to a table typed parameter when the record is empty", test( + [[

Static module functions

@@ -624,8 +640,9 @@ describe("Scrap documentation", function()
- ]], "gears.table") - local expected : 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 = 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( + [[

Object methods

@@ -720,8 +737,9 @@ describe("Scrap documentation", function()
- ]], "awful.client") - local expected : 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 , other_nodes = 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( + [[

Static module functions

@@ -779,8 +797,9 @@ describe("Scrap documentation", function() - ]], "awful.client") - local expected_ast : 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 : { Node } = { + }, + { { parameters = {}, return_types = { "integer" }, name = "client.instances", token = "function", } - } - assert.same(expected_other_nodes, other_nodes) - end) + })) end)