-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy path301_struct_name_mismatch.rs
130 lines (122 loc) · 3.69 KB
/
301_struct_name_mismatch.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use ron::error::{Error, Position, SpannedError};
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct MyUnitStruct;
#[derive(Debug, Deserialize, PartialEq)]
struct MyTupleStruct(bool, i32);
#[derive(Debug, Deserialize, PartialEq)]
struct MyNewtypeStruct(MyTupleStruct);
#[derive(Debug, Deserialize, PartialEq)]
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),
);
assert_eq!(
ron::from_str::<MyUnitStruct>("MyUnit Struct"),
Err(SpannedError {
code: Error::ExpectedDifferentStructName {
expected: "MyUnitStruct",
found: String::from("MyUnit")
},
position: Position { line: 1, col: 7 }
}),
);
assert_eq!(
ron::from_str::<MyUnitStruct>("42"),
Err(SpannedError {
code: Error::ExpectedNamedStructLike("MyUnitStruct"),
position: Position { line: 1, col: 1 }
}),
);
}
#[test]
fn test_tuple_struct_name_mismatch() {
assert_eq!(
ron::from_str::<MyTupleStruct>("(true, 42)"),
Ok(MyTupleStruct(true, 42)),
);
assert_eq!(
ron::from_str::<MyTupleStruct>("MyTupleStruct(true, 42)"),
Ok(MyTupleStruct(true, 42)),
);
assert_eq!(
ron::from_str::<MyTupleStruct>("MyTypleStruct(true, 42)"),
Err(SpannedError {
code: Error::ExpectedDifferentStructName {
expected: "MyTupleStruct",
found: String::from("MyTypleStruct")
},
position: Position { line: 1, col: 14 }
}),
);
assert_eq!(
ron::from_str::<MyTupleStruct>("42"),
Err(SpannedError {
code: Error::ExpectedNamedStructLike("MyTupleStruct"),
position: Position { line: 1, col: 1 }
}),
);
}
#[test]
fn test_newtype_struct_name_mismatch() {
assert_eq!(
ron::from_str::<MyNewtypeStruct>("((true, 42))"),
Ok(MyNewtypeStruct(MyTupleStruct(true, 42))),
);
assert_eq!(
ron::from_str::<MyNewtypeStruct>("MyNewtypeStruct((true, 42))"),
Ok(MyNewtypeStruct(MyTupleStruct(true, 42))),
);
assert_eq!(
ron::from_str::<MyNewtypeStruct>("MyNewtypeStrucl((true, 42))"),
Err(SpannedError {
code: Error::ExpectedDifferentStructName {
expected: "MyNewtypeStruct",
found: String::from("MyNewtypeStrucl")
},
position: Position { line: 1, col: 16 }
}),
);
assert_eq!(
ron::from_str::<MyNewtypeStruct>("42"),
Err(SpannedError {
code: Error::ExpectedNamedStructLike("MyNewtypeStruct"),
position: Position { line: 1, col: 1 }
}),
);
}
#[test]
fn test_struct_name_mismatch() {
assert_eq!(
ron::from_str::<MyStruct>("(a: true, b: 42)"),
Ok(MyStruct { a: true, b: 42 }),
);
assert_eq!(
ron::from_str::<MyStruct>("MyStruct(a: true, b: 42)"),
Ok(MyStruct { a: true, b: 42 }),
);
assert_eq!(
ron::from_str::<MyStruct>("MuStryct(a: true, b: 42)"),
Err(SpannedError {
code: Error::ExpectedDifferentStructName {
expected: "MyStruct",
found: String::from("MuStryct")
},
position: Position { line: 1, col: 9 }
}),
);
assert_eq!(
ron::from_str::<MyStruct>("42"),
Err(SpannedError {
code: Error::ExpectedNamedStructLike("MyStruct"),
position: Position { line: 1, col: 1 }
}),
);
}