aboutsummaryrefslogtreecommitdiff
path: root/src/formatter/formatter.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-26 15:51:52 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-26 15:51:52 -0400
commite5677cb9a670ca9e1e4c5d47f3c130622c619772 (patch)
tree9ccfe8d23a3ff79a523d6595e96703494b234db5 /src/formatter/formatter.c
parentcb1d36c6d8bc84f3422c71ab3eb29606e80f7837 (diff)
Add formatting for asserts
Diffstat (limited to 'src/formatter/formatter.c')
-rw-r--r--src/formatter/formatter.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c
index 5dd65d04..6f0fc5aa 100644
--- a/src/formatter/formatter.c
+++ b/src/formatter/formatter.c
@@ -47,6 +47,13 @@ OptionalText_t format_inline_code(ast_t *ast, Table_t comments) {
/*inline*/ case ConvertDef:
/*inline*/ case DocTest:
return NONE_TEXT;
+ /*inline*/ case Assert: {
+ DeclareMatch(assert, ast, Assert);
+ Text_t expr = fmt_inline(assert->expr, comments);
+ if (!assert->message) return Texts("assert ", expr);
+ Text_t message = fmt_inline(assert->message, comments);
+ return Texts("assert ", expr, ", ", message);
+ }
/*inline*/ case Lambda: {
DeclareMatch(lambda, ast, Lambda);
Text_t code = Texts("func(", format_inline_args(lambda->args, comments));
@@ -662,6 +669,13 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) {
}
return code;
}
+ /*multiline*/ case Assert: {
+ DeclareMatch(assert, ast, Assert);
+ Text_t expr = fmt(assert->expr, comments, indent);
+ if (!assert->message) return Texts("assert ", expr);
+ Text_t message = fmt(assert->message, comments, indent);
+ return Texts("assert ", expr, ", ", message);
+ }
/*multiline*/ case BINOP_CASES: {
if (inlined_fits) return inlined;
binary_operands_t operands = BINARY_OPERANDS(ast);