mirror of
https://github.com/MontFerret/ferret.git
synced 2026-06-20 01:17:53 +02:00
refactor: simplify bare array question lowering test to assert key optimization properties
Remove assertions on dataset construction opcodes (OpDataSet, OpPush) that bake in the materialization implementation detail. Instead, assert only the key optimization property: no counting-loop OpIncr and presence of OpLength for the emptiness check.
This commit is contained in:
committed by
GitHub
parent
86f7bcb131
commit
b55b8cc000
@@ -20,18 +20,14 @@ func TestArrayQuestionLowering(t *testing.T) {
|
||||
}
|
||||
|
||||
func expectBareArrayQuestionLowering(prog *bytecode.Program) error {
|
||||
expected := map[bytecode.Opcode]int{
|
||||
bytecode.OpDataSet: 1,
|
||||
bytecode.OpPush: 1,
|
||||
bytecode.OpLength: 1,
|
||||
bytecode.OpGt: 1,
|
||||
bytecode.OpIncr: 0,
|
||||
// The optimization must eliminate the counting loop (no OpIncr)
|
||||
// and use a length/emptiness check instead.
|
||||
if got := inspect.CountOpcode(prog, bytecode.OpIncr); got != 0 {
|
||||
return fmt.Errorf("expected no OpIncr (counting loop eliminated), got %d", got)
|
||||
}
|
||||
|
||||
for opcode, count := range expected {
|
||||
if got := inspect.CountOpcode(prog, opcode); got != count {
|
||||
return fmt.Errorf("expected %d %s ops, got %d", count, opcode, got)
|
||||
}
|
||||
if !inspect.HasOpcode(prog, bytecode.OpLength) {
|
||||
return fmt.Errorf("expected OpLength for emptiness check")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user