Skip to content

Commit

Permalink
feat: Permit newlines in text documents
Browse files Browse the repository at this point in the history
Multiline strings are actually a valid use-case for this.
  • Loading branch information
Marwes committed Jun 16, 2018
1 parent ba08ced commit d11ad4b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ pub trait DocAllocator<'a, A> {
#[inline]
fn text<T: Into<Cow<'a, str>>>(&'a self, data: T) -> DocBuilder<'a, Self, A> {
let text = data.into();
debug_assert!(!text.contains(|c: char| c == '\n' || c == '\r'));
DocBuilder(self, Text(text))
}

Expand Down Expand Up @@ -418,7 +417,6 @@ impl<'a, A, B> Doc<'a, A, B> {
#[inline]
pub fn text<T: Into<Cow<'a, str>>>(data: T) -> Doc<'a, A, B> {
let text = data.into();
debug_assert!(!text.contains(|c: char| c == '\n' || c == '\r'));
Text(text)
}

Expand Down Expand Up @@ -518,6 +516,19 @@ mod tests {
test!(doc, "test test");
}

#[test]
fn newline_in_text() {
let doc = Doc::<_>::group(
Doc::text("test").append(
Doc::space()
.append(Doc::text("\"test\n test\""))
.nest(4),
),
);

test!(5, doc, "test\n \"test\n test\"");
}

#[test]
fn forced_newline() {
let doc = Doc::<_>::group(
Expand Down

0 comments on commit d11ad4b

Please sign in to comment.