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

Commit

Permalink
Unindent -> indoc in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 11, 2020
1 parent d24b924 commit f208925
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 208 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -17,8 +17,8 @@ serde = "1.0.60"
yaml-rust = "0.4"

[dev-dependencies]
indoc = "1.0"
serde_derive = "1.0"
unindent = "0.1"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
79 changes: 34 additions & 45 deletions tests/test_de.rs
@@ -1,9 +1,9 @@
use indoc::indoc;
use serde::serde_if_integer128;
use serde_derive::Deserialize;
use serde_yaml::Value;
use std::collections::BTreeMap;
use std::fmt::Debug;
use unindent::unindent;

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

#[test]
fn test_alias() {
let yaml = unindent(
"
let yaml = indoc! {"
---
first:
&alias
1
second:
*alias
third: 3",
);
third: 3
"};
let mut expected = BTreeMap::new();
{
expected.insert(String::from("first"), 1);
Expand All @@ -57,12 +56,11 @@ fn test_option() {
b: Option<String>,
c: Option<bool>,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
b:
c: true",
);
c: true
"};
let expected = Data {
a: None,
b: None,
Expand All @@ -82,8 +80,7 @@ fn test_option_alias() {
e: Option<String>,
f: Option<bool>,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
none_f:
&none_f
Expand All @@ -110,8 +107,8 @@ fn test_option_alias() {
c: *none_b
d: *some_f
e: *some_s
f: *some_b",
);
f: *some_b
"};
let expected = Data {
a: None,
b: None,
Expand All @@ -135,8 +132,7 @@ fn test_enum_alias() {
a: E,
b: E,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
aref:
&aref
Expand All @@ -148,8 +144,8 @@ fn test_enum_alias() {
- 2
a: *aref
b: *bref",
);
b: *bref
"};
let expected = Data {
a: E::A,
b: E::B(1, 2),
Expand All @@ -169,12 +165,11 @@ fn test_enum_tag() {
a: E,
b: E,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
a: !A foo
b: !B bar",
);
b: !B bar
"};
let expected = Data {
a: E::A("foo".into()),
b: E::B("bar".into()),
Expand All @@ -188,12 +183,11 @@ fn test_number_as_string() {
struct Num {
value: String,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
# Cannot be represented as u128
value: 340282366920938463463374607431768211457",
);
value: 340282366920938463463374607431768211457
"};
let expected = Num {
value: "340282366920938463463374607431768211457".to_owned(),
};
Expand All @@ -204,22 +198,20 @@ serde_if_integer128! {
#[test]
fn test_i128_big() {
let expected: i128 = ::std::i64::MIN as i128 - 1;
let yaml = unindent(
"
let yaml = indoc! {"
---
-9223372036854775809",
);
-9223372036854775809
"};
assert_eq!(expected, serde_yaml::from_str::<i128>(&yaml).unwrap());
}

#[test]
fn test_u128_big() {
let expected: u128 = ::std::u64::MAX as u128 + 1;
let yaml = unindent(
"
let yaml = indoc! {"
---
18446744073709551616",
);
18446744073709551616
"};
assert_eq!(expected, serde_yaml::from_str::<u128>(&yaml).unwrap());
}
}
Expand All @@ -231,12 +223,11 @@ fn test_number_alias_as_string() {
version: String,
value: String,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
version: &a 1.10
value: *a",
);
value: *a
"};
let expected = Num {
version: "1.10".to_owned(),
value: "1.10".to_owned(),
Expand All @@ -250,13 +241,12 @@ fn test_de_mapping() {
struct Data {
pub substructure: serde_yaml::Mapping,
}
let yaml = unindent(
"
let yaml = indoc! {"
---
substructure:
a: 'foo'
b: 'bar'",
);
b: 'bar'
"};

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

// This would deserialize an astronomical number of elements if we were
// vulnerable.
let yaml = unindent(
"
let yaml = indoc! {"
---
a: &a ~
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
Expand Down Expand Up @@ -311,8 +300,8 @@ fn test_bomb() {
x: &x [*w,*w,*w,*w,*w,*w,*w,*w,*w]
y: &y [*x,*x,*x,*x,*x,*x,*x,*x,*x]
z: &z [*y,*y,*y,*y,*y,*y,*y,*y,*y]
expected: string",
);
expected: string
"};

let expected = Data {
expected: "string".to_owned(),
Expand Down

0 comments on commit f208925

Please sign in to comment.