From ff2aafeb98ee917bcd3b9f576ce10be0d3ee6506 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 23 May 2019 19:57:51 -0500 Subject: [PATCH] DEV: Handle grouped comments with embedded comments. --- src/ast/printer/mod.rs | 8 ++++++++ src/ast/printer/test.rs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ast/printer/mod.rs b/src/ast/printer/mod.rs index 2fc7895..bb682e6 100644 --- a/src/ast/printer/mod.rs +++ b/src/ast/printer/mod.rs @@ -425,7 +425,15 @@ where }, Expression::Grouped(ref expr, _) => { write!(self.w, "(")?; + if self.has_comment(expr.pos().line) { + self.curr_indent += self.indent_size; + did_indent = true; + write!(self.w, "\n")?; + } self.render_expr(expr)?; + if did_indent { + write!(self.w, "\n")?; + } write!(self.w, ")")?; } Expression::Import(_def) => { diff --git a/src/ast/printer/test.rs b/src/ast/printer/test.rs index 82b26f8..cf07201 100644 --- a/src/ast/printer/test.rs +++ b/src/ast/printer/test.rs @@ -360,3 +360,19 @@ fn test_reduce_func_operator_expression_with_embedded_comment() { let output = print_to_buffer(input); assert_eq!(output, format!("{}\n", input.trim())); } + +#[test] +fn test_map_func_operator_expression_with_embedded_comment() { + //let input = "// a comment\nfilter(foo, bar);"; + let input = "// a comment\nmap(\n // another comment\n foo,\n // one more\n bar);"; + let output = print_to_buffer(input); + assert_eq!(output, format!("{}\n", input.trim())); +} + +#[test] +fn test_grouped_expression_with_embedded_comment() { + //let input = "// a comment\nfilter(foo, bar);"; + let input = "// a comment\n(\n // a comment\n foo\n);"; + let output = print_to_buffer(input); + assert_eq!(output, format!("{}\n", input.trim())); +}