Skip to content

Commit

Permalink
Experimentation with ron-rs#253 and ron-rs#357
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Jan 5, 2022
1 parent d45c2e8 commit a5158d9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
33 changes: 20 additions & 13 deletions src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,27 @@ mod tests {
),
Value::Option(Some(Box::new(Value::Seq(vec![
Value::Map(
vec![
(
Value::String("width".to_owned()),
Value::Number(Number::new(20)),
),
(
Value::String("height".to_owned()),
Value::Number(Number::new(5)),
vec![(
Value::String("Room".to_owned()),
Value::Map(
vec![
(
Value::String("width".to_owned()),
Value::Number(Number::new(20)),
),
(
Value::String("height".to_owned()),
Value::Number(Number::new(5)),
),
(
Value::String("name".to_owned()),
Value::String("The Room".to_owned()),
),
]
.into_iter()
.collect(),
),
(
Value::String("name".to_owned()),
Value::String("The Room".to_owned()),
),
]
)]
.into_iter()
.collect(),
),
Expand Down
2 changes: 1 addition & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> Bytes<'a> {
}

Ok(num_acc)
};
}

let res = if sign > 0 {
calc_num(&*self, s, base, T::checked_add_ext)
Expand Down
2 changes: 1 addition & 1 deletion tests/117_untagged_tuple_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn test_ebkalderon_case() {
flags: [
"--enable-thing",
"--enable-other-thing",
If("some-conditional", ["--enable-third-thing"]),
("some-conditional", ["--enable-third-thing"]),
]
)
"#;
Expand Down
30 changes: 30 additions & 0 deletions tests/357_untagged_roundtrip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
enum MyValue {
Int(i64),
String(String),
Enum(Enum),
List(Vec<MyValue>),
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
enum Enum {
First(String),
Second(i64),
}

#[test]
fn test() {
let value = MyValue::Enum(Enum::First(String::from("foo")));

let serialized = ron::to_string(&value).unwrap();
assert_eq!(serialized, r#"First("foo")"#);

let inner_deserialized: Enum = ron::from_str(&serialized).unwrap();
assert_eq!(inner_deserialized, Enum::First(String::from("foo")));

let deserialized: MyValue = ron::from_str(&serialized).unwrap();
assert_eq!(deserialized, value);
}
2 changes: 1 addition & 1 deletion tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn unit() {
use ron::error::{Error, ErrorCode, Position};

assert_eq!("()".parse(), Ok(Value::Unit));
assert_eq!("Foo".parse(), Ok(Value::Unit));
assert_eq!("Foo".parse(), Ok(Value::String(String::from("Foo"))));

assert_eq!(
"".parse::<Value>(),
Expand Down

0 comments on commit a5158d9

Please sign in to comment.