#![allow(clippy::min_ident_chars)]
use core::f64::consts::E;
use super::super::macros::assert_f64_eq;
use crate::Parser;
const VALID_TEST_CASES: [(&str, f64); 9] = [
("1", 1.0),
("1.2", 1.2),
("1.2e3", 1.2e3),
("1.2e-3", 1.2e-3),
("1.2e+3", 1.2e+3),
("1e", 1. * E),
("1.2e", 1.2 * E),
("1.2e+ 1", 1.2 * E + 1.),
("1.2e- 1", 1.2 * E - 1.),
];
const ERROR_TEST_CASES: [&str; 2] = ["1.2e+", "1.2e-"];
#[test]
fn parse_number() {
let parser = Parser::default();
for (input, expected) in VALID_TEST_CASES {
let result = parser.parse(input).unwrap().eval(&[].into());
assert!(result.is_ok(), "Should have parsed: '{input}'.");
let value = result.unwrap();
assert_f64_eq!(
value,
expected,
"{input}\nExpected: {expected}, got: {value}"
);
}
for input in ERROR_TEST_CASES {
assert!(
parser.parse(input).is_err(),
"Should have errored: '{input}'."
);
}
}