use ass_core::{
parser::IssueCategory,
utils::errors::{encoding::validate_bom_handling, resource::check_input_size_limit},
Script,
};
#[cfg(not(feature = "std"))]
use alloc::string::String;
#[test]
fn test_input_size_limit_exceeded() {
const TEST_LIMIT: usize = 1024;
let large_source = "x".repeat(TEST_LIMIT + 1);
let result = check_input_size_limit(large_source.len(), TEST_LIMIT);
assert!(result.is_err());
let normal_script = "[Script Info]\nTitle: Test\n[Events]\nDialogue: 0:00:00.00,0:00:05.00,Default,,0,0,0,,Test";
let script = Script::parse(normal_script).expect("Script parsing should work");
assert!(!script
.issues()
.iter()
.any(|issue| matches!(issue.category, IssueCategory::Security)));
}
#[test]
#[allow(clippy::similar_names)]
fn test_invalid_bom_handling() {
let utf16_le_bytes = [0xFF, 0xFE, b'[', b'S', 0x00, b'c', 0x00];
let result = validate_bom_handling(&utf16_le_bytes);
assert!(result.is_err());
let utf16_be_bytes = [0xFE, 0xFF, 0x00, b'[', 0x00, b'S'];
let result = validate_bom_handling(&utf16_be_bytes);
assert!(result.is_err());
let malformed_bom = [0xEF, 0xBB, b'X']; let result = validate_bom_handling(&malformed_bom);
assert!(result.is_err());
let source_with_utf16_bom = String::from_utf8_lossy(&utf16_le_bytes);
let script = Script::parse(&source_with_utf16_bom).expect("Script parsing should work");
assert!(script
.issues()
.iter()
.any(|issue| matches!(issue.category, IssueCategory::Format)));
}