aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/io/null_io_test.rs
blob: ced598b970dc1b0d7a97fe8921f2fde789510ae2 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! ref: composer/tests/Composer/Test/IO/NullIOTest.php

use indexmap::IndexMap;
use shirabe::io::IOInterfaceImmutable;
use shirabe::io::null_io::NullIO;
use shirabe_php_shim::PhpMixed;

#[test]
fn test_is_interactive() {
    let io = NullIO::new();

    assert!(!io.is_interactive());
}

#[test]
fn test_has_authentication() {
    let io = NullIO::new();

    assert!(!io.has_authentication("foo"));
}

#[test]
fn test_ask_and_hide_answer() {
    let io = NullIO::new();

    assert_eq!(None, io.ask_and_hide_answer("foo".to_string()));
}

#[test]
fn test_get_authentications() {
    let io = NullIO::new();

    assert!(io.get_authentications().is_empty());

    let mut expected: IndexMap<String, Option<String>> = IndexMap::new();
    expected.insert("username".to_string(), None);
    expected.insert("password".to_string(), None);
    assert_eq!(expected, io.get_authentication("foo"));
}

#[test]
fn test_ask() {
    let io = NullIO::new();

    assert_eq!(
        PhpMixed::String("foo".to_string()),
        io.ask("bar".to_string(), PhpMixed::String("foo".to_string()))
            .unwrap()
    );
}

#[test]
fn test_ask_confirmation() {
    let io = NullIO::new();

    assert!(!io.ask_confirmation("bar".to_string(), false));
}

#[test]
fn test_ask_and_validate() {
    let io = NullIO::new();

    assert_eq!(
        PhpMixed::String("foo".to_string()),
        io.ask_and_validate(
            "question".to_string(),
            Box::new(|_x| Ok(PhpMixed::Bool(true))),
            None,
            PhpMixed::String("foo".to_string())
        )
        .unwrap()
    );
}

#[test]
fn test_select() {
    let io = NullIO::new();

    assert_eq!(
        PhpMixed::String("1".to_string()),
        io.select(
            "question".to_string(),
            PhpMixed::List(vec![
                PhpMixed::String("item1".to_string()),
                PhpMixed::String("item2".to_string()),
            ]),
            PhpMixed::String("1".to_string()),
            PhpMixed::Int(2),
            "foo".to_string(),
            true
        )
        .unwrap()
    );
}