Skip to content

Commit

Permalink
refactor: Resolve deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 27, 2024
1 parent ec270f8 commit b62c76e
Show file tree
Hide file tree
Showing 12 changed files with 1,383 additions and 1,674 deletions.
274 changes: 139 additions & 135 deletions crates/toml/tests/testsuite/de_errors.rs

Large diffs are not rendered by default.

101 changes: 43 additions & 58 deletions crates/toml/tests/testsuite/enum_external_deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use serde::Deserialize;
use snapbox::assert_data_eq;
use snapbox::prelude::*;
use snapbox::str;

#[derive(Debug, Deserialize, PartialEq)]
struct OuterStruct {
Expand Down Expand Up @@ -33,90 +36,72 @@ where
#[test]
fn invalid_variant_returns_error_with_good_message_string() {
let error = value_from_str::<TheEnum>("\"NonExistent\"").unwrap_err();
snapbox::assert_eq(
r#"unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#]].raw());

let error = toml::from_str::<Val>("val = \"NonExistent\"").unwrap_err();
snapbox::assert_eq(
r#"TOML parse error at line 1, column 7
|
1 | val = "NonExistent"
| ^^^^^^^^^^^^^
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
TOML parse error at line 1, column 7
|
1 | val = "NonExistent"
| ^^^^^^^^^^^^^
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#]].raw());
}

#[test]
fn invalid_variant_returns_error_with_good_message_inline_table() {
let error = value_from_str::<TheEnum>("{ NonExistent = {} }").unwrap_err();
snapbox::assert_eq(
r#"unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#]].raw());

let error = toml::from_str::<Val>("val = { NonExistent = {} }").unwrap_err();
snapbox::assert_eq(
r#"TOML parse error at line 1, column 9
|
1 | val = { NonExistent = {} }
| ^^^^^^^^^^^
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
TOML parse error at line 1, column 9
|
1 | val = { NonExistent = {} }
| ^^^^^^^^^^^
unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`
"#]].raw());
}

#[test]
fn extra_field_returns_expected_empty_table_error() {
let error = value_from_str::<TheEnum>("{ Plain = { extra_field = 404 } }").unwrap_err();
snapbox::assert_eq(
r#"expected empty table
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
expected empty table
"#]].raw());

let error = toml::from_str::<Val>("val = { Plain = { extra_field = 404 } }").unwrap_err();
snapbox::assert_eq(
r#"TOML parse error at line 1, column 17
|
1 | val = { Plain = { extra_field = 404 } }
| ^^^^^^^^^^^^^^^^^^^^^
expected empty table
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
TOML parse error at line 1, column 17
|
1 | val = { Plain = { extra_field = 404 } }
| ^^^^^^^^^^^^^^^^^^^^^
expected empty table
"#]].raw());
}

#[test]
fn extra_field_returns_expected_empty_table_error_struct_variant() {
let error = value_from_str::<TheEnum>("{ Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }")
.unwrap_err();

snapbox::assert_eq(
r#"unexpected keys in table: extra_0, extra_1, available keys: value
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
unexpected keys in table: extra_0, extra_1, available keys: value
"#]].raw());

let error =
toml::from_str::<Val>("val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }")
.unwrap_err();

snapbox::assert_eq(
r#"TOML parse error at line 1, column 33
|
1 | val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }
| ^^^^^^^
unexpected keys in table: extra_0, extra_1, available keys: value
"#,
error.to_string(),
);
assert_data_eq!(error.to_string(), str![[r#"
TOML parse error at line 1, column 33
|
1 | val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }
| ^^^^^^^
unexpected keys in table: extra_0, extra_1, available keys: value
"#]].raw());
}

mod enum_unit {
Expand Down
17 changes: 9 additions & 8 deletions crates/toml/tests/testsuite/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::ser::Serialize;
use snapbox::assert_eq;
use snapbox::assert_data_eq;
use snapbox::prelude::*;

const NO_PRETTY: &str = "\
[example]
Expand All @@ -18,7 +19,7 @@ fn no_pretty() {
let value: toml::Value = toml::from_str(toml).unwrap();
let mut result = String::with_capacity(128);
value.serialize(toml::Serializer::new(&mut result)).unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

const PRETTY_STD: &str = "\
Expand All @@ -44,7 +45,7 @@ fn pretty_std() {
value
.serialize(toml::Serializer::pretty(&mut result))
.unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

const PRETTY_TRICKY: &str = r#"[example]
Expand Down Expand Up @@ -82,7 +83,7 @@ fn pretty_tricky() {
value
.serialize(toml::Serializer::pretty(&mut result))
.unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

const PRETTY_TABLE_ARRAY: &str = r#"[[array]]
Expand All @@ -106,7 +107,7 @@ fn pretty_table_array() {
value
.serialize(toml::Serializer::pretty(&mut result))
.unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

const TABLE_ARRAY: &str = r#"[[array]]
Expand All @@ -128,7 +129,7 @@ fn table_array() {
let value: toml::Value = toml::from_str(toml).unwrap();
let mut result = String::with_capacity(128);
value.serialize(toml::Serializer::new(&mut result)).unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

const PRETTY_EMPTY_TABLE: &str = r#"[example]
Expand All @@ -140,7 +141,7 @@ fn pretty_empty_table() {
let value: toml::Value = toml::from_str(toml).unwrap();
let mut result = String::with_capacity(128);
value.serialize(toml::Serializer::new(&mut result)).unwrap();
assert_eq(toml, &result);
assert_data_eq!(&result, toml.raw());
}

#[test]
Expand Down Expand Up @@ -180,5 +181,5 @@ debug = true

let pkg: Package = toml::from_str(raw).unwrap();
let pretty = toml::to_string_pretty(&pkg).unwrap();
assert_eq(raw, pretty);
assert_data_eq!(pretty, raw.raw());
}
Loading

0 comments on commit b62c76e

Please sign in to comment.