mirror of
				https://github.com/serde-rs/serde.git
				synced 2025-11-03 23:13:52 +00:00 
			
		
		
		
	Merge pull request #2733 from jamessan/nan-decimal
Only format Unexpected::Float with decimal point if it is finite
This commit is contained in:
		
						commit
						2d973c1805
					
				@ -2312,6 +2312,7 @@ impl Display for WithDecimalPoint {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if self.0.is_finite() {
 | 
			
		||||
            let mut writer = LookForDecimalPoint {
 | 
			
		||||
                formatter,
 | 
			
		||||
                has_decimal_point: false,
 | 
			
		||||
@ -2320,6 +2321,9 @@ impl Display for WithDecimalPoint {
 | 
			
		||||
            if !writer.has_decimal_point {
 | 
			
		||||
                tri!(formatter.write_str(".0"));
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            tri!(write!(formatter, "{}", self.0));
 | 
			
		||||
        }
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1438,6 +1438,14 @@ fn test_integer_from_float() {
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_nan_no_decimal_point() {
 | 
			
		||||
    assert_de_tokens_error::<isize>(
 | 
			
		||||
        &[Token::F32(f32::NAN)],
 | 
			
		||||
        "invalid type: floating point `NaN`, expected isize",
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_unit_struct_from_seq() {
 | 
			
		||||
    assert_de_tokens_error::<UnitStruct>(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user