1
use super::message_lines;
2
use crate::draw::form::tests::form_rows;
3
use crate::form::Form;
4

            
5
2
fn texts(lines: &[ratatui::text::Line<'_>]) -> Vec<String> {
6
2
    lines
7
2
        .iter()
8
5
        .map(|line| line.spans.iter().map(|s| s.content.as_ref()).collect())
9
        .collect()
10
2
}
11

            
12
#[test]
13
1
fn a_multi_line_message_keeps_its_source_line_and_caret() {
14
1
    let message = "Source: unexpected end\n(oops\n     ^".to_string();
15
1
    assert_eq!(
16
1
        texts(&message_lines("! ", &[message])),
17
1
        ["! Source: unexpected end", "  (oops", "       ^"]
18
    );
19
1
}
20

            
21
#[test]
22
1
fn every_message_gets_the_prefix() {
23
1
    let messages = ["a".to_string(), "b".to_string()];
24
1
    assert_eq!(
25
1
        texts(&message_lines("note: ", &messages)),
26
1
        ["note: a", "note: b"]
27
    );
28
1
}
29

            
30
#[test]
31
1
fn the_script_form_shows_its_notice_and_its_compile_error_in_lines() {
32
1
    let mut form = Form::script_edit(&forms::FormValues::default());
33
1
    form.notices = vec!["uploaded as bytecode".to_string()];
34
1
    form.errors = vec!["Source: unclosed\n(oops\n     ^".to_string()];
35

            
36
1
    let lines = form_rows(&form, false, &crate::test_support::app());
37

            
38
1
    assert_eq!(crate::draw::form::title(form.kind), "Edit Script");
39
1
    assert_eq!(lines[0], "note: uploaded as bytecode");
40
9
    let at = lines.iter().position(|l| l == "! Source: unclosed");
41
1
    assert!(at.is_some_and(|i| lines[i + 1] == "  (oops" && lines[i + 2] == "       ^"));
42
1
}