tests: add parser/vm bitops tests; docs: update cheatsheet and language guide for bitwise ops and shift; note Arrow(>>) removal
- Add src/tests/parser_bitops_test.rs and vm_bitops_test.rs - Update tokenizer unit test to expect SHIFT_RIGHT - Update quick-reference and language guide to document &,|,^,<<,>> and Arrow deprecation Known: one unrelated test failing (consolebox println TLV vs typebox) pre-existing.
This commit is contained in:
25
src/tests/vm_bitops_test.rs
Normal file
25
src/tests/vm_bitops_test.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::parser::NyashParser;
|
||||
use crate::interpreter::NyashInterpreter;
|
||||
|
||||
#[test]
|
||||
fn vm_exec_bitwise_and_shift() {
|
||||
let code = r#"
|
||||
return (5 & 3) + (5 | 2) + (5 ^ 1) + (1 << 5) + (32 >> 3)
|
||||
"#;
|
||||
let ast = NyashParser::parse_from_string(code).expect("parse ok");
|
||||
let mut interp = NyashInterpreter::new();
|
||||
let out = interp.execute(ast).expect("exec ok");
|
||||
assert_eq!(out.to_string_box().value, "48");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_exec_shift_masking() {
|
||||
// 1 << 100 should mask to 1 << (100 & 63) = 1 << 36
|
||||
let code = r#" return 1 << 100 "#;
|
||||
let ast = NyashParser::parse_from_string(code).expect("parse ok");
|
||||
let mut interp = NyashInterpreter::new();
|
||||
let out = interp.execute(ast).expect("exec ok");
|
||||
// compute expected as i64
|
||||
let expected = (1_i64 as i64).wrapping_shl((100_u32) & 63);
|
||||
assert_eq!(out.to_string_box().value, expected.to_string());
|
||||
}
|
||||
Reference in New Issue
Block a user