ass-core 0.1.1

High-performance ASS subtitle format parser and analyzer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
//! Benchmark utilities for generating synthetic ASS scripts
//!
//! This module provides generators for creating test ASS scripts with varying
//! complexity levels, used primarily for benchmarking parser performance.
//! All generators produce valid ASS format strings that can be parsed by
//! the core parser.

#[cfg(not(feature = "std"))]
extern crate alloc;
use crate::parser::{
    ast::{EventType, Span},
    Event,
};
#[cfg(not(feature = "std"))]
use alloc::{
    fmt::Write,
    format,
    string::{String, ToString},
    vec::Vec,
};
#[cfg(feature = "std")]
use std::fmt::Write;

/// Synthetic ASS script generator for benchmarking
pub struct ScriptGenerator {
    /// Script title for metadata
    pub title: String,
    /// Number of styles to generate
    pub styles_count: usize,
    /// Number of events to generate
    pub events_count: usize,
    /// Complexity level for generated content
    pub complexity_level: ComplexityLevel,
}

/// Script complexity levels for testing
#[derive(Debug, Clone, Copy)]
pub enum ComplexityLevel {
    /// Simple text with minimal formatting
    Simple,
    /// Moderate formatting and some animations
    Moderate,
    /// Heavy animations, complex styling, karaoke
    Complex,
    /// Extreme complexity to stress-test parser
    Extreme,
    /// Anime subtitles - heavy styling and effects
    AnimeRealistic,
    /// Movie subtitles - simple, timing-focused
    MovieRealistic,
    /// Karaoke files - complex animations and timing
    KaraokeRealistic,
    /// Sign translations - positioning and styling
    SignRealistic,
    /// Educational content - long dialogues and formatting
    EducationalRealistic,
}

impl ScriptGenerator {
    /// Create generator for simple scripts
    #[must_use]
    pub fn simple(events_count: usize) -> Self {
        Self {
            title: "Simple Benchmark Script".to_string(),
            styles_count: 1,
            events_count,
            complexity_level: ComplexityLevel::Simple,
        }
    }

    /// Create generator for moderate complexity scripts
    #[must_use]
    pub fn moderate(events_count: usize) -> Self {
        Self {
            title: "Moderate Benchmark Script".to_string(),
            styles_count: 5,
            events_count,
            complexity_level: ComplexityLevel::Moderate,
        }
    }

    /// Create generator for complex scripts
    #[must_use]
    pub fn complex(events_count: usize) -> Self {
        Self {
            title: "Complex Benchmark Script".to_string(),
            styles_count: 10,
            events_count,
            complexity_level: ComplexityLevel::Complex,
        }
    }

    /// Create generator for extreme complexity scripts
    #[must_use]
    pub fn extreme(events_count: usize) -> Self {
        Self {
            title: "Extreme Benchmark Script".to_string(),
            styles_count: 20,
            events_count,
            complexity_level: ComplexityLevel::Extreme,
        }
    }

    /// Create generator for anime-style subtitles
    #[must_use]
    pub fn anime_realistic(events_count: usize) -> Self {
        Self {
            title: "Anime Subtitles".to_string(),
            styles_count: 15,
            events_count,
            complexity_level: ComplexityLevel::AnimeRealistic,
        }
    }

    /// Create generator for movie subtitles
    #[must_use]
    pub fn movie_realistic(events_count: usize) -> Self {
        Self {
            title: "Movie Subtitles".to_string(),
            styles_count: 3,
            events_count,
            complexity_level: ComplexityLevel::MovieRealistic,
        }
    }

    /// Create generator for karaoke files
    #[must_use]
    pub fn karaoke_realistic(events_count: usize) -> Self {
        Self {
            title: "Karaoke Script".to_string(),
            styles_count: 8,
            events_count,
            complexity_level: ComplexityLevel::KaraokeRealistic,
        }
    }

    /// Create generator for sign translation subtitles
    #[must_use]
    pub fn sign_realistic(events_count: usize) -> Self {
        Self {
            title: "Sign Translation".to_string(),
            styles_count: 12,
            events_count,
            complexity_level: ComplexityLevel::SignRealistic,
        }
    }

    /// Create generator for educational content
    #[must_use]
    pub fn educational_realistic(events_count: usize) -> Self {
        Self {
            title: "Educational Content".to_string(),
            styles_count: 6,
            events_count,
            complexity_level: ComplexityLevel::EducationalRealistic,
        }
    }

    /// Generate complete ASS script as string
    #[must_use]
    pub fn generate(&self) -> String {
        let mut script =
            String::with_capacity(1000 + (self.styles_count * 200) + (self.events_count * 150));

        // Script Info section
        script.push_str(&self.generate_script_info());
        script.push('\n');

        // V4+ Styles section
        script.push_str(&self.generate_styles());
        script.push('\n');

        // Events section
        script.push_str(&self.generate_events());

        script
    }

    /// Generate Script Info section
    fn generate_script_info(&self) -> String {
        format!(
            r"[Script Info]
Title: {}
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
PlayResX: 1920
PlayResY: 1080",
            self.title
        )
    }

    /// Generate V4+ Styles section
    fn generate_styles(&self) -> String {
        let mut styles = String::from(
            "[V4+ Styles]\n\
            Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n"
        );

        for i in 0..self.styles_count {
            let style_name_string;
            let style_name = if i == 0 {
                "Default"
            } else {
                style_name_string = format!("Style{i}");
                &style_name_string
            };
            let fontsize = 20 + (i * 2);
            let color = format!("&H00{:06X}&", i * 0x0011_1111);

            writeln!(
                styles,
                "Style: {style_name},Arial,{fontsize},{color},{color},{color},&H00000000&,0,0,0,0,100,100,0,0,1,2,0,2,10,10,10,1"
            ).unwrap();
        }

        styles
    }

    /// Generate Events section
    fn generate_events(&self) -> String {
        let mut events = String::from(
            "[Events]\n\
            Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n",
        );

        for i in 0..self.events_count {
            let start_cs = u32::try_from(i * 3000).unwrap_or(u32::MAX);
            let end_cs = u32::try_from(i * 3000 + 2500).unwrap_or(u32::MAX);
            let start_time = Self::format_time(start_cs); // 3 seconds apart
            let end_time = Self::format_time(end_cs); // 2.5 second duration
            let style = if self.styles_count > 1 {
                format!("Style{}", i % self.styles_count)
            } else {
                "Default".to_string()
            };
            let text = self.generate_dialogue_text(i);

            writeln!(
                events,
                "Dialogue: 0,{start_time},{end_time},{style},Speaker,0,0,0,,{text}"
            )
            .unwrap();
        }

        events
    }

    /// Format time in ASS format (H:MM:SS.cc)
    fn format_time(centiseconds: u32) -> String {
        let hours = centiseconds / 360_000;
        let minutes = (centiseconds % 360_000) / 6_000;
        let seconds = (centiseconds % 6000) / 100;
        let cs = centiseconds % 100;
        format!("{hours}:{minutes:02}:{seconds:02}.{cs:02}")
    }

    /// Generate dialogue text based on complexity level
    fn generate_dialogue_text(&self, event_index: usize) -> String {
        let base_text = format!("This is dialogue line number {}", event_index + 1);

        match self.complexity_level {
            ComplexityLevel::Simple => base_text,
            ComplexityLevel::Moderate => {
                format!(r"{{\b1}}{base_text}{{\b0}} with {{\i1}}some{{\i0}} formatting")
            }
            ComplexityLevel::Complex => {
                format!(
                    r"{{\pos(100,200)\fad(500,500)\b1\i1\c&H00FF00&}}{base_text}{{\b0\i0\c&HFFFFFF&}} with {{\t(0,1000,\frz360)}}animation{{\t(1000,2000,\frz0)}}"
                )
            }
            ComplexityLevel::Extreme => {
                format!(
                    r"{{\pos(100,200)\move(100,200,500,400)\fad(300,300)\t(0,500,\fscx120\fscy120)\t(500,1000,\fscx100\fscy100)\b1\i1\u1\s1\bord2\shad2\c&H00FF00&\3c&H0000FF&\4c&H000000&\alpha&H00\3a&H80}}{base_text}{{\b0\i0\u0\s0\r}} {{\k50}}with {{\k30}}karaoke {{\k40}}timing {{\k60}}and {{\k45}}complex {{\k35}}animations"
                )
            }
            ComplexityLevel::AnimeRealistic => {
                Self::generate_anime_dialogue(event_index, &base_text)
            }
            ComplexityLevel::MovieRealistic => {
                Self::generate_movie_dialogue(event_index, &base_text)
            }
            ComplexityLevel::KaraokeRealistic => {
                Self::generate_karaoke_dialogue(event_index, &base_text)
            }
            ComplexityLevel::SignRealistic => Self::generate_sign_dialogue(event_index, &base_text),
            ComplexityLevel::EducationalRealistic => {
                Self::generate_educational_dialogue(event_index, &base_text)
            }
        }
    }

    /// Generate anime-style dialogue with heavy effects
    fn generate_anime_dialogue(event_index: usize, base_text: &str) -> String {
        let patterns = [
            // Character speaking with glow effect
            format!(
                r"{{\an8\pos(960,80)\fad(250,250)\bord3\shad0\c&H00FFFFFF&\3c&H00FF8C00&}}{base_text}"
            ),
            // Thought bubble with transparency
            format!(
                r"{{\an5\pos(960,540)\fad(500,500)\alpha&H80&\bord2\c&H00E6E6FA&\3c&H00483D8B&}}{base_text}"
            ),
            // Dramatic effect with color change
            format!(
                r"{{\an2\pos(960,980)\fad(300,800)\b1\bord4\shad3\c&H0000FFFF&\3c&H000000FF&\4c&H00000000&\t(0,2000,\c&H00FF0000&)}}{base_text}"
            ),
            // Side character with positioning
            format!(
                r"{{\an7\pos(200,400)\fad(200,200)\bord2\c&H00FFFFFF&\3c&H00800080&}}{base_text}"
            ),
        ];
        patterns[event_index % patterns.len()].clone()
    }

    /// Generate movie-style dialogue (simple and clean)
    fn generate_movie_dialogue(event_index: usize, base_text: &str) -> String {
        let patterns = [
            // Standard dialogue
            base_text.to_string(),
            // Italic for emphasis
            format!(r"{{\i1}}{base_text}{{\i0}}"),
            // Bold for shouting
            format!(r"{{\b1}}{base_text}{{\b0}}"),
            // Different speaker position
            format!(r"{{\an8}}{base_text}"),
        ];
        patterns[event_index % patterns.len()].clone()
    }

    /// Generate karaoke-style dialogue with timing
    fn generate_karaoke_dialogue(event_index: usize, base_text: &str) -> String {
        let words: Vec<&str> = base_text.split_whitespace().collect();
        let mut karaoke_text = String::new();

        // Add base styling
        karaoke_text.push_str(
            r"{\an5\pos(960,540)\fad(200,200)\b1\bord2\shad1\c&H00FFFFFF&\3c&H00FF6347&}",
        );

        // Add karaoke timing for each word
        for (i, word) in words.iter().enumerate() {
            let timing = 50 + (i * 30); // Varying timing
            write!(karaoke_text, r"{{\k{timing}}}{word} ").unwrap();
        }

        // Add final effect
        if event_index % 3 == 0 {
            karaoke_text.push_str(r"{\t(2000,3000,\fscx120\fscy120\alpha&HFF&)}");
        }

        karaoke_text
    }

    /// Generate sign translation dialogue with positioning
    fn generate_sign_dialogue(event_index: usize, base_text: &str) -> String {
        let positions = [
            // Top signs
            (r"{\an8\pos(960,100)", "RESTAURANT"),
            (r"{\an9\pos(1700,150)", "EXIT"),
            (r"{\an7\pos(220,120)", "HOTEL"),
            // Screen text
            (r"{\an5\pos(960,540)", "NEWS FLASH"),
            // Bottom signs
            (r"{\an2\pos(960,950)", "SUBWAY"),
            // Side signs
            (r"{\an4\pos(100,540)", "STORE"),
        ];

        let (pos_tag, sign_type) = &positions[event_index % positions.len()];
        let sign_text = if base_text.contains("number") {
            format!(
                "{sign_type}: {}",
                base_text.replace("dialogue line", "sign")
            )
        } else {
            (*sign_type).to_string()
        };

        format!(
            r"{pos_tag}\fad(500,500)\bord3\shad2\c&H00000000&\3c&H00FFFFFF&\fn{{Arial}}\fs36}}{sign_text}"
        )
    }

    /// Generate educational content dialogue
    fn generate_educational_dialogue(event_index: usize, base_text: &str) -> String {
        let patterns = [
            // Main content
            format!(
                r"{{\an2\pos(960,900)\fad(200,200)\bord1\c&H00FFFFFF&}}{base_text} - This explains the concept in detail with proper formatting."
            ),
            // Question format
            format!(
                r"{{\an8\pos(960,150)\fad(200,200)\b1\c&H0000FFFF&}}Question {}: {base_text}",
                event_index + 1
            ),
            // Answer format
            format!(r"{{\an7\pos(100,400)\fad(200,200)\i1\c&H0000FF00&}}Answer: {base_text}"),
            // Definition
            format!(
                r"{{\an5\pos(960,540)\fad(200,200)\bord2\c&H00FFFFFF&\3c&H000080FF&}}Definition: {base_text}"
            ),
            // Example
            format!(r"{{\an1\pos(100,900)\fad(200,200)\c&H00FFFF00&}}Example: {base_text}"),
            // Summary
            format!(r"{{\an9\pos(1700,100)\fad(200,200)\b1\c&H00FF8000&}}Summary: {base_text}"),
        ];
        patterns[event_index % patterns.len()].clone()
    }
}

/// Create a test event with the given parameters
///
/// This is a convenience function for creating `Event` instances in tests
/// and benchmarks without having to specify all the fields manually.
///
/// # Examples
///
/// ```
/// use ass_core::utils::benchmark_generators::create_test_event;
///
/// let event = create_test_event("0:00:00.00", "0:00:05.00", "Hello world");
/// assert_eq!(event.text, "Hello world");
/// ```
#[must_use]
pub const fn create_test_event<'a>(start: &'a str, end: &'a str, text: &'a str) -> Event<'a> {
    Event {
        event_type: EventType::Dialogue,
        layer: "0",
        start,
        end,
        style: "Default",
        name: "",
        margin_l: "0",
        margin_r: "0",
        margin_v: "0",
        margin_t: None,
        margin_b: None,
        effect: "",
        text,
        span: Span::new(0, 0, 0, 0),
    }
}

/// Generate script with intentional issues for linting benchmarks
///
/// Creates an ASS script containing various problematic patterns that
/// linting rules should detect, such as empty tags, unknown tags, and
/// performance-heavy animations.
///
/// # Arguments
///
/// * `event_count` - Number of events to generate in the script
///
/// # Returns
///
/// A complete ASS script string with intentional issues for testing
/// linting performance and accuracy.
#[must_use]
pub fn generate_script_with_issues(event_count: usize) -> String {
    let mut script = String::from(
        "[Script Info]\n\
        Title: Test Script\n\n\
        [V4+ Styles]\n\
        Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n\
        Style: Default,Arial,20,&H00FFFFFF&,&H000000FF&,&H00000000&,&H00000000&,0,0,0,0,100,100,0,0,1,2,0,2,10,10,10,1\n\n\
        [Events]\n\
        Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n"
    );

    for i in 0..event_count {
        let start_time = format!("0:{:02}:{:02}.00", i / 60, i % 60);
        let end_time = format!("0:{:02}:{:02}.50", i / 60, i % 60);

        // Add some problematic content every 10th event
        let text_string;
        let text = if i % 10 == 0 {
            r"Text with {\} empty tag and {\invalidtag} unknown tag"
        } else if i % 7 == 0 {
            // Very complex animation that might cause performance issues
            r"{\pos(100,200)\move(100,200,500,400,0,5000)\t(0,1000,\frz360)\t(1000,2000,\fscx200\fscy200)\t(2000,3000,\alpha&HFF&)\t(3000,4000,\alpha&H00&)\t(4000,5000,\c&HFF0000&)}Performance heavy animation"
        } else {
            let line_num = i + 1;
            text_string = format!("Normal dialogue line {line_num}");
            &text_string
        };

        writeln!(
            script,
            "Dialogue: 0,{start_time},{end_time},Default,Speaker,0,0,0,,{text}"
        )
        .unwrap();
    }

    script
}

/// Generate script with overlapping events for timing analysis benchmarks
///
/// Creates an ASS script where events have overlapping time ranges,
/// useful for testing overlap detection algorithms and timing analysis
/// performance.
///
/// # Arguments
///
/// * `event_count` - Number of overlapping events to generate
///
/// # Returns
///
/// A complete ASS script string with overlapping dialogue events.
#[must_use]
pub fn generate_overlapping_script(event_count: usize) -> String {
    let mut script = String::from(
        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,20,&H00FFFFFF,&H000000FF,&H00000000,&H80000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
",
    );

    for i in 0..event_count {
        // Create overlapping events: each event overlaps with several others
        let start_time = i * 2; // 2 second intervals
        let end_time = start_time + 5; // 5 second duration (overlaps next 2-3 events)
        writeln!(
            &mut script,
            "Dialogue: 0,0:{:02}:{:02}.00,0:{:02}:{:02}.00,Default,,0,0,0,,Event {} text",
            start_time / 60,
            start_time % 60,
            end_time / 60,
            end_time % 60,
            i
        )
        .unwrap();
    }

    script
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn script_generator_simple() {
        let generator = ScriptGenerator::simple(5);
        assert_eq!(generator.events_count, 5);
        assert_eq!(generator.styles_count, 1);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::Simple
        ));

        let script = generator.generate();
        assert!(script.contains("[Script Info]"));
        assert!(script.contains("[V4+ Styles]"));
        assert!(script.contains("[Events]"));
        assert!(script.contains("Simple Benchmark Script"));
    }

    #[test]
    fn script_generator_moderate() {
        let generator = ScriptGenerator::moderate(3);
        assert_eq!(generator.events_count, 3);
        assert_eq!(generator.styles_count, 5);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::Moderate
        ));
    }

    #[test]
    fn script_generator_complex() {
        let generator = ScriptGenerator::complex(2);
        assert_eq!(generator.events_count, 2);
        assert_eq!(generator.styles_count, 10);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::Complex
        ));
    }

    #[test]
    fn script_generator_extreme() {
        let generator = ScriptGenerator::extreme(1);
        assert_eq!(generator.events_count, 1);
        assert_eq!(generator.styles_count, 20);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::Extreme
        ));
    }

    #[test]
    fn format_time_zero() {
        assert_eq!(ScriptGenerator::format_time(0), "0:00:00.00");
    }

    #[test]
    fn format_time_basic() {
        assert_eq!(ScriptGenerator::format_time(6150), "0:01:01.50");
    }

    #[test]
    fn format_time_hours() {
        assert_eq!(ScriptGenerator::format_time(360_000), "1:00:00.00");
    }

    #[test]
    fn create_test_event_basic() {
        let event = create_test_event("0:00:00.00", "0:00:05.00", "Test text");
        assert_eq!(event.start, "0:00:00.00");
        assert_eq!(event.end, "0:00:05.00");
        assert_eq!(event.text, "Test text");
        assert_eq!(event.style, "Default");
        assert!(matches!(event.event_type, EventType::Dialogue));
    }

    #[test]
    fn generate_script_with_issues_basic() {
        let script = generate_script_with_issues(5);
        assert!(script.contains("[Script Info]"));
        assert!(script.contains("[V4+ Styles]"));
        assert!(script.contains("[Events]"));
        assert!(script.contains("Dialogue:"));
    }

    #[test]
    fn generate_script_with_issues_contains_problems() {
        let script = generate_script_with_issues(20);
        // Should contain some problematic content
        assert!(script.lines().count() > 10);
        // At least one event should have issues (every 10th event)
        assert!(script.contains("empty tag") || script.contains("unknown tag"));
    }

    #[test]
    fn generate_overlapping_script_basic() {
        let script = generate_overlapping_script(3);
        assert!(script.contains("[V4+ Styles]"));
        assert!(script.contains("[Events]"));
        assert!(script.contains("Event 0 text"));
        assert!(script.contains("Event 1 text"));
        assert!(script.contains("Event 2 text"));
    }

    #[test]
    fn generate_overlapping_script_timing() {
        let script = generate_overlapping_script(2);
        // First event: 0:00:00.00 to 0:00:05.00
        // Second event: 0:00:02.00 to 0:00:07.00 (overlaps with first)
        assert!(script.contains("0:00:00.00"));
        assert!(script.contains("0:00:05.00"));
        assert!(script.contains("0:00:02.00"));
        assert!(script.contains("0:00:07.00"));
    }

    #[test]
    fn dialogue_text_complexity_simple() {
        let generator = ScriptGenerator::simple(1);
        let text = generator.generate_dialogue_text(0);
        assert_eq!(text, "This is dialogue line number 1");
    }

    #[test]
    fn dialogue_text_complexity_moderate() {
        let generator = ScriptGenerator::moderate(1);
        let text = generator.generate_dialogue_text(0);
        assert!(text.contains(r"{\b1}"));
        assert!(text.contains(r"{\i1}"));
        assert!(text.contains("This is dialogue line number 1"));
    }

    #[test]
    fn dialogue_text_complexity_complex() {
        let generator = ScriptGenerator::complex(1);
        let text = generator.generate_dialogue_text(0);
        assert!(text.contains(r"{\pos("));
        assert!(text.contains(r"{\t("));
        assert!(text.contains("animation"));
    }

    #[test]
    fn dialogue_text_complexity_extreme() {
        let generator = ScriptGenerator::extreme(1);
        let text = generator.generate_dialogue_text(0);
        assert!(text.contains(r"{\k"));
        assert!(text.contains("karaoke"));
        assert!(text.contains("animations"));
    }

    #[test]
    fn anime_realistic_generator() {
        let generator = ScriptGenerator::anime_realistic(5);
        assert_eq!(generator.events_count, 5);
        assert_eq!(generator.styles_count, 15);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::AnimeRealistic
        ));

        let script = generator.generate();
        assert!(script.contains("Anime Subtitles"));
    }

    #[test]
    fn movie_realistic_generator() {
        let generator = ScriptGenerator::movie_realistic(3);
        assert_eq!(generator.events_count, 3);
        assert_eq!(generator.styles_count, 3);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::MovieRealistic
        ));
    }

    #[test]
    fn karaoke_realistic_generator() {
        let generator = ScriptGenerator::karaoke_realistic(2);
        assert_eq!(generator.events_count, 2);
        assert_eq!(generator.styles_count, 8);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::KaraokeRealistic
        ));

        let text = generator.generate_dialogue_text(0);
        assert!(text.contains(r"{\k"));
    }

    #[test]
    fn sign_realistic_generator() {
        let generator = ScriptGenerator::sign_realistic(4);
        assert_eq!(generator.events_count, 4);
        assert_eq!(generator.styles_count, 12);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::SignRealistic
        ));

        let text = generator.generate_dialogue_text(0);
        assert!(text.contains(r"{\pos(") || text.contains(r"{\an"));
    }

    #[test]
    fn educational_realistic_generator() {
        let generator = ScriptGenerator::educational_realistic(6);
        assert_eq!(generator.events_count, 6);
        assert_eq!(generator.styles_count, 6);
        assert!(matches!(
            generator.complexity_level,
            ComplexityLevel::EducationalRealistic
        ));

        let text = generator.generate_dialogue_text(1);
        assert!(
            text.contains("Question") || text.contains("Answer") || text.contains("Definition")
        );
    }

    #[test]
    fn script_generator_generate_has_correct_event_count() {
        let generator = ScriptGenerator::simple(3);
        let script = generator.generate();
        assert_eq!(
            script
                .lines()
                .filter(|line| line.starts_with("Dialogue:"))
                .count(),
            3
        );
    }

    #[test]
    fn script_generator_generate_has_correct_style_count() {
        let generator = ScriptGenerator::moderate(1); // 5 styles
        let script = generator.generate();
        assert_eq!(
            script
                .lines()
                .filter(|line| line.starts_with("Style:"))
                .count(),
            5
        );
    }
}