Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #322 from dtolnay/width
Browse files Browse the repository at this point in the history
Set width=-1 on libyaml emitter
  • Loading branch information
dtolnay committed Sep 2, 2022
2 parents 638b1c0 + 53ccded commit 4253336
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libyaml/emitter.rs
Expand Up @@ -70,6 +70,7 @@ impl<'a> Emitter<'a> {
panic!("malloc error: {}", libyaml::Error::emit_error(emitter));
}
sys::yaml_emitter_set_unicode(emitter, true);
sys::yaml_emitter_set_width(emitter, -1);
addr_of_mut!((*owned.ptr).write).write(write);
addr_of_mut!((*owned.ptr).write_error).write(None);
sys::yaml_emitter_set_output(emitter, write_handler, owned.ptr.cast());
Expand Down
19 changes: 19 additions & 0 deletions tests/test_serde.rs
Expand Up @@ -11,6 +11,7 @@ use serde_derive::{Deserialize, Serialize};
use serde_yaml::{Mapping, Number, Value};
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;

fn test_serde<T>(thing: &T, yaml: &str)
where
Expand Down Expand Up @@ -528,3 +529,21 @@ fn test_mapping() {

test_serde(&thing, yaml);
}

#[test]
fn test_long_string() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Data {
pub string: String,
}

let thing = Data {
string: iter::repeat(["word", " "]).flatten().take(69).collect(),
};

let yaml = indoc! {"
string: word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word
"};

test_serde(&thing, yaml);
}

0 comments on commit 4253336

Please sign in to comment.