spec(teal_type_definition): test Variable node
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-13 00:19:49 +02:00
parent 136560aad6
commit 5ae73bbbc6
2 changed files with 28 additions and 13 deletions

View File

@ -17,7 +17,7 @@ local function gen(ast: Node, expected_code: string): function()
end
end
describe("Print Teal type definition", function()
describe("Teal type definition Printer", function()
it("should print a simple module type definition", gen(
{
children = {},
@ -66,4 +66,26 @@ describe("Print Teal type definition", function()
return Signal_Module
]]))
it("should print a property exposed by the module", gen(
{
children = {
{
name = "text",
types = { "string", "nil" },
token = "variable",
}
},
name = "Property_Module",
token = "module",
},
[[
-- This file was auto-generated.
local record Property_Module
text: string | nil
end
return Property_Module
]]))
end)

View File

@ -1,23 +1,16 @@
local ast = require "ast"
local logger = require "logger"
local type Node = require "types.Node"
local ast = require("ast")
local logger = require("logger")
local type Node = require("types.Node")
local stringx = require("pl.stringx")
local log = logger.log("scraper")
local function concatenate_strings(strings: { string }): string
local result = ""
for _, str in ipairs(strings) do
result = result .. str
end
return result
end
local function render_types(types: { string }): string
if not types or #types == 0 then
return ""
end
return ": " .. concatenate_strings(types)
return ": " .. stringx.join(" | ", types)
end
local record Node_Printer_Function