toml-rs/tests/pretty.rs

27 lines
538 B
Rust
Raw Normal View History

2017-07-09 15:58:48 -05:00
extern crate toml;
extern crate serde;
use serde::ser::Serialize;
2017-07-09 16:10:36 -05:00
const EXAMPLE: &str = "\
2017-07-09 15:58:48 -05:00
[example]
2017-07-09 16:20:29 -05:00
array = [
\"item 1\",
\"item 2\",
]
2017-07-09 15:58:48 -05:00
text = '''
this is the first line
this is the second line
'''
";
#[test]
fn test_pretty() {
2017-07-09 16:10:36 -05:00
let value: toml::Value = toml::from_str(EXAMPLE).unwrap();
2017-07-09 15:58:48 -05:00
let mut result = String::with_capacity(128);
value.serialize(&mut toml::Serializer::pretty(&mut result)).unwrap();
2017-07-09 16:20:29 -05:00
println!("example:\n{}", EXAMPLE);
println!("result:\n{}", result);
2017-07-09 16:10:36 -05:00
assert_eq!(EXAMPLE, &result);
2017-07-09 15:58:48 -05:00
}