DEV: Handle grouped comments with embedded comments.

This commit is contained in:
Jeremy Wall 2019-05-23 19:57:51 -05:00
parent 157f123355
commit ff2aafeb98
2 changed files with 24 additions and 0 deletions

View File

@ -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) => {

View File

@ -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()));
}