Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit f208925

Browse files
committed
Unindent -> indoc in test suite
1 parent d24b924 commit f208925

4 files changed

Lines changed: 158 additions & 208 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ serde = "1.0.60"
1717
yaml-rust = "0.4"
1818

1919
[dev-dependencies]
20+
indoc = "1.0"
2021
serde_derive = "1.0"
21-
unindent = "0.1"
2222

2323
[package.metadata.docs.rs]
2424
targets = ["x86_64-unknown-linux-gnu"]

‎tests/test_de.rs‎

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use indoc::indoc;
12
use serde::serde_if_integer128;
23
use serde_derive::Deserialize;
34
use serde_yaml::Value;
45
use std::collections::BTreeMap;
56
use std::fmt::Debug;
6-
use unindent::unindent;
77

88
fn test_de<T>(yaml: &str, expected: &T)
99
where
@@ -30,16 +30,15 @@ where
3030

3131
#[test]
3232
fn test_alias() {
33-
let yaml = unindent(
34-
"
33+
let yaml = indoc! {"
3534
---
3635
first:
3736
&alias
3837
1
3938
second:
4039
*alias
41-
third: 3",
42-
);
40+
third: 3
41+
"};
4342
let mut expected = BTreeMap::new();
4443
{
4544
expected.insert(String::from("first"), 1);
@@ -57,12 +56,11 @@ fn test_option() {
5756
b: Option<String>,
5857
c: Option<bool>,
5958
}
60-
let yaml = unindent(
61-
"
59+
let yaml = indoc! {"
6260
---
6361
b:
64-
c: true",
65-
);
62+
c: true
63+
"};
6664
let expected = Data {
6765
a: None,
6866
b: None,
@@ -82,8 +80,7 @@ fn test_option_alias() {
8280
e: Option<String>,
8381
f: Option<bool>,
8482
}
85-
let yaml = unindent(
86-
"
83+
let yaml = indoc! {"
8784
---
8885
none_f:
8986
&none_f
@@ -110,8 +107,8 @@ fn test_option_alias() {
110107
c: *none_b
111108
d: *some_f
112109
e: *some_s
113-
f: *some_b",
114-
);
110+
f: *some_b
111+
"};
115112
let expected = Data {
116113
a: None,
117114
b: None,
@@ -135,8 +132,7 @@ fn test_enum_alias() {
135132
a: E,
136133
b: E,
137134
}
138-
let yaml = unindent(
139-
"
135+
let yaml = indoc! {"
140136
---
141137
aref:
142138
&aref
@@ -148,8 +144,8 @@ fn test_enum_alias() {
148144
- 2
149145
150146
a: *aref
151-
b: *bref",
152-
);
147+
b: *bref
148+
"};
153149
let expected = Data {
154150
a: E::A,
155151
b: E::B(1, 2),
@@ -169,12 +165,11 @@ fn test_enum_tag() {
169165
a: E,
170166
b: E,
171167
}
172-
let yaml = unindent(
173-
"
168+
let yaml = indoc! {"
174169
---
175170
a: !A foo
176-
b: !B bar",
177-
);
171+
b: !B bar
172+
"};
178173
let expected = Data {
179174
a: E::A("foo".into()),
180175
b: E::B("bar".into()),
@@ -188,12 +183,11 @@ fn test_number_as_string() {
188183
struct Num {
189184
value: String,
190185
}
191-
let yaml = unindent(
192-
"
186+
let yaml = indoc! {"
193187
---
194188
# Cannot be represented as u128
195-
value: 340282366920938463463374607431768211457",
196-
);
189+
value: 340282366920938463463374607431768211457
190+
"};
197191
let expected = Num {
198192
value: "340282366920938463463374607431768211457".to_owned(),
199193
};
@@ -204,22 +198,20 @@ serde_if_integer128! {
204198
#[test]
205199
fn test_i128_big() {
206200
let expected: i128 = ::std::i64::MIN as i128 - 1;
207-
let yaml = unindent(
208-
"
201+
let yaml = indoc! {"
209202
---
210-
-9223372036854775809",
211-
);
203+
-9223372036854775809
204+
"};
212205
assert_eq!(expected, serde_yaml::from_str::<i128>(&yaml).unwrap());
213206
}
214207

215208
#[test]
216209
fn test_u128_big() {
217210
let expected: u128 = ::std::u64::MAX as u128 + 1;
218-
let yaml = unindent(
219-
"
211+
let yaml = indoc! {"
220212
---
221-
18446744073709551616",
222-
);
213+
18446744073709551616
214+
"};
223215
assert_eq!(expected, serde_yaml::from_str::<u128>(&yaml).unwrap());
224216
}
225217
}
@@ -231,12 +223,11 @@ fn test_number_alias_as_string() {
231223
version: String,
232224
value: String,
233225
}
234-
let yaml = unindent(
235-
"
226+
let yaml = indoc! {"
236227
---
237228
version: &a 1.10
238-
value: *a",
239-
);
229+
value: *a
230+
"};
240231
let expected = Num {
241232
version: "1.10".to_owned(),
242233
value: "1.10".to_owned(),
@@ -250,13 +241,12 @@ fn test_de_mapping() {
250241
struct Data {
251242
pub substructure: serde_yaml::Mapping,
252243
}
253-
let yaml = unindent(
254-
"
244+
let yaml = indoc! {"
255245
---
256246
substructure:
257247
a: 'foo'
258-
b: 'bar'",
259-
);
248+
b: 'bar'
249+
"};
260250

261251
let mut expected = Data {
262252
substructure: serde_yaml::Mapping::new(),
@@ -282,8 +272,7 @@ fn test_bomb() {
282272

283273
// This would deserialize an astronomical number of elements if we were
284274
// vulnerable.
285-
let yaml = unindent(
286-
"
275+
let yaml = indoc! {"
287276
---
288277
a: &a ~
289278
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
@@ -311,8 +300,8 @@ fn test_bomb() {
311300
x: &x [*w,*w,*w,*w,*w,*w,*w,*w,*w]
312301
y: &y [*x,*x,*x,*x,*x,*x,*x,*x,*x]
313302
z: &z [*y,*y,*y,*y,*y,*y,*y,*y,*y]
314-
expected: string",
315-
);
303+
expected: string
304+
"};
316305

317306
let expected = Data {
318307
expected: "string".to_owned(),

0 commit comments

Comments
 (0)