lottie-rs 0.2.17

A simple yet powerful Fountain screenplay editor
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
// This file is part of Lottie.
//
// Copyright (c) 2026  René Coignard <contact@renecoignard.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use regex::Regex;
use std::sync::LazyLock;

use crate::types::LineType;

static META_KEY_RE: LazyLock<Regex> =
    LazyLock::new(|| Regex::new(r"^([\p{L}][\p{L}\s]*):\s*").unwrap());

/// Stateless Fountain markup language parser.
///
/// The parser classifies every line of a Fountain document as a [`LineType`]
/// variant.  It understands the full Fountain specification including:
///
/// - Title-page metadata blocks
/// - Scene headings (standard prefixes and forced `.HEADING`)
/// - Character cues and dual-dialogue (`^`)
/// - Dialogue, parentheticals
/// - Transitions (uppercase + colon, `FADE OUT.`, forced `>`)
/// - Centred text (`>text<`)
/// - Lyrics (`~`), sections (`#`), synopses (`=`)
/// - Boneyard (`/* ... */`) and notes (`[[ ... ]]`) spanning multiple lines
/// - Page breaks (`===`)
/// - Forced action (`!`) and shots (`!!`)
///
/// All methods are associated functions; no state is maintained between calls.
pub struct Parser;

impl Parser {
    /// Classifies every line in `lines` and returns a parallel `Vec<LineType>`.
    ///
    /// The returned vector has the same length as `lines`.  The parser is
    /// context-sensitive: the type assigned to a line may depend on the types of
    /// preceding lines (e.g. dialogue follows a character cue, parentheticals
    /// follow dialogue).
    ///
    /// Multi-line boneyard and note spans are tracked via internal flags so that
    /// their constituent lines are correctly tagged even across blank lines.
    pub fn parse(lines: &[String]) -> Vec<LineType> {
        let mut types = vec![LineType::Empty; lines.len()];

        let mut in_header = false;
        for line in lines {
            let trim = line.trim();
            if trim.is_empty() {
                continue;
            }
            if META_KEY_RE.is_match(trim) && !Self::is_transition_format(trim) {
                in_header = true;
            }
            break;
        }

        let mut in_boneyard = false;
        let mut in_note = false;

        for i in 0..lines.len() {
            let raw = &lines[i];

            if in_header {
                if raw.is_empty() {
                    in_header = false;
                    types[i] = LineType::Empty;
                    continue;
                }

                let trim = raw.trim();
                if trim.is_empty() {
                    if raw.starts_with("  ") || raw.starts_with('\t') {
                        types[i] = LineType::MetadataValue;
                        continue;
                    } else {
                        in_header = false;
                        types[i] = LineType::Empty;
                        continue;
                    }
                }

                if META_KEY_RE.is_match(trim) {
                    if trim.to_lowercase().starts_with("title:") {
                        types[i] = LineType::MetadataTitle;
                    } else {
                        types[i] = LineType::MetadataKey;
                    }
                } else {
                    types[i] = LineType::MetadataValue;
                }
                continue;
            }

            let mut effective = String::new();
            let chars: Vec<char> = raw.chars().collect();
            let mut j = 0;

            let mut boneyard_chars = 0;
            let mut note_chars = 0;
            let mut visible_chars = 0;

            while j < chars.len() {
                if in_boneyard {
                    if j + 1 < chars.len() && chars[j] == '*' && chars[j + 1] == '/' {
                        in_boneyard = false;
                        boneyard_chars += 2;
                        j += 2;
                    } else {
                        boneyard_chars += 1;
                        j += 1;
                    }
                    continue;
                }
                if in_note {
                    if j + 1 < chars.len() && chars[j] == ']' && chars[j + 1] == ']' {
                        in_note = false;
                        note_chars += 2;
                        j += 2;
                    } else {
                        note_chars += 1;
                        j += 1;
                    }
                    continue;
                }

                if j + 1 < chars.len() && chars[j] == '/' && chars[j + 1] == '*' {
                    in_boneyard = true;
                    boneyard_chars += 2;
                    j += 2;
                    continue;
                }
                if j + 1 < chars.len() && chars[j] == '[' && chars[j + 1] == '[' {
                    in_note = true;
                    note_chars += 2;
                    j += 2;
                    continue;
                }

                if !chars[j].is_whitespace() {
                    visible_chars += 1;
                }
                effective.push(chars[j]);
                j += 1;
            }

            let trim = effective.trim();

            if visible_chars == 0 {
                if boneyard_chars > 0 || in_boneyard {
                    types[i] = LineType::Boneyard;
                } else if note_chars > 0 || in_note {
                    types[i] = LineType::Note;
                } else if raw == "  "
                    && i > 0
                    && matches!(
                        types[i - 1],
                        LineType::Character
                            | LineType::DualDialogueCharacter
                            | LineType::Parenthetical
                            | LineType::Dialogue
                    )
                {
                    types[i] = LineType::Dialogue;
                } else {
                    types[i] = LineType::Empty;
                }
                continue;
            }

            if trim.starts_with("===") {
                types[i] = LineType::PageBreak;
                continue;
            }

            let prev = if i > 0 { types[i - 1] } else { LineType::Empty };
            let prev_empty = prev == LineType::Empty;

            if let Some(t) = Self::forced_type(trim, prev_empty) {
                types[i] = t;
                continue;
            }

            if prev_empty && Self::is_scene_heading(trim) {
                types[i] = LineType::SceneHeading;
                continue;
            }

            let is_transition = prev_empty && Self::is_transition_format(trim);

            if is_transition {
                types[i] = LineType::Transition;
                continue;
            }

            if trim.starts_with('(') {
                match prev {
                    LineType::Character
                    | LineType::DualDialogueCharacter
                    | LineType::Parenthetical
                    | LineType::Dialogue => {
                        types[i] = LineType::Parenthetical;
                        continue;
                    }
                    _ => {}
                }
            }

            match prev {
                LineType::Character
                | LineType::DualDialogueCharacter
                | LineType::Dialogue
                | LineType::Parenthetical => {
                    types[i] = LineType::Dialogue;
                    continue;
                }
                _ => {}
            }

            if prev_empty && Self::is_character_cue(trim) {
                if trim.ends_with('^') {
                    types[i] = LineType::DualDialogueCharacter;
                } else {
                    types[i] = LineType::Character;
                }
                continue;
            }

            types[i] = LineType::Action;
        }

        types
    }

    /// Returns `true` when `s` matches the pattern of a Fountain transition.
    ///
    /// A line is a transition if it is entirely uppercase and ends with a colon,
    /// or if it is one of the special-cased literals `FADE TO BLACK.`,
    /// `FADE OUT.`, or `CUT TO BLACK.`.
    ///
    /// This method is `pub` so that [`crate::config`] can reuse the check when
    /// disambiguating metadata keys from transitions at the start of a document.
    ///
    /// # Examples
    ///
    /// ```
    /// use lottie_rs::parser::Parser;
    ///
    /// assert!(Parser::is_transition_format("CUT TO:"));
    /// assert!(Parser::is_transition_format("FADE TO BLACK."));
    /// assert!(Parser::is_transition_format("FADE OUT."));
    /// assert!(!Parser::is_transition_format("Action line"));
    /// assert!(!Parser::is_transition_format("Author:"));  // lowercase letters
    /// ```
    pub fn is_transition_format(s: &str) -> bool {
        (s.ends_with(':') && Self::is_uppercase_content(s))
            || s == "FADE TO BLACK."
            || s == "FADE OUT."
            || s == "CUT TO BLACK."
    }

    fn forced_type(trim: &str, prev_empty: bool) -> Option<LineType> {
        let first = trim.chars().next()?;
        let last = trim.chars().last()?;
        match first {
            '!' | '' => Some(if trim.starts_with("!!") || trim.starts_with("!!") {
                LineType::Shot
            } else {
                LineType::Action
            }),
            '@' | '' => Some(if last == '^' {
                LineType::DualDialogueCharacter
            } else {
                LineType::Character
            }),
            '~' => Some(LineType::Lyrics),
            '>' => Some(if last == '<' {
                LineType::Centered
            } else {
                LineType::Transition
            }),
            '=' => Some(LineType::Synopsis),
            '#' => Some(LineType::Section),
            '.' if prev_empty && trim.len() > 1 && !trim.starts_with("..") => {
                Some(LineType::SceneHeading)
            }
            _ => None,
        }
    }

    fn is_scene_heading(s: &str) -> bool {
        let prefixes = ["INT", "EXT", "EST", "I/E", "E/I", "I./E", "E./I"];

        for p in prefixes {
            if s.get(..p.len())
                .is_some_and(|sub| sub.eq_ignore_ascii_case(p))
            {
                let rest = &s[p.len()..];
                if rest.is_empty() {
                    return true;
                }
                if let Some(next_char) = rest.chars().next()
                    && (next_char == '.' || next_char == ' ' || next_char == '/')
                {
                    return true;
                }
            }
        }

        if Self::is_uppercase_content(s)
            && let Some(dot_idx) = s.find(". ")
        {
            let prefix = &s[..dot_idx];
            if !prefix.contains(' ') && !prefix.is_empty() {
                let remainder = &s[dot_idx + 2..];
                if remainder.contains(" - ")
                    || remainder.contains("")
                    || remainder.contains("")
                    || remainder.contains(". ")
                {
                    return true;
                }
            }
        }

        false
    }

    /// Returns `true` if `s` contains at least one uppercase letter and no
    /// lowercase letters.
    ///
    /// Digits, punctuation, and whitespace are neutral and do not affect the
    /// result.  An empty string or a string consisting solely of non-alphabetic
    /// characters returns `false`.
    ///
    /// Used to detect character cues, scene headings, and transitions.
    ///
    /// # Examples
    ///
    /// ```
    /// use lottie_rs::parser::Parser;
    ///
    /// assert!(Parser::is_uppercase_content("CUT TO:"));
    /// assert!(Parser::is_uppercase_content("RENÉ"));
    /// assert!(!Parser::is_uppercase_content("René"));
    /// assert!(!Parser::is_uppercase_content("12345"));
    /// assert!(!Parser::is_uppercase_content("!@#$"));
    /// ```
    pub fn is_uppercase_content(s: &str) -> bool {
        let mut has = false;
        for c in s.chars() {
            if c.is_lowercase() {
                return false;
            }
            if c.is_uppercase() {
                has = true;
            }
        }
        has
    }

    fn is_character_cue(s: &str) -> bool {
        let stripped = s.trim_end_matches('^').trim();
        // Hubert Blaine Wolfeschlegelsteinhausenbergerdorff fits (barely)
        if stripped.is_empty() || stripped.len() > 50 || stripped.ends_with('.') {
            return false;
        }
        let no_markdown = stripped.replace("**", "").replace(['*', '_'], "");
        let check_part = if let Some(idx) = no_markdown.find('(') {
            no_markdown[..idx].trim()
        } else {
            no_markdown.as_str()
        };
        let alpha_count = check_part.chars().filter(|c| c.is_alphabetic()).count();
        alpha_count >= 2 && Self::is_uppercase_content(check_part)
    }
}

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

    #[test]
    fn test_is_uppercase_content() {
        assert!(Parser::is_uppercase_content("RENÉ"));
        assert!(Parser::is_uppercase_content("EXT. PARK - DAY"));
        assert!(Parser::is_uppercase_content("CHARACTER (O.S.)"));
        assert!(!Parser::is_uppercase_content("René"));
        assert!(!Parser::is_uppercase_content("ext. park"));
        assert!(!Parser::is_uppercase_content("12345"));
        assert!(!Parser::is_uppercase_content("!@#$"));
    }

    #[test]
    fn test_parse_metadata_block_strict() {
        let lines = vec![
            "Title: Date in Kutaisi".to_string(),
            "Authors:".to_string(),
            "  René Coignard,".to_string(),
            "  Charlotte C.".to_string(),
            "".to_string(),
            "EXT. RIONI RIVERBANK - EVENING".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::MetadataTitle);
        assert_eq!(types[1], LineType::MetadataKey);
        assert_eq!(types[2], LineType::MetadataValue);
        assert_eq!(types[3], LineType::MetadataValue);
        assert_eq!(types[4], LineType::Empty);
        assert_eq!(types[5], LineType::SceneHeading);
    }

    #[test]
    fn test_parse_scene_headings() {
        let lines = vec![
            "INT. ROOM - DAY".to_string(),
            "EXT. STREET - NIGHT".to_string(),
            "EST. BUILDING".to_string(),
            "I/E. CAR".to_string(),
            "E/I. TRAIN".to_string(),
            "I./E. HOUSE".to_string(),
            "E./I. BOAT".to_string(),
        ];
        for (i, _) in lines.iter().enumerate() {
            let test_block = vec!["".to_string(), lines[i].clone()];
            let types = Parser::parse(&test_block);
            assert_eq!(types[1], LineType::SceneHeading);
        }
    }

    #[test]
    fn test_parse_forced_scene_heading() {
        let lines = vec!["".to_string(), ".HOUSE".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::SceneHeading);
    }

    #[test]
    fn test_parse_not_scene_heading() {
        let lines = vec!["".to_string(), "..not heading".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::Action);
    }

    #[test]
    fn test_parse_character_and_dialogue() {
        let lines = vec![
            "".to_string(),
            "RENÉ".to_string(),
            "Hallo.".to_string(),
            "".to_string(),
            "CHARLOTTE".to_string(),
            "(en souriant)".to_string(),
            "Coucou.".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::Character);
        assert_eq!(types[2], LineType::Dialogue);
        assert_eq!(types[3], LineType::Empty);
        assert_eq!(types[4], LineType::Character);
        assert_eq!(types[5], LineType::Parenthetical);
        assert_eq!(types[6], LineType::Dialogue);
    }

    #[test]
    fn test_parse_dual_dialogue_character() {
        let lines = vec![
            "".to_string(),
            "CHARLOTTE ^".to_string(),
            "Coucou.".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::DualDialogueCharacter);
        assert_eq!(types[2], LineType::Dialogue);
    }

    #[test]
    fn test_parse_transitions() {
        let lines = vec![
            "Action".to_string(),
            "".to_string(),
            "CUT TO:".to_string(),
            "".to_string(),
            "FADE OUT.".to_string(),
            "".to_string(),
            "FADE IN:".to_string(),
            "".to_string(),
            "CUT TO BLACK.".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[2], LineType::Transition);
        assert_eq!(types[4], LineType::Transition);
        assert_eq!(types[6], LineType::Transition);
        assert_eq!(types[8], LineType::Transition);
    }

    #[test]
    fn test_parse_forced_transition() {
        let lines = vec!["".to_string(), ">SMASH CUT".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::Transition);
    }

    #[test]
    fn test_parse_centered_text() {
        let lines = vec![">THE END<".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Centered);
    }

    #[test]
    fn test_parse_forced_action_and_shot() {
        let lines = vec!["!ACT".to_string(), "!!SHOT".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Action);
        assert_eq!(types[1], LineType::Shot);
    }

    #[test]
    fn test_parse_lyrics_synopsis_section() {
        let lines = vec![
            "~Song line".to_string(),
            "=Synopsis block".to_string(),
            "#Section block".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Lyrics);
        assert_eq!(types[1], LineType::Synopsis);
        assert_eq!(types[2], LineType::Section);
    }

    #[test]
    fn test_parse_boneyard_multiline() {
        let lines = vec![
            "/*".to_string(),
            "Hidden text".to_string(),
            "More hidden".to_string(),
            "*/".to_string(),
            "Visible action".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Boneyard);
        assert_eq!(types[1], LineType::Boneyard);
        assert_eq!(types[2], LineType::Boneyard);
        assert_eq!(types[3], LineType::Boneyard);
        assert_eq!(types[4], LineType::Action);
    }

    #[test]
    fn test_parse_boneyard_inline() {
        let lines = vec!["/* Inline hidden */".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Boneyard);
    }

    #[test]
    fn test_parse_note_multiline() {
        let lines = vec!["[[".to_string(), "Note text".to_string(), "]]".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Note);
        assert_eq!(types[1], LineType::Note);
        assert_eq!(types[2], LineType::Note);
    }

    #[test]
    fn test_parse_note_inline() {
        let lines = vec!["[[Inline note]]".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Note);
    }

    #[test]
    fn test_parse_page_break() {
        let lines = vec!["===".to_string(), "=====".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::PageBreak);
        assert_eq!(types[1], LineType::PageBreak);
    }

    #[test]
    fn test_parse_action_default() {
        let lines = vec![
            "".to_string(),
            "A man walks into a foobar.".to_string(),
            "He orders foo, bar, and baz.".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Empty);
        assert_eq!(types[1], LineType::Action);
        assert_eq!(types[2], LineType::Action);
    }

    #[test]
    fn test_parse_dialogue_with_empty_line() {
        let lines = vec![
            "CHARLOTTE".to_string(),
            "Line 1".to_string(),
            "  ".to_string(),
            "Line 2".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Character);
        assert_eq!(types[1], LineType::Dialogue);
        assert_eq!(types[2], LineType::Dialogue);
        assert_eq!(types[3], LineType::Dialogue);
    }

    #[test]
    fn test_parse_transition_at_start_not_metadata() {
        let lines = vec![
            "CUT TO:".to_string(),
            "".to_string(),
            "INT. ROOM - DAY".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Transition);
    }

    #[test]
    fn test_parse_cyrillic_metadata() {
        let lines = vec![
            "Автор: Рене".to_string(),
            "".to_string(),
            "INT. ROOM - DAY".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::MetadataKey);
    }

    #[test]
    fn test_parse_cyrillic_transition() {
        let lines = vec![
            "ИЗ ЗТМ:".to_string(),
            "".to_string(),
            "ИНТ. КОМНАТА - ДЕНЬ".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Transition);
    }

    #[test]
    fn test_parse_transition_not_metadata_at_eof_or_start() {
        let lines = vec![
            "CUT TO:".to_string(),
            "".to_string(),
            "INT. ROOM - DAY".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::Transition);
        assert_eq!(types[1], LineType::Empty);
        assert_eq!(types[2], LineType::SceneHeading);
    }

    #[test]
    fn test_parse_cyrillic_metadata_with_unicode_regex() {
        let lines = vec![
            "Автор: Рене".to_string(),
            "".to_string(),
            "ИНТ. КОМНАТА - ДЕНЬ".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::MetadataKey);
        assert_eq!(types[1], LineType::Empty);
        assert_eq!(types[2], LineType::SceneHeading);
    }

    #[test]
    fn test_parser_metadata_leading_spaces() {
        let lines = vec![
            "Title: Script".to_string(),
            "  Subtitle".to_string(),
            "\tAuthor".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[0], LineType::MetadataTitle);
        assert_eq!(types[1], LineType::MetadataValue);
        assert_eq!(types[2], LineType::MetadataValue);
    }

    #[test]
    fn test_parser_forced_dual_dialogue() {
        let lines = vec!["".to_string(), "@CHAR^".to_string(), "@CHAR2^".to_string()];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::DualDialogueCharacter);
        assert_eq!(types[2], LineType::DualDialogueCharacter);
    }

    #[test]
    fn test_parser_is_scene_heading_fast_return() {
        assert!(Parser::is_scene_heading("INT"));
        assert!(Parser::is_scene_heading("EXT"));
    }

    #[test]
    fn test_parse_cyrillic_scene_heading_with_dot() {
        let lines = vec![
            "".to_string(),
            "НАТ. МЕСТО. ДЕНЬ".to_string(),
            "".to_string(),
            "ИНТ. МЕСТО – ДЕНЬ".to_string(),
            "".to_string(),
            "НАТ. МЕСТО — ДЕНЬ".to_string(),
            "".to_string(),
            "ЭТО НЕ СЦЕНА. ЭТО ПРОСТО ПРЕДЛОЖЕНИЕ КРУПНЫМ ШРИФТОМ".to_string(),
        ];
        let types = Parser::parse(&lines);
        assert_eq!(types[1], LineType::SceneHeading);
        assert_eq!(types[3], LineType::SceneHeading);
        assert_eq!(types[5], LineType::SceneHeading);
        assert_ne!(types[7], LineType::SceneHeading);
    }
}