From 08d2d528c7f2bf07ec634b9981e74650f28c2896 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Mon, 5 Jan 2026 14:49:48 +0100 Subject: [PATCH] added test for game scanning --- internal/gamefile_test.go | 122 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 internal/gamefile_test.go diff --git a/internal/gamefile_test.go b/internal/gamefile_test.go new file mode 100644 index 0000000..3f65c35 --- /dev/null +++ b/internal/gamefile_test.go @@ -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) + } + }) + } +}