123 lines
2.4 KiB
Go
123 lines
2.4 KiB
Go
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_123.45",
|
|
},
|
|
{
|
|
name: "SLUS with hyphen",
|
|
content: []byte("\x00\x00\x00SLUS-12345\x00\x00\x00"),
|
|
expected: "SLUS_123.45",
|
|
},
|
|
{
|
|
name: "SLES format",
|
|
content: []byte("Header data\x00SLES_987.65\x00footer"),
|
|
expected: "SLES_987.65",
|
|
},
|
|
{
|
|
name: "SLPS format",
|
|
content: []byte("\xFF\xFESLPS_456.78\x00"),
|
|
expected: "SLPS_456.78",
|
|
},
|
|
{
|
|
name: "SCUS format",
|
|
content: []byte("SCUS-97512"),
|
|
expected: "SCUS_975.12",
|
|
},
|
|
{
|
|
name: "No separator format",
|
|
content: []byte("\x00\x00SLUS12345\x00\x00"),
|
|
expected: "SLUS_123.45",
|
|
},
|
|
{
|
|
name: "With spaces",
|
|
content: []byte("SLUS 123.45"),
|
|
expected: "SLUS_123.45",
|
|
},
|
|
{
|
|
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_123.45",
|
|
},
|
|
{
|
|
input: "SLES_987.65",
|
|
expected: "SLES_987.65",
|
|
},
|
|
{
|
|
input: "SLPS_456.78",
|
|
expected: "SLPS_456.78",
|
|
},
|
|
{
|
|
input: "scus-97512",
|
|
expected: "SCUS_975.12",
|
|
},
|
|
{
|
|
input: "SLUS12345",
|
|
expected: "SLUS_123.45",
|
|
},
|
|
{
|
|
input: "SLUS123.45",
|
|
expected: "SLUS_123.45",
|
|
},
|
|
{
|
|
input: "SLUs123.45",
|
|
expected: "SLUS_123.45",
|
|
},
|
|
}
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|