diff --git a/spec/printer/teal_type_definition_spec.tl b/spec/printer/teal_type_definition_spec.tl new file mode 100644 index 0000000..7e49a7c --- /dev/null +++ b/spec/printer/teal_type_definition_spec.tl @@ -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)