From 129f15ea9d1a536ea9f29beff75b7c3af5b82d78 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 4 May 2023 00:49:19 +0200 Subject: [PATCH] spec(module_doc): add "Object properties" tests --- .vscode/settings.json | 1 + spec/scraper/module_doc_spec.tl | 211 +++++++++++++++++++++++ src/awesomewm.d.tl/scraper/module_doc.tl | 2 +- 3 files changed, 213 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 008bada..87b906d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -37,6 +37,7 @@ "Stylua", "sublist", "tablex", + "tbody", "tmpl", "wibox", "woodpeckerci", diff --git a/spec/scraper/module_doc_spec.tl b/spec/scraper/module_doc_spec.tl index b0432b4..b347cd4 100644 --- a/spec/scraper/module_doc_spec.tl +++ b/spec/scraper/module_doc_spec.tl @@ -20,6 +20,217 @@ describe("Scrap documentation", function() 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

diff --git a/src/awesomewm.d.tl/scraper/module_doc.tl b/src/awesomewm.d.tl/scraper/module_doc.tl index 972f5d8..a58f2d8 100644 --- a/src/awesomewm.d.tl/scraper/module_doc.tl +++ b/src/awesomewm.d.tl/scraper/module_doc.tl @@ -82,7 +82,7 @@ end local function extract_property_constraints(property_constraint_node: scan.HTMLNode): { string } return scraper_utils.scrape( property_constraint_node:outer_html(), - "tr.see_also_sublist", + "tr.see_also_sublist i code", extract_node_text ) end