package ass import ( "testing" "sub-cli/internal/model" ) func TestParseASSTimestamp(t *testing.T) { testCases := []struct { name string input string expected model.Timestamp }{ { name: "Standard format", input: "0:00:01.00", expected: model.Timestamp{Hours: 0, Minutes: 0, Seconds: 1, Milliseconds: 0}, }, { name: "With centiseconds", input: "0:00:01.50", expected: model.Timestamp{Hours: 0, Minutes: 0, Seconds: 1, Milliseconds: 500}, }, { name: "Complete hours, minutes, seconds", input: "1:02:03.45", expected: model.Timestamp{Hours: 1, Minutes: 2, Seconds: 3, Milliseconds: 450}, }, { name: "Invalid format", input: "invalid", expected: model.Timestamp{}, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { result := parseASSTimestamp(tc.input) if result != tc.expected { t.Errorf("For input '%s', expected %+v, got %+v", tc.input, tc.expected, result) } }) } } func TestFormatASSTimestamp(t *testing.T) { testCases := []struct { name string input model.Timestamp expected string }{ { name: "Zero timestamp", input: model.Timestamp{}, expected: "0:00:00.00", }, { name: "Simple seconds", input: model.Timestamp{Hours: 0, Minutes: 0, Seconds: 1, Milliseconds: 0}, expected: "0:00:01.00", }, { name: "With milliseconds", input: model.Timestamp{Hours: 0, Minutes: 0, Seconds: 1, Milliseconds: 500}, expected: "0:00:01.50", }, { name: "Complete timestamp", input: model.Timestamp{Hours: 1, Minutes: 2, Seconds: 3, Milliseconds: 450}, expected: "1:02:03.45", }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { result := formatASSTimestamp(tc.input) if result != tc.expected { t.Errorf("For timestamp %+v, expected '%s', got '%s'", tc.input, tc.expected, result) } }) } } func TestSplitCSV(t *testing.T) { testCases := []struct { name string input string expected []string }{ { name: "Simple CSV", input: "Value1, Value2, Value3", expected: []string{"Value1", "Value2", "Value3"}, }, { name: "Text field with commas", input: "0, 00:00:01.00, 00:00:05.00, Default, Name, 0, 0, 0, Effect, Text with, commas", expected: []string{"0", "00:00:01.00", "00:00:05.00", "Default", "Name", "0", "0", "0", "Effect", "Text with, commas"}, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { result := splitCSV(tc.input) // Check result length if len(result) != len(tc.expected) { t.Errorf("Expected %d values, got %d: %v", len(tc.expected), len(result), result) return } // Check content for i := range result { if result[i] != tc.expected[i] { t.Errorf("At index %d, expected '%s', got '%s'", i, tc.expected[i], result[i]) } } }) } } func TestParseFormatLine(t *testing.T) { input := " Name, Fontname, Fontsize, PrimaryColour" expected := []string{"Name", "Fontname", "Fontsize", "PrimaryColour"} result := parseFormatLine(input) if len(result) != len(expected) { t.Errorf("Expected %d values, got %d: %v", len(expected), len(result), result) return } for i := range result { if result[i] != expected[i] { t.Errorf("At index %d, expected '%s', got '%s'", i, expected[i], result[i]) } } }