aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Berg <vitiral@gmail.com>2017-07-09 15:10:36 -0600
committerGarrett Berg <vitiral@gmail.com>2017-07-09 15:10:36 -0600
commitffdafc4d361df0d6f6063af50863b7f87f4aa46a (patch)
tree5d6bd26e7aa73a3480aa55756ff7805dd84d1b28
parent391cb61dffd51322bd310be7cba8641fe3398c19 (diff)
downloadmilf-rs-ffdafc4d361df0d6f6063af50863b7f87f4aa46a.tar.gz
milf-rs-ffdafc4d361df0d6f6063af50863b7f87f4aa46a.zip
array doesn't break anything...
-rw-r--r--src/ser.rs30
-rw-r--r--tests/pretty.rs6
2 files changed, 28 insertions, 8 deletions
diff --git a/src/ser.rs b/src/ser.rs
index d92b8a3..2bb9333 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -274,10 +274,24 @@ impl<'a> Serializer<'a> {
}
fn emit_array(&mut self, first: &Cell<bool>) -> Result<(), Error> {
- if first.get() {
- self.dst.push_str("[");
- } else {
- self.dst.push_str(", ");
+ match self.settings.array {
+ Some(ref a) => {
+ if first.get() {
+ self.dst.push_str("[\n")
+ } else {
+ self.dst.push_str(",\n")
+ }
+ for _ in 0..a.indent {
+ self.dst.push_str(" ");
+ }
+ },
+ None => {
+ if first.get() {
+ self.dst.push_str("[")
+ } else {
+ self.dst.push_str(", ")
+ }
+ },
}
Ok(())
}
@@ -652,7 +666,13 @@ impl<'a, 'b> ser::SerializeSeq for SerializeSeq<'a, 'b> {
fn end(self) -> Result<(), Error> {
match self.type_.get() {
Some("table") => return Ok(()),
- Some(_) => self.ser.dst.push_str("]"),
+ Some(_) => {
+ if self.ser.settings.array.is_some() {
+ self.ser.dst.push_str("\n]");
+ } else {
+ self.ser.dst.push_str("]");
+ }
+ }
None => {
assert!(self.first.get());
self.ser.emit_key("array")?;
diff --git a/tests/pretty.rs b/tests/pretty.rs
index 71c9e63..6758cfb 100644
--- a/tests/pretty.rs
+++ b/tests/pretty.rs
@@ -3,7 +3,7 @@ extern crate serde;
use serde::ser::Serialize;
-const example: &str = "\
+const EXAMPLE: &str = "\
[example]
text = '''
this is the first line
@@ -13,8 +13,8 @@ this is the second line
#[test]
fn test_pretty() {
- let value: toml::Value = toml::from_str(example).unwrap();
+ let value: toml::Value = toml::from_str(EXAMPLE).unwrap();
let mut result = String::with_capacity(128);
value.serialize(&mut toml::Serializer::pretty(&mut result)).unwrap();
- assert_eq!(example, &result);
+ assert_eq!(EXAMPLE, &result);
}