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