Skip to content

Commit

Permalink
Add tests to lib, fix doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wraitii committed Jun 13, 2023
1 parent 4687fb7 commit 787c9b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions crates/cairo-lang-plugins/src/plugins/consteval_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ impl MacroPlugin for ConstevalIntMacroPlugin {
}
}

// Rewrite a constant declaration that contains a consteval_int macro
// into a constant declaration with the computed value,
// e.g. `const a: felt252 = consteval_int!(2 * 2 * 2);` into `const a: felt252 = 8;`.
/// Rewrite a constant declaration that contains a consteval_int macro
/// into a constant declaration with the computed value,
/// e.g. `const a: felt252 = consteval_int!(2 * 2 * 2);` into `const a: felt252 = 8;`.
fn handle_constant(db: &dyn SyntaxGroup, constant_ast: &ast::ItemConstant) -> PluginResult {
let constant_value = constant_ast.value(db);
if let ast::Expr::InlineMacro(inline_macro) = constant_value {
Expand Down Expand Up @@ -68,7 +68,7 @@ fn handle_constant(db: &dyn SyntaxGroup, constant_ast: &ast::ItemConstant) -> Pl
PluginResult::default()
}

// Extract the actual expression from the consteval_int macro, or fail with diagnostics.
/// Extract the actual expression from the consteval_int macro, or fail with diagnostics.
fn extract_consteval_macro_expression(
db: &dyn SyntaxGroup,
macro_ast: &ast::ExprInlineMacro,
Expand All @@ -94,8 +94,8 @@ fn extract_consteval_macro_expression(
}
}

// Compute the actual value of an integer expression, or fail with diagnostics.
// This computation handles arbitrary integers, unlike regular Cairo math.
/// Compute the actual value of an integer expression, or fail with diagnostics.
/// This computation handles arbitrary integers, unlike regular Cairo math.
fn compute_constant_expr(
db: &dyn SyntaxGroup,
value: &ast::Expr,
Expand Down
8 changes: 4 additions & 4 deletions tests/bug_samples/issue3130.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const a: felt252 = (4 + 2 * 3) * 256;
const b: felt252 = 0xff & (24 + 5 * 2);
const c: felt252 = -0xff & (24 + 5 * 2);
const d: felt252 = 0xff | (24 + 5 * 2);
const a: felt252 = consteval_int!((4 + 2 * 3) * 256);
const b: felt252 = consteval_int!(0xff & (24 + 5 * 2));
const c: felt252 = consteval_int!(-0xff & (24 + 5 * 2));
const d: felt252 = consteval_int!(0xff | (24 + 5 * 2));

#[test]
fn main() {}
1 change: 1 addition & 0 deletions tests/bug_samples/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod issue2939;
mod issue2961;
mod issue2964;
mod issue2995;
mod issue3130;
mod issue3153;
mod issue3192;
mod issue3211;
Expand Down

0 comments on commit 787c9b1

Please sign in to comment.