-
Notifications
You must be signed in to change notification settings - Fork 0
/
z80Format_test.go
144 lines (124 loc) · 3.85 KB
/
z80Format_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package z80format_test
import (
"bytes"
"strings"
"testing"
"github.com/jeromelesaux/z80format"
"github.com/stretchr/testify/assert"
)
func TestLdWithLabelComment(t *testing.T) {
code := `LD de,my_font ; SpriteHardPtr`
expected := "\tLD DE,my_font; SpriteHardPtr\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestIncB(t *testing.T) {
code := `inc b`
expected := "\t" + strings.ToUpper(code) + "\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestCallWithLabel(t *testing.T) {
code := `call #BC07`
expected := "\t" + strings.ToUpper(code) + "\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestOut(t *testing.T) {
code := `out (c),a`
expected := "\t" + strings.ToUpper(code) + "\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestLd16Registers(t *testing.T) {
code := `ld bc,DE`
expected := "\t" + strings.ToUpper(code) + "\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestLd16RegistersWithLabelComment(t *testing.T) {
code := `ptr ld bc,DE ; comment`
expected := "ptr\tLD BC,DE; comment\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestLd16RegistersWithLabelComments(t *testing.T) {
code := `ptr ld bc,DE ; comment comment1 comment2`
expected := "ptr\tLD BC,DE; comment comment1 comment2\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestLdWithLabel(t *testing.T) {
code := `space ld bc,#F40E`
expected := "space\tLD BC,#F40E\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestJumpWithConditionComment(t *testing.T) {
code := `jr nc, WaitVbl; my comment`
expected := "\tJR NC,WaitVbl;my comment\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestIm1(t *testing.T) {
code := `im 1`
expected := "\tIM 1\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestIsHexadecimal(t *testing.T) {
res := z80format.IsHexadecimal("#BC77")
assert.Equal(t, true, res)
res = z80format.IsHexadecimal("#bc77")
assert.Equal(t, true, res)
res = z80format.IsHexadecimal("&77")
assert.Equal(t, true, res)
}
func TestData(t *testing.T) {
code := `def 1,2,3,4,5`
expected := "def 1,2,3,4,5\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestRasmSaveKeyword(t *testing.T) {
code := `save'disc.bin',#200, end - start,DSK,'martine-animate.dsk'`
expected := "save'disc.bin',#200, end - start,DSK,'martine-animate.dsk'\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestOutiWithLabel(t *testing.T) {
code := `label outi`
expected := "label\tOUTI\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}
func TestRegisterA(t *testing.T) {
code := `LD B,C`
expected := "\tLD B,C\n"
res, err := z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
code = `LD A,I`
expected = "\tLD A,I\n"
res, err = z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
code = ` LD C,A`
expected = "\tLD C,A\n"
res, err = z80format.Format(bytes.NewBufferString(code))
assert.NoError(t, err)
assert.Equal(t, expected, res)
}