feat: 支持复合运算符
This commit is contained in:
@@ -202,3 +202,43 @@ fn compile_unary_plus_no_error() {
|
||||
});
|
||||
assert!(result.is_ok(), "+'hello' should compile without error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compile_compound_add() {
|
||||
let module = compile_source("var x=0; x+=1");
|
||||
assert!(
|
||||
module
|
||||
.bytecode
|
||||
.iter()
|
||||
.any(|&i| opcode::opcode(i) == OpCode::COMPOUND_ADD),
|
||||
"x+=1 should emit COMPOUND_ADD opcode"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compile_compound_exp() {
|
||||
let module = compile_source("var x=0; x**=2");
|
||||
assert!(
|
||||
module
|
||||
.bytecode
|
||||
.iter()
|
||||
.any(|&i| opcode::opcode(i) == OpCode::COMPOUND_EXP),
|
||||
"x**=2 should emit COMPOUND_EXP opcode"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compile_compound_assign_no_error() {
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
compile_source("x+=1");
|
||||
});
|
||||
assert!(result.is_ok(), "x+=1 should compile without error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compile_compound_exp_no_error() {
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
compile_source("x**=2");
|
||||
});
|
||||
assert!(result.is_ok(), "x**=2 should compile without error");
|
||||
}
|
||||
|
||||
@@ -97,3 +97,10 @@ fn regression_conditionalexpression_hash() {
|
||||
"different expression types with same test must produce different hashes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_compound_vs_simple_assign() {
|
||||
let hash_a = parse_to_hash("x=1");
|
||||
let hash_b = parse_to_hash("x+=1");
|
||||
assert_ne!(hash_a, hash_b, "x=1 and x+=1 must produce different hashes");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user