use ass_core::Script;
#[cfg(test)]
mod parser_main_edge_paths {
use super::*;
#[test]
fn test_input_size_limit_exceeded() {
let input = "a".repeat(1024); let result = Script::parse(&input);
assert!(result.is_ok());
}
#[test]
fn test_bom_validation_warning() {
let input_with_invalid_bom = "\u{FFFE}[Script Info]\nTitle: Test"; let result = Script::parse(input_with_invalid_bom);
if let Ok(script) = result {
let has_bom_warning = script
.issues()
.iter()
.any(|issue| issue.message.contains("BOM") || issue.message.contains("validation"));
let _ = has_bom_warning;
} else {
}
}
#[test]
fn test_section_parse_error_handling() {
let input = "[Script Info]\nMalformed: field: with: too: many: colons:";
let result = Script::parse(input);
if let Ok(script) = result {
let _has_issues = !script.issues().is_empty();
} else {
}
}
#[test]
fn test_unknown_section_handling() {
let input = "[Unknown Section]\nSome content\n\n[Script Info]\nTitle: Test";
let result = Script::parse(input);
if let Ok(script) = result {
let has_unknown_warning = script.issues().iter().any(|issue| {
issue.message.contains("Unknown") || issue.message.contains("section")
});
let _ = has_unknown_warning;
} else {
}
}
#[test]
fn test_unclosed_section_header() {
let input = "[Script Info\nTitle: Test";
let result = Script::parse(input);
match result {
Ok(script) => {
assert!(!script.issues().is_empty());
}
Err(e) => {
assert!(e.to_string().contains("Unclosed") || e.to_string().contains("section"));
}
}
}
#[test]
fn test_script_info_section_parsing() {
let input = r"[Script Info]
Title: Test Script
ScriptType: v4.00+
PlayResX: 1920
PlayResY: 1080";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_v4_plus_styles_section_parsing() {
let input = r"[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&H00ffffff,&H000000ff,&H00000000,&H80000000,0,0,0,0,100,100,0,0,1,0,0,2,10,10,10,1";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_v4_styles_section_parsing() {
let input = r"[V4 Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Arial,16,16777215,255,0,0,0,0,1,0,0,2,10,10,10,0,1";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_events_section_parsing() {
let input = r"[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Hello World";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_multiple_sections_parsing() {
let input = r"[Script Info]
Title: Test Script
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&H00ffffff,&H000000ff,&H00000000,&H80000000,0,0,0,0,100,100,0,0,1,0,0,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Hello World";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(script.sections().len() >= 3);
}
#[test]
fn test_section_parsing_with_errors() {
let input = r"[Script Info]
Title: Test
InvalidField
[V4+ Styles]
Format: Name
Style: Incomplete
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: Malformed dialogue line";
let result = Script::parse(input);
if let Ok(script) = result {
assert!(!script.issues().is_empty());
} else {
}
}
#[test]
fn test_empty_section_content() {
let input = r"[Script Info]
[V4+ Styles]
[Events]
";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_version_detection_from_script_info() {
let input = r"[Script Info]
ScriptType: v4.00+
Title: Test";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(matches!(
script.version(),
ass_core::ScriptVersion::AssV4
| ass_core::ScriptVersion::AssV4Plus
| ass_core::ScriptVersion::SsaV4
));
}
#[test]
fn test_skip_to_next_section_functionality() {
let input = r"[Malformed Section
This content should be skipped
[Script Info]
Title: Test";
let result = Script::parse(input);
if let Ok(script) = result {
let has_script_info = script.sections().iter().any(|_section| {
true
});
let _ = has_script_info;
} else {
}
}
#[test]
fn test_issue_severity_classification() {
let input = r"[Unknown Section]
Content
[Script Info]
Title: Test";
let result = Script::parse(input);
if let Ok(script) = result {
for issue in script.issues() {
assert!(matches!(
issue.severity,
ass_core::parser::IssueSeverity::Warning
| ass_core::parser::IssueSeverity::Error
| ass_core::parser::IssueSeverity::Info
| ass_core::parser::IssueSeverity::Critical
));
}
} else {
}
}
#[test]
fn test_position_and_line_tracking() {
let input = "Line 1\nLine 2\n[Script Info]\nTitle: Test\nLine 5";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(!script.sections().is_empty());
}
#[test]
fn test_format_detection_and_storage() {
let input = r"[V4+ Styles]
Format: Name, Fontname, Fontsize
Style: Default,Arial,16
[Events]
Format: Layer, Start, End, Style, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,Hello";
let result = Script::parse(input);
assert!(result.is_ok());
let script = result.unwrap();
assert!(script.sections().len() >= 2);
}
#[test]
fn test_binary_data_in_input() {
let input = "Valid text\0\u{00FF}\u{00FE}[Script Info]\nTitle: Test";
let result = Script::parse(input);
if let Ok(_script) = result {
} else {
}
}
}