Add assertion library (testify) and cartridge tests

This commit is contained in:
Michael Smith
2025-08-05 12:37:11 +02:00
parent b3da228722
commit 8d8c20221d
4 changed files with 43 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package gb
import (
"bytes"
"encoding/binary"
"io"
"log"
@@ -53,7 +54,7 @@ var cartridgeTypes = map[byte]string{
// RAM sizes
// https://gbdev.io/pandocs/The_Cartridge_Header.html#0149--ram-size
var ramSizes = map[byte]string{
0x00: "0 - No RAM ",
0x00: "0 - No RAM",
0x01: "UNUSED VALUE",
0x02: "8 KiB - 1 bank",
0x03: "32 KiB - 4 banks of 8 KiB each",
@@ -244,7 +245,7 @@ type Cartridge struct {
}
func Insert(filename string) Cartridge {
file, err := os.Open("rom.gb")
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
@@ -270,7 +271,7 @@ func Insert(filename string) Cartridge {
}
// Convert some header values
cartridge.Title = string(header.Title[:])
cartridge.Title = string(bytes.Trim(header.Title[:], "\x00"))
cartridge.Mapper = cartridgeTypes[header.CartridgeType]
if header.OldLicenseeCode == 0x33 {
// FIXME(m): Support new licensee codes

21
gb/cartridge_test.go Normal file
View File

@@ -0,0 +1,21 @@
package gb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInsertCartridge(t *testing.T) {
cartridge := Insert("../rom.gb")
assert := assert.New(t)
assert.Equal(cartridge.Title, "SEIKEN DENSETSU")
assert.Equal(cartridge.Mapper, "MBC2+BATTERY")
assert.Equal(cartridge.Licensee, "Square")
assert.False(cartridge.SGBSupport, "SGB support should be false")
assert.Equal(cartridge.ROMSize, 256)
assert.Equal(cartridge.RAMSize, "0 - No RAM")
assert.Equal(cartridge.Destination, "Overseas only")
assert.Equal(cartridge.Version, 0)
}