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:
20
src/tests/parser_bitops_test.rs
Normal file
20
src/tests/parser_bitops_test.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::parser::NyashParser;
|
||||
use crate::ast::ASTNode;
|
||||
|
||||
#[test]
|
||||
fn parse_bitops_and_shift_precedence() {
|
||||
// Expression: 1 + 2 << 3 & 7
|
||||
// Precedence: shift before add, then &: (1 + (2 << 3)) & 7
|
||||
let code = "return 1 + 2 << 3 & 7";
|
||||
let ast = NyashParser::parse_from_string(code).expect("parse ok");
|
||||
// Just ensure it parses into a Program and contains a Return; deeper tree checks are optional here
|
||||
fn has_return(n: &ASTNode) -> bool {
|
||||
match n {
|
||||
ASTNode::Program { statements, .. } => statements.iter().any(has_return),
|
||||
ASTNode::Return { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
assert!(has_return(&ast));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user