100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNewSubtitle(t *testing.T) {
|
|
subtitle := NewSubtitle()
|
|
|
|
if subtitle.Format != "" {
|
|
t.Errorf("Expected empty format, got %s", subtitle.Format)
|
|
}
|
|
|
|
if subtitle.Title != "" {
|
|
t.Errorf("Expected empty title, got %s", subtitle.Title)
|
|
}
|
|
|
|
if len(subtitle.Entries) != 0 {
|
|
t.Errorf("Expected 0 entries, got %d", len(subtitle.Entries))
|
|
}
|
|
|
|
if subtitle.Metadata == nil {
|
|
t.Error("Expected metadata map to be initialized")
|
|
}
|
|
|
|
if subtitle.Styles == nil {
|
|
t.Error("Expected styles map to be initialized")
|
|
}
|
|
}
|
|
|
|
func TestNewSubtitleEntry(t *testing.T) {
|
|
entry := NewSubtitleEntry()
|
|
|
|
if entry.Index != 0 {
|
|
t.Errorf("Expected index 0, got %d", entry.Index)
|
|
}
|
|
|
|
if entry.StartTime.Hours != 0 || entry.StartTime.Minutes != 0 ||
|
|
entry.StartTime.Seconds != 0 || entry.StartTime.Milliseconds != 0 {
|
|
t.Errorf("Expected zero start time, got %+v", entry.StartTime)
|
|
}
|
|
|
|
if entry.EndTime.Hours != 0 || entry.EndTime.Minutes != 0 ||
|
|
entry.EndTime.Seconds != 0 || entry.EndTime.Milliseconds != 0 {
|
|
t.Errorf("Expected zero end time, got %+v", entry.EndTime)
|
|
}
|
|
|
|
if entry.Text != "" {
|
|
t.Errorf("Expected empty text, got %s", entry.Text)
|
|
}
|
|
|
|
if entry.Metadata == nil {
|
|
t.Error("Expected metadata map to be initialized")
|
|
}
|
|
|
|
if entry.Styles == nil {
|
|
t.Error("Expected styles map to be initialized")
|
|
}
|
|
|
|
if entry.FormatData == nil {
|
|
t.Error("Expected formatData map to be initialized")
|
|
}
|
|
|
|
if entry.Classes == nil {
|
|
t.Error("Expected classes slice to be initialized")
|
|
}
|
|
}
|
|
|
|
func TestNewSubtitleRegion(t *testing.T) {
|
|
// Test with empty ID
|
|
region := NewSubtitleRegion("")
|
|
|
|
if region.ID != "" {
|
|
t.Errorf("Expected empty ID, got %s", region.ID)
|
|
}
|
|
|
|
if region.Settings == nil {
|
|
t.Error("Expected settings map to be initialized")
|
|
}
|
|
|
|
// Test with a specific ID
|
|
testID := "region1"
|
|
region = NewSubtitleRegion(testID)
|
|
|
|
if region.ID != testID {
|
|
t.Errorf("Expected ID %s, got %s", testID, region.ID)
|
|
}
|
|
|
|
// Verify the settings map is initialized and can store values
|
|
region.Settings["width"] = "100%"
|
|
region.Settings["lines"] = "3"
|
|
|
|
if val, ok := region.Settings["width"]; !ok || val != "100%" {
|
|
t.Errorf("Expected settings to contain width=100%%, got %s", val)
|
|
}
|
|
|
|
if val, ok := region.Settings["lines"]; !ok || val != "3" {
|
|
t.Errorf("Expected settings to contain lines=3, got %s", val)
|
|
}
|
|
}
|