stage_test.mx raw
1 package iskra
2
3 import "testing"
4
5 func TestMakeKey(t *testing.T) {
6 key := MakeCodeKey(StageSRC, 0x00ABCDEF12345678)
7 if KeyStage(key) != StageSRC {
8 t.Fatal("stage not preserved")
9 }
10 if KeyHash(key) != 0x00ABCDEF12345678 {
11 t.Fatal("hash not preserved")
12 }
13 }
14
15 func TestMakeKeyTruncatesHash(t *testing.T) {
16 // Hash with bits in the top byte should be masked off.
17 key := MakeCodeKey(StageIR, 0xFFFFFFFFFFFFFFFF)
18 if KeyHash(key) != 0x00FFFFFFFFFFFFFF {
19 t.Fatal("hash should be truncated to 56 bits")
20 }
21 if KeyStage(key) != StageIR {
22 t.Fatal("stage should override top bits")
23 }
24 }
25
26 func TestStageConstants(t *testing.T) {
27 stages := []uint8{StageSRC, StageAST, StageIR, StageASM, StageBIN}
28 for i := 0; i < len(stages); i++ {
29 for j := i + 1; j < len(stages); j++ {
30 if stages[i] == stages[j] {
31 t.Fatal("stage constants must be unique")
32 }
33 }
34 }
35 }
36