package hbrtl import ( "five/hbrt" "testing" ) func TestErrorBlock(t *testing.T) { _, th := setupVM() // Reset errorBlock for test errorBlock = hbrt.MakeNil() // Get default (NIL) th.PendingParams2(0) ErrorBlock(th) if !th.GetRetValue().IsNil() { t.Error("Default ERRORBLOCK should be NIL") } // Set a block block := hbrt.MakeBlock(func(t *hbrt.Thread) { t.Frame(0, 0) defer t.EndProc() t.RetNil() }, 0) th.PushValue(block) th.PendingParams2(1) ErrorBlock(th) // Returns old (NIL) if !th.GetRetValue().IsNil() { t.Error("ERRORBLOCK(bNew) should return old NIL") } // Query — should return the block now th.PendingParams2(0) ErrorBlock(th) if th.GetRetValue().IsNil() { t.Error("ERRORBLOCK() should return the set block") } } func TestErrorNew(t *testing.T) { _, th := setupVM() th.PendingParams2(0) ErrorNew(th) errObj := th.GetRetValue() if errObj.IsNil() { t.Fatal("ERRORNEW returned NIL") } if !errObj.IsHash() { t.Fatal("ERRORNEW should return a hash") } h := errObj.AsHash() if h == nil || len(h.Keys) != 14 { t.Errorf("ERRORNEW hash has %d keys, want 14", len(h.Keys)) } } func TestDosError(t *testing.T) { _, th := setupVM() lastDosErr = 0 // reset // Get th.PendingParams2(0) DosError(th) if r := th.GetRetValue().AsLong(); r != 0 { t.Errorf("DOSERROR() = %d, want 0", r) } // Set th.PushInt(5) th.PendingParams2(1) DosError(th) if r := th.GetRetValue().AsLong(); r != 0 { t.Errorf("DOSERROR(5) old = %d, want 0", r) } // Get again th.PendingParams2(0) DosError(th) if r := th.GetRetValue().AsLong(); r != 5 { t.Errorf("DOSERROR() = %d, want 5", r) } } func TestFError(t *testing.T) { _, th := setupVM() SetFError(2) th.PendingParams2(0) FError(th) if r := th.GetRetValue().AsLong(); r != 2 { t.Errorf("FERROR() = %d, want 2", r) } }