added test for game scanning
This commit is contained in:
122
internal/gamefile_test.go
Normal file
122
internal/gamefile_test.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package oplcli
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseCases(t *testing.T) {
|
||||
var testData = []struct {
|
||||
name string
|
||||
content []byte
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "SLUS with underscore and dot",
|
||||
content: []byte("Some binary data\x00\x00SLUS_123.45\x00\x00more data"),
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
name: "SLUS with hyphen",
|
||||
content: []byte("\x00\x00\x00SLUS-12345\x00\x00\x00"),
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
name: "SLES format",
|
||||
content: []byte("Header data\x00SLES_987.65\x00footer"),
|
||||
expected: "SLES-98765",
|
||||
},
|
||||
{
|
||||
name: "SLPS format",
|
||||
content: []byte("\xFF\xFESLPS_456.78\x00"),
|
||||
expected: "SLPS-45678",
|
||||
},
|
||||
{
|
||||
name: "SCUS format",
|
||||
content: []byte("SCUS-97512"),
|
||||
expected: "SCUS-97512",
|
||||
},
|
||||
{
|
||||
name: "No separator format",
|
||||
content: []byte("\x00\x00SLUS12345\x00\x00"),
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
name: "With spaces",
|
||||
content: []byte("SLUS 123.45"),
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
name: "No game ID found",
|
||||
content: []byte("Just some random data without any game ID"),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "Invalid game ID format",
|
||||
content: []byte("SLUS-ABC.DE"),
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testData {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gameID, found := scanBufferForID(tt.content)
|
||||
|
||||
if tt.expected == "" && found {
|
||||
t.Errorf("Found game id where none should be found: %s", gameID)
|
||||
}
|
||||
|
||||
if tt.expected == "" && !found {
|
||||
return
|
||||
}
|
||||
|
||||
if tt.expected != gameID {
|
||||
t.Errorf("Expected %s got %s", tt.expected, gameID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalize(t *testing.T) {
|
||||
testData := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
input: "SLUS-12345",
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
input: "SLES_987.65",
|
||||
expected: "SLES-98765",
|
||||
},
|
||||
{
|
||||
input: "SLPS_456.78",
|
||||
expected: "SLPS-45678",
|
||||
},
|
||||
{
|
||||
input: "scus-97512",
|
||||
expected: "SCUS-97512",
|
||||
},
|
||||
{
|
||||
input: "SLUS12345",
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
input: "SLUS123.45",
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
{
|
||||
input: "SLUs123.45",
|
||||
expected: "SLUS-12345",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testData {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
normalized := normalizeGameID(tt.input)
|
||||
|
||||
if normalized != tt.expected {
|
||||
t.Errorf("Expected %s got %s", tt.expected, normalized)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user