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
|
#[test]
#[cfg(feature = "write-integers")]
fn integer_to_string_test() {
let mut buffer = [b'0'; lexical_core::BUFFER_SIZE];
assert_eq!(lexical_core::write(12345u32, &mut buffer), b"12345");
let options = lexical_core::WriteIntegerOptions::new();
const FORMAT: u128 = lexical_core::format::STANDARD;
assert_eq!(
lexical_core::write_with_options::<_, FORMAT>(12345u32, &mut buffer, &options),
b"12345"
);
}
#[test]
#[cfg(feature = "write-floats")]
fn float_to_string_test() {
let mut buffer = [b'0'; lexical_core::BUFFER_SIZE];
assert_eq!(lexical_core::write(12345.0f32, &mut buffer), b"12345.0");
let options = lexical_core::WriteFloatOptions::new();
const FORMAT: u128 = lexical_core::format::STANDARD;
assert_eq!(
lexical_core::write_with_options::<_, FORMAT>(12345.0f32, &mut buffer, &options),
b"12345.0"
);
}
#[test]
#[cfg(feature = "parse-integers")]
fn string_to_integer_test() {
assert_eq!(lexical_core::parse(b"12345"), Ok(12345u32));
assert_eq!(lexical_core::parse_partial(b"12345"), Ok((12345u32, 5)));
let options = lexical_core::ParseIntegerOptions::new();
const FORMAT: u128 = lexical_core::format::STANDARD;
assert_eq!(lexical_core::parse_with_options::<_, FORMAT>(b"12345", &options), Ok(12345u32));
assert_eq!(
lexical_core::parse_partial_with_options::<_, FORMAT>(b"12345", &options),
Ok((12345u32, 5))
);
}
#[test]
#[cfg(feature = "parse-floats")]
fn string_to_float_test() {
assert_eq!(lexical_core::parse(b"12345.0"), Ok(12345.0f32));
assert_eq!(lexical_core::parse_partial(b"12345.0"), Ok((12345.0f32, 7)));
let options = lexical_core::ParseFloatOptions::new();
const FORMAT: u128 = lexical_core::format::STANDARD;
assert_eq!(lexical_core::parse_with_options::<_, FORMAT>(b"12345.0", &options), Ok(12345.0f32));
assert_eq!(
lexical_core::parse_partial_with_options::<_, FORMAT>(b"12345.0", &options),
Ok((12345.0f32, 7))
);
}
|