mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
Test too big/small int literals
This commit is contained in:
parent
dfd1d4bbb4
commit
5e740da48c
3 changed files with 22 additions and 5 deletions
|
@ -111,12 +111,12 @@ where
|
|||
|
||||
match f64_buf.parse::<f64>() {
|
||||
Ok(float) => Expr::Float(float),
|
||||
Err(_) => Expr::MalformedNumber(Problem::TooLarge),
|
||||
Err(_) => Expr::MalformedNumber(Problem::OutsideSupportedRange),
|
||||
}
|
||||
} else {
|
||||
match before_decimal.parse::<i64>() {
|
||||
Ok(int_val) => Expr::Int(int_val),
|
||||
Err(_) => Expr::MalformedNumber(Problem::TooLarge),
|
||||
Err(_) => Expr::MalformedNumber(Problem::OutsideSupportedRange),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -21,5 +21,5 @@ pub enum Problem {
|
|||
UnsupportedEscapedChar,
|
||||
|
||||
// NUMBER LITERAL
|
||||
TooLarge,
|
||||
OutsideSupportedRange,
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ mod test_parser {
|
|||
use roc::parse::parser::{Fail, FailReason, Parser, State};
|
||||
use roc::parse::problems::Problem;
|
||||
use roc::region::{Located, Region};
|
||||
use std::i64;
|
||||
|
||||
fn assert_parses_to<'a>(input: &'a str, expected_expr: Expr<'a>) {
|
||||
let state = State::new(&input, Attempting::Module);
|
||||
|
@ -287,14 +288,30 @@ mod test_parser {
|
|||
fn positive_int() {
|
||||
assert_parses_to("1", Int(1));
|
||||
assert_parses_to("42", Int(42));
|
||||
assert_parses_to(&std::i64::MAX.to_string(), Int(std::i64::MAX));
|
||||
assert_parses_to(i64::MAX.to_string().as_str(), Int(std::i64::MAX));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn negative_int() {
|
||||
assert_parses_to("-1", Int(-1));
|
||||
assert_parses_to("-42", Int(-42));
|
||||
assert_parses_to(&std::i64::MIN.to_string(), Int(std::i64::MIN));
|
||||
assert_parses_to(i64::MIN.to_string().as_str(), Int(std::i64::MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int_too_large() {
|
||||
assert_parses_to(
|
||||
(i64::MAX as i128 + 1).to_string().as_str(),
|
||||
MalformedNumber(Problem::OutsideSupportedRange),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int_too_small() {
|
||||
assert_parses_to(
|
||||
(i64::MIN as i128 - 1).to_string().as_str(),
|
||||
MalformedNumber(Problem::OutsideSupportedRange),
|
||||
);
|
||||
}
|
||||
|
||||
// fn expect_parsed_float<'a>(expected: f64, actual: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue