| 1 |
use super::Cursor; |
| 2 |
|
| 3 |
use rmp::decode::*; |
| 4 |
use rmp::Marker; |
| 5 |
|
| 6 |
#[test] |
| 7 |
fn from_f32_zero_plus() { |
| 8 |
let buf: &[u8] = &[0xca, 0x00, 0x00, 0x00, 0x00]; |
| 9 |
let mut cur = Cursor::new(buf); |
| 10 |
|
| 11 |
assert_eq!(0.0, read_f32(&mut cur).unwrap()); |
| 12 |
assert_eq!(5, cur.position()); |
| 13 |
} |
| 14 |
|
| 15 |
#[test] |
| 16 |
fn from_f32_max() { |
| 17 |
let buf: &[u8] = &[0xca, 0x7f, 0x7f, 0xff, 0xff]; |
| 18 |
let mut cur = Cursor::new(buf); |
| 19 |
|
| 20 |
assert_eq!(3.4028234e38_f32, read_f32(&mut cur).unwrap()); |
| 21 |
assert_eq!(5, cur.position()); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn from_f32_inf() { |
| 26 |
use std::f32; |
| 27 |
|
| 28 |
let buf: &[u8] = &[0xca, 0x7f, 0x80, 0x00, 0x00]; |
| 29 |
let mut cur = Cursor::new(buf); |
| 30 |
|
| 31 |
assert_eq!(f32::INFINITY, read_f32(&mut cur).unwrap()); |
| 32 |
assert_eq!(5, cur.position()); |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn from_f32_neg_inf() { |
| 37 |
use std::f32; |
| 38 |
|
| 39 |
let buf: &[u8] = &[0xca, 0xff, 0x80, 0x00, 0x00]; |
| 40 |
let mut cur = Cursor::new(buf); |
| 41 |
|
| 42 |
assert_eq!(f32::NEG_INFINITY, read_f32(&mut cur).unwrap()); |
| 43 |
assert_eq!(5, cur.position()); |
| 44 |
} |
| 45 |
|
| 46 |
#[test] |
| 47 |
fn from_null_read_f32() { |
| 48 |
let buf: &[u8] = &[0xc0]; |
| 49 |
let mut cur = Cursor::new(buf); |
| 50 |
|
| 51 |
match read_f32(&mut cur) { |
| 52 |
Err(ValueReadError::TypeMismatch(Marker::Null)) => (), |
| 53 |
other => panic!("unexpected result: {other:?}"), |
| 54 |
} |
| 55 |
assert_eq!(1, cur.position()); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn from_f64_zero_plus() { |
| 60 |
let buf: &[u8] = &[0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 61 |
let mut cur = Cursor::new(buf); |
| 62 |
|
| 63 |
assert_eq!(0.0, read_f64(&mut cur).unwrap()); |
| 64 |
assert_eq!(9, cur.position()); |
| 65 |
} |
| 66 |
|
| 67 |
#[test] |
| 68 |
fn from_f64_zero_minus() { |
| 69 |
let buf: &[u8] = &[0xcb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 70 |
let mut cur = Cursor::new(buf); |
| 71 |
|
| 72 |
assert_eq!(-0.0, read_f64(&mut cur).unwrap()); |
| 73 |
assert_eq!(9, cur.position()); |
| 74 |
} |
| 75 |
|
| 76 |
#[test] |
| 77 |
fn from_f64_inf() { |
| 78 |
use std::f64; |
| 79 |
|
| 80 |
let buf: &[u8] = &[0xcb, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 81 |
let mut cur = Cursor::new(buf); |
| 82 |
|
| 83 |
assert_eq!(f64::INFINITY, read_f64(&mut cur).unwrap()); |
| 84 |
assert_eq!(9, cur.position()); |
| 85 |
} |
| 86 |
|
| 87 |
#[test] |
| 88 |
fn from_f64_neg_inf() { |
| 89 |
use std::f64; |
| 90 |
|
| 91 |
let buf: &[u8] = &[0xcb, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 92 |
let mut cur = Cursor::new(buf); |
| 93 |
|
| 94 |
assert_eq!(f64::NEG_INFINITY, read_f64(&mut cur).unwrap()); |
| 95 |
assert_eq!(9, cur.position()); |
| 96 |
} |
| 97 |
|
| 98 |
#[test] |
| 99 |
fn from_null_read_f64() { |
| 100 |
let buf: &[u8] = &[0xc0]; |
| 101 |
let mut cur = Cursor::new(buf); |
| 102 |
|
| 103 |
match read_f64(&mut cur) { |
| 104 |
Err(ValueReadError::TypeMismatch(Marker::Null)) => (), |
| 105 |
other => panic!("unexpected result: {other:?}"), |
| 106 |
} |
| 107 |
assert_eq!(1, cur.position()); |
| 108 |
} |