From 1e4481c42198ddf09dd8d9bf5b6501c3859f3b94 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 2 May 2024 15:55:57 -0400 Subject: [PATCH] Fix tests with serde >= 1.0.196 In serde 1.0.196, the "invalid type" error message for floats started adding a trailing ".0" if no decimal point was already part of the formatted float, causing tests to fail like: ---- test_chrono_timestamp_seconds_with_frac stdout ---- error: expect test failed --> serde_with/tests/chrono_0_4.rs:551:9 Expect: ---- invalid type: floating point `0`, expected a string at line 1 column 3 ---- Actual: ---- invalid type: floating point `0.0`, expected a string at line 1 column 3 ---- Change the tests to use a test value of 0.1, so the test will work both pre- and post-serde 1.0.196. --- serde_with/tests/chrono_0_4.rs | 8 ++++---- serde_with/tests/serde_as/time.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/serde_with/tests/chrono_0_4.rs b/serde_with/tests/chrono_0_4.rs index f18a29b6..f1c5ee40 100644 --- a/serde_with/tests/chrono_0_4.rs +++ b/serde_with/tests/chrono_0_4.rs @@ -456,9 +456,9 @@ fn test_chrono_timestamp_seconds() { ]], ); check_error_deserialization::( - r#"0.0"#, + r#"0.1"#, expect![[ - r#"invalid type: floating point `0`, expected a string containing a number at line 1 column 3"# + r#"invalid type: floating point `0.1`, expected a string containing a number at line 1 column 3"# ]], ); @@ -547,8 +547,8 @@ fn test_chrono_timestamp_seconds_with_frac() { expect![[r#"invalid type: integer `1`, expected a string at line 1 column 1"#]], ); check_error_deserialization::( - r#"0.0"#, - expect![[r#"invalid type: floating point `0`, expected a string at line 1 column 3"#]], + r#"0.1"#, + expect![[r#"invalid type: floating point `0.1`, expected a string at line 1 column 3"#]], ); #[serde_as] diff --git a/serde_with/tests/serde_as/time.rs b/serde_with/tests/serde_as/time.rs index 91808b4d..f33ea0f7 100644 --- a/serde_with/tests/serde_as/time.rs +++ b/serde_with/tests/serde_as/time.rs @@ -324,9 +324,9 @@ fn test_timestamp_seconds_systemtime() { ]], ); check_error_deserialization::( - r#"0.0"#, + r#"0.1"#, expect![[ - r#"invalid type: floating point `0`, expected a string containing a number at line 1 column 3"# + r#"invalid type: floating point `0.1`, expected a string containing a number at line 1 column 3"# ]], ); @@ -423,8 +423,8 @@ fn test_timestamp_seconds_with_frac_systemtime() { expect![[r#"invalid type: integer `1`, expected a string at line 1 column 1"#]], ); check_error_deserialization::( - r#"0.0"#, - expect![[r#"invalid type: floating point `0`, expected a string at line 1 column 3"#]], + r#"0.1"#, + expect![[r#"invalid type: floating point `0.1`, expected a string at line 1 column 3"#]], ); #[serde_as]