spec(teal_type_definition): add basic test
This commit is contained in:
parent
008985d5ea
commit
1ccb6d0ce9
|
@ -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)
|
Loading…
Reference in New Issue