Repository: ron-rs/ron (Rust)

Issue:
`to_string` produces text that `from_str` does not accept (with tuple variants)
```
# Cargo.toml
ron = "0.2.1"
```

---

Given the following type:

```rust
pub enum FileOrMem {
    File(String),
    Memory,
}
```

`ser::to_string` produces the following RON:

```
            data: Node (
                location: Location (
                    file_or_mem: File(
                        "foo/bar"
                    ),
                    column: 1,
                    line: 1
                ),
                key: "Player",
                value: None,
                comment: None
            )
```

Which fails deserialization with:

```
Parser(ExpectedString, Position { col: 39, line: 19 })
```

The fix, IME, is to change the text to be inline. But this should be fixed in parsing IMO (what I mean is that this syntax is reasonable and should be accepted).

---

For the sake of completeness this error is not restricted to string literals on a new line.

It also occurs if there is a space between the `(` and `"`.


Discussion:
Was this fixed in https://github.com/ron-rs/ron/commit/239cb7919ff06abdf2bd40514b16f39d6c3786f4?
Possibly, at least there was a similar bug.
Or in https://github.com/ron-rs/ron/commit/713284f17ab1b0883f0206c50e08d2c88b80e061
Version 0.2.2 is uploaded.
Thanks for the speedy fix, @torkleyy! :tada:



Patch:
diff --git a/Cargo.toml b/Cargo.toml
index bc69f4ee9..e9c901470 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "ron"
-version = "0.2.1"
+version = "0.2.2"
 license = "MIT/Apache-2.0"
 keywords = ["parser", "serde", "serialization"]
 authors = [
diff --git a/src/de/mod.rs b/src/de/mod.rs
index 5fb7fbb6a..0813ddefa 100644
--- a/src/de/mod.rs
+++ b/src/de/mod.rs
@@ -578,6 +578,8 @@ impl<'de, 'a> de::VariantAccess<'de> for Enum<'a, 'de> {
         self.de.bytes.skip_ws()?;
 
         if self.de.bytes.consume("(") {
+            self.de.bytes.skip_ws()?;
+
             let val = seed.deserialize(&mut *self.de)?;
 
             self.de.bytes.comma()?;


Test patch:
diff --git a/src/de/tests.rs b/src/de/tests.rs
index eac34a8e1..c07fe342d 100644
--- a/src/de/tests.rs
+++ b/src/de/tests.rs
@@ -258,3 +258,8 @@ fn implicit_some() {
     // Not concise
     assert_eq!(de::<Option<Option<char>>>("None"), None);
 }
+
+#[test]
+fn ws_tuple_newtype_variant() {
+    assert_eq!(Ok(MyEnum::B(true)), from_str("B  ( \n true \n ) "));
+}
diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs
index 399d573cf..e990c55cb 100644
--- a/tests/roundtrip.rs
+++ b/tests/roundtrip.rs
@@ -79,3 +79,51 @@ fn roundtrip_pretty() {
 
     assert_eq!(Ok(value), deserial);
 }
+
+#[test]
+fn roundtrip_sep_tuple_members() {
+    #[derive(Debug, Deserialize, PartialEq, Serialize)]
+    pub enum FileOrMem {
+        File(String),
+        Memory,
+    }
+
+    #[derive(Debug, Deserialize, PartialEq, Serialize)]
+    struct Both {
+        a: Struct,
+        b: FileOrMem,
+    }
+
+    let a = Struct {
+        tuple: ((), NewType(0.5), TupleStruct(UnitStruct, -5)),
+        vec: vec![None, Some(UnitStruct)],
+        map: vec![
+            (Key(5), Enum::Unit),
+            (Key(6), Enum::Bool(false)),
+            (Key(7), Enum::Bool(true)),
+            (Key(9), Enum::Chars('x', "".to_string())),
+        ].into_iter()
+            .collect(),
+    };
+    let b = FileOrMem::File("foo".to_owned());
+
+    let value = Both {
+        a,
+        b,
+    };
+
+    let pretty = ron::ser::PrettyConfig {
+        depth_limit: !0,
+        new_line: "\n".to_owned(),
+        indentor: "    ".to_owned(),
+        separate_tuple_members: true,
+        enumerate_arrays: false,
+    };
+    let serial = ron::ser::to_string_pretty(&value, pretty).unwrap();
+
+    println!("Serialized: {}", serial);
+
+    let deserial = ron::de::from_str(&serial);
+
+    assert_eq!(Ok(value), deserial);
+}