package iskra import "testing" func TestMakeKey(t *testing.T) { key := MakeCodeKey(StageSRC, 0x00ABCDEF12345678) if KeyStage(key) != StageSRC { t.Fatal("stage not preserved") } if KeyHash(key) != 0x00ABCDEF12345678 { t.Fatal("hash not preserved") } } func TestMakeKeyTruncatesHash(t *testing.T) { // Hash with bits in the top byte should be masked off. key := MakeCodeKey(StageIR, 0xFFFFFFFFFFFFFFFF) if KeyHash(key) != 0x00FFFFFFFFFFFFFF { t.Fatal("hash should be truncated to 56 bits") } if KeyStage(key) != StageIR { t.Fatal("stage should override top bits") } } func TestStageConstants(t *testing.T) { stages := []uint8{StageSRC, StageAST, StageIR, StageASM, StageBIN} for i := 0; i < len(stages); i++ { for j := i + 1; j < len(stages); j++ { if stages[i] == stages[j] { t.Fatal("stage constants must be unique") } } } }