mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
more test coverage
This commit is contained in:
parent
f7ec5de7c9
commit
8c497f0b7a
@ -35,15 +35,9 @@ impl CombinerError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn illegal_compound_array_access(span: &Span) -> Self {
|
||||
pub fn illegal_compound_array_range(span: &Span) -> Self {
|
||||
let message = "Illegal compound assignement with array range".to_string();
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn illegal_compound_operation(span: &Span) -> Self {
|
||||
let message = "Illegal compound assignment operator =".to_string();
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ impl Canonicalizer {
|
||||
span: span.clone(),
|
||||
}));
|
||||
}
|
||||
_ => return Err(ReducerError::from(CombinerError::illegal_compound_array_access(&span))),
|
||||
_ => return Err(ReducerError::from(CombinerError::illegal_compound_array_range(&span))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,10 +79,9 @@ impl Canonicalizer {
|
||||
pub fn compound_operation_converstion(
|
||||
&mut self,
|
||||
operation: &AssignOperation,
|
||||
span: &Span,
|
||||
) -> Result<BinaryOperation, ReducerError> {
|
||||
match operation {
|
||||
AssignOperation::Assign => Err(ReducerError::from(CombinerError::illegal_compound_operation(&span))),
|
||||
AssignOperation::Assign => unreachable!(),
|
||||
AssignOperation::Add => Ok(BinaryOperation::Add),
|
||||
AssignOperation::Sub => Ok(BinaryOperation::Sub),
|
||||
AssignOperation::Mul => Ok(BinaryOperation::Mul),
|
||||
@ -550,7 +549,7 @@ impl ReconstructingReducer for Canonicalizer {
|
||||
&assign.span,
|
||||
)?;
|
||||
let right = Box::new(Expression::Binary(binary_expr));
|
||||
let op = self.compound_operation_converstion(&assign.operation, &assign.span)?;
|
||||
let op = self.compound_operation_converstion(&assign.operation)?;
|
||||
|
||||
let new_value = Expression::Binary(BinaryExpression {
|
||||
left,
|
||||
@ -573,7 +572,7 @@ impl ReconstructingReducer for Canonicalizer {
|
||||
&assign.span,
|
||||
)?;
|
||||
let right = Box::new(Expression::Value(value_expr));
|
||||
let op = self.compound_operation_converstion(&assign.operation, &assign.span)?;
|
||||
let op = self.compound_operation_converstion(&assign.operation)?;
|
||||
|
||||
let new_value = Expression::Binary(BinaryExpression {
|
||||
left,
|
||||
|
@ -0,0 +1,4 @@
|
||||
function main () {
|
||||
let x = [1u32; 5];
|
||||
x[..2] += 1;
|
||||
}
|
@ -87,3 +87,11 @@ fn test_compound_assignment() {
|
||||
|
||||
assert_eq!(expected_ast, ast);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_illegal_array_range_fail() {
|
||||
// Check program is invalid.
|
||||
let program_string = include_str!("illegal_array_range_fail.leo");
|
||||
let program = parse_program(program_string);
|
||||
assert!(program.is_err());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user