-
Notifications
You must be signed in to change notification settings - Fork 1
/
bytecode_test.go
45 lines (37 loc) · 932 Bytes
/
bytecode_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
package vmgen
import (
"fmt"
"testing"
"github.com/end-r/goutil"
)
func TestBytecodeAddCommand(t *testing.T) {
b := new(Bytecode)
c := Command{
mnemonic: "ADD",
}
b.AddCommand(&c)
goutil.Assert(t, b.Length() == 1, "wrong length")
}
func TestBytecodeAdd(t *testing.T) {
b := new(Bytecode)
b.Add("ADD")
goutil.Assert(t, b.Length() == 1, "wrong length")
}
func TestBytecodeConcat(t *testing.T) {
b := new(Bytecode)
b.Add("ADD")
goutil.Assert(t, b.Length() == 1, "wrong b length")
o := Bytecode{}
o.Add("ADD")
goutil.Assert(t, o.Length() == 1, "wrong o length")
b.Concat(o)
goutil.Assert(t, b.Length() == 2, "wrong total length")
}
func TestBytecodeFinalise(t *testing.T) {
b := new(Bytecode)
b.Add("ADD")
b.AddMarker("PUSH", 10)
b.Finalise()
goutil.Assert(t, b.Length() == 2, "wrong total length")
goutil.Assert(t, b.commands[1].offset == 10, fmt.Sprintf("wrong offset: %d", b.commands[1].offset))
}