instruction_test.go (958B)
1 package asm 2 3 import "testing" 4 5 func TestInstructionStringify(t *testing.T) { 6 input := []struct { 7 instr Instruction 8 str string 9 }{ 10 {Instruction{Opcode: CMOV, RegA: 10, RegB: 20, RegC: 30}, "CMOV 10 20 30 "}, 11 {Instruction{Opcode: OUTP, RegC: 54}, "OUTP 54 "}, 12 {Instruction{Opcode: ORTH, RegA: 5, Value: 65535}, "ORTH 5 65535"}, 13 {Instruction{Opcode: HALT}, "HALT "}, 14 } 15 16 for _, tt := range input { 17 if tt.instr.String() != tt.str { 18 t.Fatalf(`invalid string for instruction %q, expected "%s", got "%s"`, tt.instr, tt.str, tt.instr.String()) 19 } 20 } 21 } 22 23 func TestInstructionParse(t *testing.T) { 24 input := []struct { 25 in string 26 out string 27 }{ 28 {"cmov 2 3 4", "CMOV 2 3 4 "}, 29 {"orth 1 1020", "ORTH 1 1020"}, 30 {"orth 1 'b'", "ORTH 1 98"}, 31 {"outp 6", "OUTP 6 "}, 32 } 33 34 for _, tt := range input { 35 ins := NewInstruction(tt.in) 36 if ins.String() != tt.out { 37 t.Fatalf(`test mismatch: "%s" instead of "%s"`, ins.String(), tt.out) 38 } 39 } 40 }