speckl/compiler/test-parser.mjs
Scott Scoble 3ca5a8d21a fix(z3): preserve implies args, multi-level field access, len(), nil, distinct operator
Z3 expression translator fixes:
- implies(x, y) now preserves both arguments (was dropping both → (=> true true))
- Multi-level field access m.price.amount → m_price_amount (was m_price.(>= amount 0))
- len() now handled same as length() (was left as bare len())
- nil/null translated to speckl_nil sentinel constant
- != now properly converts to (distinct X Y) via convertToPrefix (was bare 'distinct')
- Added 'distinct' as binary operator in convertToPrefix
- speckl_nil declared as Int constant in output

All 8 product spec constraints now produce valid SMT-LIB2.
57/57 tests pass.
2026-06-29 17:31:31 -07:00

22 lines
635 B
JavaScript

import { parseActionStatements } from './dist/expr/stmt-parser.js';
const tests = [
['serverState[voter].currentTerm := req.term'],
['let newTerm := 5', 'newTerm := 6'],
['require foo == bar'],
['return 5'],
['emit VoteGranted { voter: voter, candidate: 1, term: 2 }'],
['if foo { x := 1 } else { y := 2 }'],
['x := 1', 'y := 2', 'return 5'],
];
for (const lines of tests) {
console.log('---');
console.log('input:', lines);
try {
const out = parseActionStatements(lines);
console.log('output:', JSON.stringify(out, null, 2).substring(0, 700));
} catch (e) {
console.log('error:', e.message);
}
}