go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

debug_test.go (1079B)


      1 package state
      2 
      3 import (
      4 	"fmt"
      5 	"strings"
      6 	"testing"
      7 )
      8 
      9 func TestDebugFlagDenied(t *testing.T) {
     10 	err := FlagDebugger.Register(7, "foo")
     11 	if err == nil {
     12 		t.Fatalf("expected error")
     13 	}
     14 }
     15 
     16 func TestDebugFlagString(t *testing.T) {
     17 	err := FlagDebugger.Register(8, "FOO")
     18 	if err != nil {
     19 		t.Fatal(err)
     20 	}
     21 	err = FlagDebugger.Register(9, "BAR")
     22 	if err != nil {
     23 		t.Fatal(err)
     24 	}
     25 	err = FlagDebugger.Register(11, "BAZ")
     26 	if err != nil {
     27 		t.Fatal(err)
     28 	}
     29 	flags := []byte{0x06, 0x19}
     30 	r := FlagDebugger.AsString(flags, 5)
     31 	expect := "INTERNAL_INMATCH(1),INTERNAL_WAIT(2),FOO(8),BAZ(11),?unreg?(12)" 
     32 	if r != expect {
     33 		t.Fatalf("expected '%s', got '%s'", expect, r)
     34 	}
     35 }
     36 
     37 func TestDebugState(t *testing.T) {
     38 	err := FlagDebugger.Register(8, "FOO")
     39 	if err != nil {
     40 		t.Fatal(err)
     41 	}
     42 	st := NewState(1)
     43 	st.UseDebug()
     44 	st.SetFlag(FLAG_DIRTY)
     45 	st.SetFlag(8)
     46 	st.Down("root")
     47 
     48 	r := fmt.Sprintf("%s", st)
     49 	expect := "moves: 1 idx: 0 flags: INTERNAL_DIRTY(4),FOO(8) path: root lang: (default)"
     50 	if strings.Contains(expect, r) {
     51 		t.Fatalf("expected '%s', got '%s'", expect, r)
     52 	}
     53 }
     54