spec(teal_type_definition): add basic test

This commit is contained in:
Aire-One 2023-05-09 00:27:29 +02:00
parent 008985d5ea
commit 1ccb6d0ce9
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
local assert = require("luassert")
local type Node = require("types.Node")
local stringx = require("pl.stringx")
local teal_type_definition_printer = require("printer.teal_type_definition")
local printer = teal_type_definition_printer.printer
-- We need to remove the last newline inserted by Penlight's dedent
local function dedent(str: string): string
return (stringx.dedent(str):sub(1, -3))
end
local function gen(ast: Node, expected_code: string): function()
return function()
local generated = printer(ast)
assert.same(dedent(expected_code), generated)
end
end
describe("Print Teal type definition", function()
it("should print a simple module type definition", gen(
{
children = {},
name = "Empty",
token = "module",
},
[[
-- This file was auto-generated.
local record Empty
end
return Empty
]]))
end)