Add more tests & rename 'Invalid' -> 'Unfinished'
This commit is contained in:
@@ -30,7 +30,7 @@ impl ParseError {
|
||||
|
||||
pub fn invalid_assignment_right_hand_side(span: Span) -> Self {
|
||||
Self {
|
||||
kind: ErrorKind::InvalidAssignmentRightHandSide,
|
||||
kind: ErrorKind::UnfinishedAssignmentRightHandSide,
|
||||
span,
|
||||
while_parsing: None,
|
||||
expected: HashSet::new(),
|
||||
@@ -173,7 +173,7 @@ pub enum ErrorKind {
|
||||
hint: Option<String>,
|
||||
},
|
||||
|
||||
#[error("I discovered an invalid assignment.")]
|
||||
#[error("I discovered an unfinished assignment.")]
|
||||
#[diagnostic(
|
||||
help(
|
||||
"{} and {} bindings must be followed by a valid expression.",
|
||||
@@ -181,7 +181,7 @@ pub enum ErrorKind {
|
||||
"expect".if_supports_color(Stdout, |s| s.yellow()),
|
||||
),
|
||||
)]
|
||||
InvalidAssignmentRightHandSide,
|
||||
UnfinishedAssignmentRightHandSide,
|
||||
|
||||
#[error("I tripped over a {}", fmt_curve_type(.curve))]
|
||||
PointNotOnCurve { curve: CurveType },
|
||||
|
||||
@@ -94,4 +94,42 @@ mod tests {
|
||||
fn expect_trace_if_false() {
|
||||
assert_expr!("expect foo?");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_unfinished_let() {
|
||||
assert_expr!(
|
||||
"
|
||||
let a =
|
||||
// foo
|
||||
let b = 42
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_let_in_let() {
|
||||
assert_expr!("let a = { let b = 42 }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_let_in_let_return() {
|
||||
assert_expr!(
|
||||
"
|
||||
let a = {
|
||||
let b = 42
|
||||
b
|
||||
}
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_let_in_let_parens() {
|
||||
assert_expr!("let a = ( let b = 42 )");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect_expect_let() {
|
||||
assert_expr!("expect { let a = 42 } = foo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Code:\n\nexpect { let a = 42 } = foo"
|
||||
---
|
||||
Assignment {
|
||||
location: 0..21,
|
||||
value: Sequence {
|
||||
location: 7..21,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 9..19,
|
||||
value: UInt {
|
||||
location: 17..19,
|
||||
value: "42",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
pattern: Var {
|
||||
location: 13..14,
|
||||
name: "a",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
],
|
||||
},
|
||||
pattern: Constructor {
|
||||
is_record: false,
|
||||
location: 0..21,
|
||||
name: "True",
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
tipo: (),
|
||||
},
|
||||
kind: Expect,
|
||||
annotation: None,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Code:\n\nlet a = { let b = 42 }"
|
||||
---
|
||||
Assignment {
|
||||
location: 0..22,
|
||||
value: Sequence {
|
||||
location: 8..22,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 10..20,
|
||||
value: UInt {
|
||||
location: 18..20,
|
||||
value: "42",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
pattern: Var {
|
||||
location: 14..15,
|
||||
name: "b",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
],
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..5,
|
||||
name: "a",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Invalid code (parse error):\n\nlet a = ( let b = 42 )"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: UnfinishedAssignmentRightHandSide,
|
||||
span: 0..22,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"invalid assignment right-hand side",
|
||||
),
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Code:\n\nlet a = {\n let b = 42\n b\n}\n"
|
||||
---
|
||||
Assignment {
|
||||
location: 0..28,
|
||||
value: Sequence {
|
||||
location: 12..26,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 12..22,
|
||||
value: UInt {
|
||||
location: 20..22,
|
||||
value: "42",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
pattern: Var {
|
||||
location: 16..17,
|
||||
name: "b",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
Var {
|
||||
location: 25..26,
|
||||
name: "b",
|
||||
},
|
||||
],
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..5,
|
||||
name: "a",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Invalid code (parse error):\n\nlet a =\n// foo\nlet b = 42\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: UnfinishedAssignmentRightHandSide,
|
||||
span: 0..25,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"invalid assignment right-hand side",
|
||||
),
|
||||
},
|
||||
]
|
||||
@@ -28,15 +28,28 @@ macro_rules! assert_expr {
|
||||
|
||||
let stream = chumsky::Stream::from_iter($crate::ast::Span::create(tokens.len(), 1), tokens.into_iter());
|
||||
|
||||
let result = $crate::parser::expr::sequence().parse(stream).unwrap();
|
||||
let result = $crate::parser::expr::sequence().parse(stream);
|
||||
|
||||
insta::with_settings!({
|
||||
description => concat!("Code:\n\n", indoc::indoc! { $code }),
|
||||
prepend_module_to_snapshot => false,
|
||||
omit_expression => true
|
||||
}, {
|
||||
insta::assert_debug_snapshot!(result);
|
||||
});
|
||||
match result {
|
||||
Ok(expr) => {
|
||||
insta::with_settings!({
|
||||
description => concat!("Code:\n\n", indoc::indoc! { $code }),
|
||||
prepend_module_to_snapshot => false,
|
||||
omit_expression => true
|
||||
}, {
|
||||
insta::assert_debug_snapshot!(expr);
|
||||
})
|
||||
},
|
||||
Err(err) => {
|
||||
insta::with_settings!({
|
||||
description => concat!("Invalid code (parse error):\n\n", indoc::indoc! { $code }),
|
||||
prepend_module_to_snapshot => false,
|
||||
omit_expression => true
|
||||
}, {
|
||||
insta::assert_debug_snapshot!(err);
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user