mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Test floats that are too big/small
This commit is contained in:
parent
a83638c2e1
commit
9b3bb7abd7
2 changed files with 30 additions and 7 deletions
|
@ -94,8 +94,8 @@ where
|
|||
}
|
||||
|
||||
// At this point we have a number, and will definitely succeed.
|
||||
// If the number is malformed (too large to fit), we'll succeed with
|
||||
// an appropriate Expr which records that.
|
||||
// If the number is malformed (outside the supported range),
|
||||
// we'll succeed with an appropriate Expr which records that.
|
||||
let expr = if has_decimal_point {
|
||||
let mut f64_buf = String::with_capacity_in(
|
||||
before_decimal.len()
|
||||
|
|
|
@ -298,14 +298,14 @@ mod test_parser {
|
|||
fn positive_int() {
|
||||
assert_parses_to("1", Int(1));
|
||||
assert_parses_to("42", Int(42));
|
||||
assert_parses_to(i64::MAX.to_string().as_str(), Int(std::i64::MAX));
|
||||
assert_parses_to(i64::MAX.to_string().as_str(), Int(i64::MAX));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_int() {
|
||||
assert_parses_to("-1", Int(-1));
|
||||
assert_parses_to("-42", Int(-42));
|
||||
assert_parses_to(i64::MIN.to_string().as_str(), Int(std::i64::MIN));
|
||||
assert_parses_to(i64::MIN.to_string().as_str(), Int(i64::MIN));
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
|
@ -342,8 +342,11 @@ mod test_parser {
|
|||
assert_parses_to("1.1", Float(1.1));
|
||||
assert_parses_to("42.0", Float(42.0));
|
||||
assert_parses_to("42.9", Float(42.9));
|
||||
assert_parses_to(&format!("{}.0", f64::MAX), Float(std::f64::MAX));
|
||||
panic!("TODO stress test maximum float *digits*, not just integer vals");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highest_float() {
|
||||
assert_parses_to(&format!("{}.0", f64::MAX), Float(f64::MAX));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -352,7 +355,11 @@ mod test_parser {
|
|||
assert_parses_to("-1.1", Float(-1.1));
|
||||
assert_parses_to("-42.0", Float(-42.0));
|
||||
assert_parses_to("-42.9", Float(-42.9));
|
||||
assert_parses_to(f64::MIN.to_string().as_str(), Float(std::f64::MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lowest_float() {
|
||||
assert_parses_to(&format!("{}.0", f64::MIN), Float(f64::MIN));
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
|
@ -360,6 +367,22 @@ mod test_parser {
|
|||
assert_parses_to(num.to_string().as_str(), Float(num));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_too_large() {
|
||||
assert_parses_to(
|
||||
format!("{}1.0", f64::MAX).as_str(),
|
||||
MalformedNumber(Problem::OutsideSupportedRange),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_too_small() {
|
||||
assert_parses_to(
|
||||
format!("{}1.0", f64::MIN).as_str(),
|
||||
MalformedNumber(Problem::OutsideSupportedRange),
|
||||
);
|
||||
}
|
||||
|
||||
// fn expect_parsed_float<'a>(expected: f64, actual: &str) {
|
||||
// assert_eq!(
|
||||
// Ok((Float(expected), "".to_string())),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue