From da1081387f2ae645fece8715481385973775941d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 12 Feb 2024 02:07:12 -0500 Subject: Fix doctests for declarations --- compile.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 2b4c39e4..3170369d 100644 --- a/compile.c +++ b/compile.c @@ -306,11 +306,23 @@ CORD compile(ast_t *ast) case DocTest: { auto test = Match(ast, DocTest); CORD src = heap_strn(test->expr->start, (size_t)(test->expr->end - test->expr->start)); - return CORD_asprintf( - "__test(%r, %r, %r);\n", - compile(WrapAST(test->expr, StringLiteral, .cord=src)), - compile(test->expr), - compile(WrapAST(test->expr, StringLiteral, .cord=test->output))); + if (test->expr->tag == Declare) { + auto decl = Match(test->expr, Declare); + return CORD_asprintf( + "__declare(%r, %r);\n__test(%r, %r, %r);\n", + compile(decl->var), compile(decl->value), + compile(WrapAST(test->expr, StringLiteral, .cord=src)), + compile(decl->var), + compile(WrapAST(test->expr, StringLiteral, .cord=test->output))); + } else if (test->expr->tag == Assign) { + errx(1, "Not implemented"); + } else { + return CORD_asprintf( + "__test(%r, %r, %r);\n", + compile(WrapAST(test->expr, StringLiteral, .cord=src)), + compile(test->expr), + compile(WrapAST(test->expr, StringLiteral, .cord=test->output))); + } } case FieldAccess: { auto f = Match(ast, FieldAccess); -- cgit v1.2.3