@@ -14,13 +14,13 @@ mod tests {
14
14
15
15
#[ test]
16
16
fn deserialize_int ( ) {
17
- assert_eq ! ( from_json_str :: < Int > ( " 100" ) . unwrap( ) , int!( 100 ) ) ;
18
- assert_eq ! ( from_json_str :: < Int > ( "0" ) . unwrap( ) , int!( 0 ) ) ;
19
- assert_eq ! ( from_json_str :: < Int > ( " -100" ) . unwrap( ) , int!( -100 ) ) ;
20
- assert_eq ! ( from_json_str :: < Int > ( "-9007199254740991" ) . unwrap( ) , Int :: MIN ) ;
21
- assert_eq ! ( from_json_str :: < Int > ( "9007199254740991" ) . unwrap( ) , Int :: MAX ) ;
22
- assert ! ( from_json_str :: < Int > ( "9007199254740992" ) . is_err( ) ) ;
23
- assert ! ( from_json_str :: < Int > ( "-9007199254740992" ) . is_err( ) ) ;
17
+ assert_eq ! ( deserialize_int_from ( 100 ) . unwrap( ) , int!( 100 ) ) ;
18
+ assert_eq ! ( deserialize_int_from ( 0 ) . unwrap( ) , int!( 0 ) ) ;
19
+ assert_eq ! ( deserialize_int_from ( -100 ) . unwrap( ) , int!( -100 ) ) ;
20
+ assert_eq ! ( deserialize_int_from ( - 9007199254740991i64 ) . unwrap( ) , Int :: MIN ) ;
21
+ assert_eq ! ( deserialize_int_from ( 9007199254740991i64 ) . unwrap( ) , Int :: MAX ) ;
22
+ assert ! ( deserialize_int_from ( 9007199254740992i64 ) . is_err( ) ) ;
23
+ assert ! ( deserialize_int_from ( - 9007199254740992i64 ) . is_err( ) ) ;
24
24
}
25
25
26
26
#[ test]
@@ -31,44 +31,44 @@ mod tests {
31
31
32
32
#[ test]
33
33
fn deserialize_uint ( ) {
34
- assert_eq ! ( from_json_str :: < UInt > ( " 100" ) . unwrap( ) , uint!( 100 ) ) ;
35
- assert_eq ! ( from_json_str :: < UInt > ( "0" ) . unwrap( ) , uint!( 0 ) ) ;
36
- assert_eq ! ( from_json_str :: < UInt > ( "9007199254740991" ) . unwrap( ) , UInt :: MAX ) ;
37
- assert ! ( from_json_str :: < UInt > ( "9007199254740992" ) . is_err( ) ) ;
34
+ assert_eq ! ( deserialize_uint_from ( 100 ) . unwrap( ) , uint!( 100 ) ) ;
35
+ assert_eq ! ( deserialize_uint_from ( 0 ) . unwrap( ) , uint!( 0 ) ) ;
36
+ assert_eq ! ( deserialize_uint_from ( 9007199254740991i64 ) . unwrap( ) , UInt :: MAX ) ;
37
+ assert ! ( deserialize_uint_from ( 9007199254740992i64 ) . is_err( ) ) ;
38
38
}
39
39
40
40
#[ test]
41
41
#[ cfg_attr( feature = "lax_deserialize" , ignore) ]
42
42
fn strict_deserialize_int ( ) {
43
- assert ! ( from_json_str :: < Int > ( " -10.0" ) . is_err( ) ) ;
44
- assert ! ( from_json_str :: < Int > ( " -0.0" ) . is_err( ) ) ;
45
- assert ! ( from_json_str :: < Int > ( " 0.5" ) . is_err( ) ) ;
46
- assert ! ( from_json_str :: < Int > ( " 1.0" ) . is_err( ) ) ;
47
- assert ! ( from_json_str :: < Int > ( " 9007199254740991.0" ) . is_err( ) ) ;
48
- assert ! ( from_json_str :: < Int > ( " 9007199254740991.49" ) . is_err( ) ) ;
49
- assert ! ( from_json_str :: < Int > ( " 9007199254740992.0" ) . is_err( ) ) ;
43
+ assert ! ( deserialize_int_from ( -10.0 ) . is_err( ) ) ;
44
+ assert ! ( deserialize_int_from ( -0.0 ) . is_err( ) ) ;
45
+ assert ! ( deserialize_int_from ( 0.5 ) . is_err( ) ) ;
46
+ assert ! ( deserialize_int_from ( 1.0 ) . is_err( ) ) ;
47
+ assert ! ( deserialize_int_from ( 9007199254740991.0 ) . is_err( ) ) ;
48
+ assert ! ( deserialize_int_from ( 9007199254740991.49 ) . is_err( ) ) ;
49
+ assert ! ( deserialize_int_from ( 9007199254740992.0 ) . is_err( ) ) ;
50
50
}
51
51
52
52
#[ test]
53
53
#[ cfg_attr( feature = "lax_deserialize" , ignore) ]
54
54
fn strict_deserialize_uint ( ) {
55
- assert ! ( from_json_str :: < UInt > ( " 0.5" ) . is_err( ) ) ;
56
- assert ! ( from_json_str :: < UInt > ( " 1.0" ) . is_err( ) ) ;
57
- assert ! ( from_json_str :: < UInt > ( " 9007199254740991.0" ) . is_err( ) ) ;
58
- assert ! ( from_json_str :: < UInt > ( " 9007199254740991.49" ) . is_err( ) ) ;
59
- assert ! ( from_json_str :: < UInt > ( " 9007199254740992.0" ) . is_err( ) ) ;
55
+ assert ! ( deserialize_uint_from ( 0.5 ) . is_err( ) ) ;
56
+ assert ! ( deserialize_uint_from ( 1.0 ) . is_err( ) ) ;
57
+ assert ! ( deserialize_uint_from ( 9007199254740991.0 ) . is_err( ) ) ;
58
+ assert ! ( deserialize_uint_from ( 9007199254740991.49 ) . is_err( ) ) ;
59
+ assert ! ( deserialize_uint_from ( 9007199254740992.0 ) . is_err( ) ) ;
60
60
}
61
61
62
62
#[ test]
63
63
#[ cfg_attr( not( feature = "lax_deserialize" ) , ignore) ]
64
64
fn lax_deserialize_int ( ) {
65
- assert_eq ! ( from_json_str :: < Int > ( " -10.0" ) . unwrap( ) , int!( -10 ) ) ;
66
- assert_eq ! ( from_json_str :: < Int > ( " -0.0" ) . unwrap( ) , int!( 0 ) ) ;
67
- assert_eq ! ( from_json_str :: < Int > ( " 0.5" ) . unwrap( ) , int!( 0 ) ) ;
68
- assert_eq ! ( from_json_str :: < Int > ( " 1.0" ) . unwrap( ) , int!( 1 ) ) ;
69
- assert_eq ! ( from_json_str :: < Int > ( " 9007199254740991.0" ) . unwrap( ) , Int :: MAX ) ;
70
- assert_eq ! ( from_json_str :: < Int > ( " 9007199254740991.49" ) . unwrap( ) , Int :: MAX ) ;
71
- assert ! ( from_json_str :: < Int > ( " 9007199254740992.0" ) . is_err( ) ) ;
65
+ assert_eq ! ( deserialize_int_from ( -10.0 ) . unwrap( ) , int!( -10 ) ) ;
66
+ assert_eq ! ( deserialize_int_from ( -0.0 ) . unwrap( ) , int!( 0 ) ) ;
67
+ assert_eq ! ( deserialize_int_from ( 0.5 ) . unwrap( ) , int!( 0 ) ) ;
68
+ assert_eq ! ( deserialize_int_from ( 1.0 ) . unwrap( ) , int!( 1 ) ) ;
69
+ assert_eq ! ( deserialize_int_from ( 9007199254740991.0 ) . unwrap( ) , Int :: MAX ) ;
70
+ assert_eq ! ( deserialize_int_from ( 9007199254740991.49 ) . unwrap( ) , Int :: MAX ) ;
71
+ assert ! ( deserialize_int_from ( 9007199254740992.0 ) . is_err( ) ) ;
72
72
73
73
assert ! ( deserialize_int_from( f64 :: NAN ) . is_err( ) ) ;
74
74
assert ! ( deserialize_int_from( f64 :: INFINITY ) . is_err( ) ) ;
@@ -78,11 +78,11 @@ mod tests {
78
78
#[ test]
79
79
#[ cfg_attr( not( feature = "lax_deserialize" ) , ignore) ]
80
80
fn lax_deserialize_uint ( ) {
81
- assert_eq ! ( from_json_str :: < UInt > ( " 0.5" ) . unwrap( ) , uint!( 0 ) ) ;
82
- assert_eq ! ( from_json_str :: < UInt > ( " 1.0" ) . unwrap( ) , uint!( 1 ) ) ;
83
- assert_eq ! ( from_json_str :: < UInt > ( " 9007199254740991.0" ) . unwrap( ) , UInt :: MAX ) ;
84
- assert_eq ! ( from_json_str :: < UInt > ( " 9007199254740991.49" ) . unwrap( ) , UInt :: MAX ) ;
85
- assert ! ( from_json_str :: < UInt > ( " 9007199254740992.0" ) . is_err( ) ) ;
81
+ assert_eq ! ( deserialize_uint_from ( 0.5 ) . unwrap( ) , uint!( 0 ) ) ;
82
+ assert_eq ! ( deserialize_uint_from ( 1.0 ) . unwrap( ) , uint!( 1 ) ) ;
83
+ assert_eq ! ( deserialize_uint_from ( 9007199254740991.0 ) . unwrap( ) , UInt :: MAX ) ;
84
+ assert_eq ! ( deserialize_uint_from ( 9007199254740991.49 ) . unwrap( ) , UInt :: MAX ) ;
85
+ assert ! ( deserialize_uint_from ( 9007199254740992.0 ) . is_err( ) ) ;
86
86
87
87
assert ! ( deserialize_uint_from( f64 :: NAN ) . is_err( ) ) ;
88
88
assert ! ( deserialize_uint_from( f64 :: INFINITY ) . is_err( ) ) ;
0 commit comments