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

Set width=-1 on libyaml emitter #322

Merged
merged 2 commits into from Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}