summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt/src/cargo-fmt/test/message_format.rs
blob: bf44924f13c31cdc56fa9779969791d6910418ee (plain)
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
use super::*;

#[test]
fn invalid_message_format() {
    assert_eq!(
        convert_message_format_to_rustfmt_args("awesome", &mut vec![]),
        Err(String::from(
            "invalid --message-format value: awesome. Allowed values are: short|json|human"
        )),
    );
}

#[test]
fn json_message_format_and_check_arg() {
    let mut args = vec![String::from("--check")];
    assert_eq!(
        convert_message_format_to_rustfmt_args("json", &mut args),
        Err(String::from(
            "cannot include --check arg when --message-format is set to json"
        )),
    );
}

#[test]
fn json_message_format_and_emit_arg() {
    let mut args = vec![String::from("--emit"), String::from("checkstyle")];
    assert_eq!(
        convert_message_format_to_rustfmt_args("json", &mut args),
        Err(String::from(
            "cannot include --emit arg when --message-format is set to json"
        )),
    );
}

#[test]
fn json_message_format() {
    let mut args = vec![String::from("--edition"), String::from("2018")];
    assert!(convert_message_format_to_rustfmt_args("json", &mut args).is_ok());
    assert_eq!(
        args,
        vec![
            String::from("--edition"),
            String::from("2018"),
            String::from("--emit"),
            String::from("json")
        ]
    );
}

#[test]
fn human_message_format() {
    let exp_args = vec![String::from("--emit"), String::from("json")];
    let mut act_args = exp_args.clone();
    assert!(convert_message_format_to_rustfmt_args("human", &mut act_args).is_ok());
    assert_eq!(act_args, exp_args);
}

#[test]
fn short_message_format() {
    let mut args = vec![String::from("--check")];
    assert!(convert_message_format_to_rustfmt_args("short", &mut args).is_ok());
    assert_eq!(args, vec![String::from("--check"), String::from("-l")]);
}

#[test]
fn short_message_format_included_short_list_files_flag() {
    let mut args = vec![String::from("--check"), String::from("-l")];
    assert!(convert_message_format_to_rustfmt_args("short", &mut args).is_ok());
    assert_eq!(args, vec![String::from("--check"), String::from("-l")]);
}

#[test]
fn short_message_format_included_long_list_files_flag() {
    let mut args = vec![String::from("--check"), String::from("--files-with-diff")];
    assert!(convert_message_format_to_rustfmt_args("short", &mut args).is_ok());
    assert_eq!(
        args,
        vec![String::from("--check"), String::from("--files-with-diff")]
    );
}