Skip to content

Commit

Permalink
Fix tests with serde >= 1.0.196
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamessan committed May 2, 2024
1 parent 71d3099 commit 1e4481c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions serde_with/tests/chrono_0_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ fn test_chrono_timestamp_seconds() {
]],
);
check_error_deserialization::<StructStringStrict>(
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"#
]],
);

Expand Down Expand Up @@ -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::<StructStringStrict>(
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]
Expand Down
8 changes: 4 additions & 4 deletions serde_with/tests/serde_as/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ fn test_timestamp_seconds_systemtime() {
]],
);
check_error_deserialization::<StructStringStrict>(
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"#
]],
);

Expand Down Expand Up @@ -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::<StructStringStrict>(
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]
Expand Down

0 comments on commit 1e4481c

Please sign in to comment.