mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
fix offsets, add tests
This commit is contained in:
parent
7761c51f92
commit
0684a93727
3 changed files with 46 additions and 8 deletions
|
@ -139,6 +139,21 @@ mod test_can {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn float_double_dot() {
|
||||||
|
let string = "1.1.1";
|
||||||
|
let region = Region::zero();
|
||||||
|
|
||||||
|
assert_can(
|
||||||
|
&string.clone(),
|
||||||
|
RuntimeError(RuntimeError::InvalidFloat(
|
||||||
|
FloatErrorKind::Error,
|
||||||
|
region,
|
||||||
|
string.into(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zero() {
|
fn zero() {
|
||||||
assert_can_num("0", 0);
|
assert_can_num("0", 0);
|
||||||
|
|
|
@ -40,11 +40,10 @@ fn chomp_number_base<'a>(
|
||||||
bytes: &'a [u8],
|
bytes: &'a [u8],
|
||||||
state: State<'a>,
|
state: State<'a>,
|
||||||
) -> ParseResult<'a, Expr<'a>, Number> {
|
) -> ParseResult<'a, Expr<'a>, Number> {
|
||||||
let (_is_float, mut chomped) = chomp_number(bytes);
|
let (_is_float, chomped) = chomp_number(bytes);
|
||||||
chomped += 2 + (is_negative as usize);
|
|
||||||
|
|
||||||
match parse_utf8(&bytes[0..chomped]) {
|
match parse_utf8(&bytes[0..chomped]) {
|
||||||
Ok(string) => match state.advance_without_indenting(chomped) {
|
Ok(string) => match state.advance_without_indenting(chomped + 2 + is_negative as usize) {
|
||||||
Ok(new) => {
|
Ok(new) => {
|
||||||
// all is well
|
// all is well
|
||||||
Ok((
|
Ok((
|
||||||
|
@ -73,7 +72,7 @@ fn chomp_number_dec<'a>(
|
||||||
bytes: &'a [u8],
|
bytes: &'a [u8],
|
||||||
state: State<'a>,
|
state: State<'a>,
|
||||||
) -> ParseResult<'a, Expr<'a>, Number> {
|
) -> ParseResult<'a, Expr<'a>, Number> {
|
||||||
let (is_float, mut chomped) = chomp_number(bytes);
|
let (is_float, chomped) = chomp_number(bytes);
|
||||||
|
|
||||||
if is_negative && chomped == 0 {
|
if is_negative && chomped == 0 {
|
||||||
// we're probably actually looking at unary negation here
|
// we're probably actually looking at unary negation here
|
||||||
|
@ -85,11 +84,9 @@ fn chomp_number_dec<'a>(
|
||||||
return Err((Progress::NoProgress, Number::End, state));
|
return Err((Progress::NoProgress, Number::End, state));
|
||||||
}
|
}
|
||||||
|
|
||||||
chomped += is_negative as usize;
|
let string = unsafe { from_utf8_unchecked(&state.bytes[0..chomped + is_negative as usize]) };
|
||||||
|
|
||||||
let string = unsafe { from_utf8_unchecked(&state.bytes[0..chomped]) };
|
match state.advance_without_indenting(chomped + is_negative as usize) {
|
||||||
|
|
||||||
match state.advance_without_indenting(chomped) {
|
|
||||||
Ok(new) => {
|
Ok(new) => {
|
||||||
// all is well
|
// all is well
|
||||||
Ok((
|
Ok((
|
||||||
|
|
|
@ -5134,4 +5134,30 @@ mod test_reporting {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn number_double_dot() {
|
||||||
|
report_problem_as(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
1.1.1
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
── SYNTAX PROBLEM ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
This float literal contains an invalid digit:
|
||||||
|
|
||||||
|
1│ 1.1.1
|
||||||
|
^^^^^
|
||||||
|
|
||||||
|
Floating point literals can only contain the digits 0-9, or use
|
||||||
|
scientific notation 10e4
|
||||||
|
|
||||||
|
Tip: Learn more about number literals at TODO
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue