feat: basic ass processing (without style)
This commit is contained in:
parent
8897d7ae90
commit
ebbf516689
10 changed files with 2301 additions and 808 deletions
|
@ -2,6 +2,7 @@ package model
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func TestNewSubtitle(t *testing.T) {
|
||||
|
@ -98,3 +99,117 @@ func TestNewSubtitleRegion(t *testing.T) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue