Lines
100 %
Functions
50 %
Branches
use ron::error::{Error, Position, SpannedError};
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct MyUnitStruct;
struct MyTupleStruct(bool, i32);
struct MyNewtypeStruct(MyTupleStruct);
struct MyStruct {
a: bool,
b: i32,
}
#[test]
fn test_unit_struct_name_mismatch() {
assert_eq!(ron::from_str::<MyUnitStruct>("()"), Ok(MyUnitStruct),);
assert_eq!(
ron::from_str::<MyUnitStruct>("MyUnitStruct"),
Ok(MyUnitStruct),
);
ron::from_str::<MyUnitStruct>("MyUnit Struct"),
Err(SpannedError {
code: Error::ExpectedDifferentStructName {
expected: "MyUnitStruct",
found: String::from("MyUnit")
},
position: Position { line: 1, col: 7 }
}),
ron::from_str::<MyUnitStruct>("42"),
code: Error::ExpectedNamedStructLike("MyUnitStruct"),
position: Position { line: 1, col: 1 }
fn test_tuple_struct_name_mismatch() {
ron::from_str::<MyTupleStruct>("(true, 42)"),
Ok(MyTupleStruct(true, 42)),
ron::from_str::<MyTupleStruct>("MyTupleStruct(true, 42)"),
ron::from_str::<MyTupleStruct>("MyTypleStruct(true, 42)"),
expected: "MyTupleStruct",
found: String::from("MyTypleStruct")
position: Position { line: 1, col: 14 }
ron::from_str::<MyTupleStruct>("42"),
code: Error::ExpectedNamedStructLike("MyTupleStruct"),
fn test_newtype_struct_name_mismatch() {
ron::from_str::<MyNewtypeStruct>("((true, 42))"),
Ok(MyNewtypeStruct(MyTupleStruct(true, 42))),
ron::from_str::<MyNewtypeStruct>("MyNewtypeStruct((true, 42))"),
ron::from_str::<MyNewtypeStruct>("MyNewtypeStrucl((true, 42))"),
expected: "MyNewtypeStruct",
found: String::from("MyNewtypeStrucl")
position: Position { line: 1, col: 16 }
ron::from_str::<MyNewtypeStruct>("42"),
code: Error::ExpectedNamedStructLike("MyNewtypeStruct"),
fn test_struct_name_mismatch() {
ron::from_str::<MyStruct>("(a: true, b: 42)"),
Ok(MyStruct { a: true, b: 42 }),
ron::from_str::<MyStruct>("MyStruct(a: true, b: 42)"),
ron::from_str::<MyStruct>("MuStryct(a: true, b: 42)"),
expected: "MyStruct",
found: String::from("MuStryct")
position: Position { line: 1, col: 9 }
ron::from_str::<MyStruct>("42"),
code: Error::ExpectedNamedStructLike("MyStruct"),