use ass_core::{
parser::{IssueCategory, IssueSeverity},
Script,
};
#[test]
fn test_malformed_section_error_recovery() {
let malformed_script = r"
[Script Info]
Title: Test
[Malformed Section
This section has no closing bracket
[Events]
Format: Start, End, Style, Text
Dialogue: 0:00:00.00,0:00:05.00,Default,Test
";
let script = Script::parse(malformed_script).expect("Script parsing should work");
assert!(script
.issues()
.iter()
.any(|issue| { matches!(issue.category, IssueCategory::Structure) }));
assert!(!script.sections().is_empty());
}
#[test]
fn test_expected_section_header_error() {
let script_no_bracket = r"
Script Info]
Title: Test
";
let script = Script::parse(script_no_bracket).expect("Script parsing should work");
assert!(script
.issues()
.iter()
.any(|issue| matches!(issue.severity, IssueSeverity::Error)));
}
#[test]
fn test_unclosed_section_header_error() {
let script_unclosed = r"
[Script Info
Title: Test
";
let script = Script::parse(script_unclosed).expect("Script parsing should work");
assert!(script
.issues()
.iter()
.any(|issue| matches!(issue.severity, IssueSeverity::Error)));
}
#[test]
fn test_abrupt_file_ending() {
let truncated_script = "[Script Info]\nTitle: Test\n[Events";
let script = Script::parse(truncated_script).expect("Script parsing should work");
assert!(script
.issues()
.iter()
.any(|issue| matches!(issue.severity, IssueSeverity::Error)));
}
#[test]
fn test_empty_section_name() {
let empty_section = "[]";
let script = Script::parse(empty_section).expect("Script parsing should work");
assert!(!script.issues().is_empty());
}
#[test]
fn test_whitespace_only_section_name() {
let whitespace_section = "[ \t ]";
let script = Script::parse(whitespace_section).expect("Script parsing should work");
assert!(!script.issues().is_empty());
}