215 lines
5.4 KiB
Go
215 lines
5.4 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
"strings"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestNewASSFile(t *testing.T) {
|
|
assFile := NewASSFile()
|
|
|
|
// Test that script info is initialized with defaults
|
|
if assFile.ScriptInfo == nil {
|
|
t.Error("Expected ScriptInfo map to be initialized")
|
|
}
|
|
|
|
// Check default script info values
|
|
expectedDefaults := map[string]string{
|
|
"ScriptType": "v4.00+",
|
|
"Collisions": "Normal",
|
|
"PlayResX": "640",
|
|
"PlayResY": "480",
|
|
"Timer": "100.0000",
|
|
}
|
|
|
|
for key, expectedValue := range expectedDefaults {
|
|
if value, exists := assFile.ScriptInfo[key]; !exists || value != expectedValue {
|
|
t.Errorf("Expected default ScriptInfo[%s] = %s, got %s", key, expectedValue, value)
|
|
}
|
|
}
|
|
|
|
// Test that styles are initialized
|
|
if assFile.Styles == nil {
|
|
t.Error("Expected Styles slice to be initialized")
|
|
}
|
|
|
|
// Test that at least the Default style exists
|
|
if len(assFile.Styles) < 1 {
|
|
t.Error("Expected at least Default style to be created")
|
|
} else {
|
|
defaultStyleFound := false
|
|
for _, style := range assFile.Styles {
|
|
if style.Name == "Default" {
|
|
defaultStyleFound = true
|
|
|
|
// Check the style properties of the default style
|
|
styleStr, exists := style.Properties["Style"]
|
|
if !exists {
|
|
t.Error("Expected Default style to have a Style property, but it wasn't found")
|
|
} else if !strings.Contains(styleStr, ",0,0,0,0,") { // Check that Bold, Italic, Underline, StrikeOut are all 0
|
|
t.Errorf("Expected Default style to have Bold/Italic/Underline/StrikeOut set to 0, got: %s", styleStr)
|
|
}
|
|
|
|
break
|
|
}
|
|
}
|
|
|
|
if !defaultStyleFound {
|
|
t.Error("Expected to find a Default style")
|
|
}
|
|
}
|
|
|
|
// Test that events are initialized as an empty slice
|
|
if assFile.Events == nil {
|
|
t.Error("Expected Events slice to be initialized")
|
|
}
|
|
|
|
if len(assFile.Events) != 0 {
|
|
t.Errorf("Expected 0 events, got %d", len(assFile.Events))
|
|
}
|
|
}
|
|
|
|
func TestNewASSEvent(t *testing.T) {
|
|
event := NewASSEvent()
|
|
|
|
// Test default type
|
|
if event.Type != "Dialogue" {
|
|
t.Errorf("Expected Type to be 'Dialogue', got '%s'", event.Type)
|
|
}
|
|
|
|
// Test default layer
|
|
if event.Layer != 0 {
|
|
t.Errorf("Expected Layer to be 0, got %d", event.Layer)
|
|
}
|
|
|
|
// Test default style
|
|
if event.Style != "Default" {
|
|
t.Errorf("Expected Style to be 'Default', got '%s'", event.Style)
|
|
}
|
|
|
|
// Test default name
|
|
if event.Name != "" {
|
|
t.Errorf("Expected Name to be empty, got '%s'", event.Name)
|
|
}
|
|
|
|
// Test default margins
|
|
if event.MarginL != 0 || event.MarginR != 0 || event.MarginV != 0 {
|
|
t.Errorf("Expected all margins to be 0, got L:%d, R:%d, V:%d",
|
|
event.MarginL, event.MarginR, event.MarginV)
|
|
}
|
|
|
|
// Test default effect
|
|
if event.Effect != "" {
|
|
t.Errorf("Expected Effect to be empty, got '%s'", event.Effect)
|
|
}
|
|
|
|
// Test default text
|
|
if event.Text != "" {
|
|
t.Errorf("Expected Text to be empty, got '%s'", event.Text)
|
|
}
|
|
|
|
// Test start and end times
|
|
zeroTime := Timestamp{}
|
|
if event.StartTime != zeroTime {
|
|
t.Errorf("Expected start time to be zero, got %+v", event.StartTime)
|
|
}
|
|
|
|
if event.EndTime != zeroTime {
|
|
t.Errorf("Expected end time to be zero, got %+v", event.EndTime)
|
|
}
|
|
}
|