diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/dtoa/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/dtoa/tests')
-rw-r--r-- | third_party/rust/dtoa/tests/test.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/third_party/rust/dtoa/tests/test.rs b/third_party/rust/dtoa/tests/test.rs new file mode 100644 index 0000000000..4f92d7ee13 --- /dev/null +++ b/third_party/rust/dtoa/tests/test.rs @@ -0,0 +1,38 @@ +extern crate dtoa; + +use std::str; + +#[test] +fn test_f64() { + test_write(1.234e20f64, "123400000000000000000.0"); + test_write(1.234e21f64, "1.234e21"); + test_write(2.71828f64, "2.71828"); + test_write(0.0f64, "0.0"); + test_write(-0.0f64, "-0.0"); + test_write(1.1e128f64, "1.1e128"); + test_write(1.1e-64f64, "1.1e-64"); + test_write(2.718281828459045f64, "2.718281828459045"); + test_write(5e-324f64, "5e-324"); + test_write(::std::f64::MAX, "1.7976931348623157e308"); +} + +#[test] +fn test_f32() { + test_write(1.234e20f32, "123400000000000000000.0"); + test_write(1.234e21f32, "1.234e21"); + test_write(2.71828f32, "2.71828"); + test_write(0.0f32, "0.0"); + test_write(-0.0f32, "-0.0"); + test_write(1.1e32f32, "1.1e32"); + test_write(1.1e-32f32, "1.1e-32"); + test_write(2.7182817f32, "2.7182817"); + test_write(1e-45f32, "1e-45"); + test_write(::std::f32::MAX, "3.4028235e38"); +} + +fn test_write<F: dtoa::Floating>(value: F, expected: &'static str) { + let mut buf = [b'\0'; 30]; + let len = dtoa::write(&mut buf[..], value).unwrap(); + let result = str::from_utf8(&buf[..len]).unwrap(); + assert_eq!(result, expected.to_string()); +} |