functions with bindings
Some checks failed
Build / build (push) Failing after 1m42s
Test / build (push) Successful in 2m27s

This commit is contained in:
Chuck Smith
2024-03-08 14:19:20 -05:00
parent 9d06c90e41
commit ec9a586f7f
10 changed files with 350 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ func TestMake(t *testing.T) {
}{
{OpConstant, []int{65534}, []byte{byte(OpConstant), 255, 254}},
{OpAdd, []int{}, []byte{byte(OpAdd)}},
{OpGetLocal, []int{255}, []byte{byte(OpGetLocal), 255}},
}
for _, tt := range test {
@@ -30,13 +31,15 @@ func TestMake(t *testing.T) {
func TestInstructions(t *testing.T) {
instructions := []Instructions{
Make(OpAdd),
Make(OpGetLocal, 1),
Make(OpConstant, 2),
Make(OpConstant, 65535),
}
expected := `0000 OpAdd
0001 OpConstant 2
0004 OpConstant 65535
0001 OpGetLocal 1
0003 OpConstant 2
0006 OpConstant 65535
`
concatted := Instructions{}
@@ -49,13 +52,14 @@ func TestInstructions(t *testing.T) {
}
}
func TestOperands(t *testing.T) {
func TestReadOperands(t *testing.T) {
tests := []struct {
op Opcode
operands []int
bytesRead int
}{
{OpConstant, []int{65535}, 2},
{OpGetLocal, []int{255}, 1},
}
for _, tt := range tests {