Skip to content

Commit 06d2f95

Browse files
giacomocavalierilpil
authored andcommitted
add missing tests
1 parent e80e60b commit 06d2f95

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

compiler-core/src/format.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ impl<'comments> Formatter<'comments> {
738738
[first_line, lines @ ..] => {
739739
let mut doc = docvec!("\"", first_line);
740740
for line in lines {
741-
doc = doc.append(pretty::line().set_nest(0)).append(line.to_doc())
741+
doc = doc
742+
.append(pretty::line().set_nesting(0))
743+
.append(line.to_doc())
742744
}
743745
doc.append("\"".to_doc()).group()
744746
}

compiler-core/src/format/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5390,6 +5390,25 @@ fn multiline_string_are_not_broken_with_string_concatenation_if_they_fit() {
53905390
);
53915391
}
53925392

5393+
#[test]
5394+
fn nesting_goes_back_to_normal_after_multiline_string() {
5395+
assert_format!(
5396+
r#"pub fn main() {
5397+
let x = {
5398+
"
5399+
1
5400+
2
5401+
" <> long_name_function_call(
5402+
1_111_111_111_111_111,
5403+
222_222_222_222,
5404+
3_333_333_333_333_333,
5405+
)
5406+
}
5407+
}
5408+
"#
5409+
);
5410+
}
5411+
53935412
#[test]
53945413
fn multiline_string_get_broken_on_newlines_as_function_arguments() {
53955414
assert_format!(

compiler-core/src/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'a> Document<'a> {
584584
Self::Group(Box::new(self))
585585
}
586586

587-
pub fn set_nest(self, indent: isize) -> Self {
587+
pub fn set_nesting(self, indent: isize) -> Self {
588588
Self::Nest(indent, NestMode::Set, NestCondition::Always, Box::new(self))
589589
}
590590

compiler-core/src/pretty/tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,9 @@ fn empty_documents() {
309309
assert!(!"foo".to_doc().append("".to_doc()).is_empty());
310310
assert!(!"".to_doc().append("foo".to_doc()).is_empty());
311311
}
312+
313+
#[test]
314+
fn set_nesting() {
315+
let doc = Vec(vec!["foo".to_doc(), break_("", " "), "bar".to_doc()]).group();
316+
assert_eq!("foo\nbar", doc.set_nesting(0).nest(2).to_pretty_string(1));
317+
}

0 commit comments

Comments
 (0)