summaryrefslogtreecommitdiff
path: root/test/lib/completions/xhost.exp
blob: d4098adeb9ba8edef297b3fc72da7bc0df44348d (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
95
96
97
98
99
100
proc setup {} {
    assert_bash_exec {HOME=$TESTDIR}
    save_env
}


proc teardown {} {
    assert_env_unmodified
}


setup


set test "Tab should complete hostnames"
    # Build string list of hostnames
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
    lappend hosts $h
}
assert_complete $hosts "xhost " $test


sync_after_int


set test "Tab should complete partial hostname"
# Build string list of hostnames, starting with the character of the first hostname
set hosts {}
set char ""
foreach h [exec bash -c "compgen -A hostname"] {
    if {$char == ""} {set char [string range $h 0 0]}
        # Only append hostname if starting with $char
    if {[string range $h 0 0] == "$char"} {
        lappend hosts $h
    }
}
assert_complete $hosts "xhost $char" $test


sync_after_int


set test "Tab should complete hostnames prefixed with +"
# Build string list of hostnames, prefixed with plus (+)
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
    lappend hosts "+$h"
}
assert_complete $hosts "xhost \+" $test


sync_after_int


set test "Tab should complete partial hostname prefixed with +"
    # Build string list of hostnames, starting with character of first host.
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
    if {$char == ""} {set char [string range $h 0 0]}
        # Only append hostname if starting with $char
    if {[string range $h 0 0] == "$char"} {
        lappend hosts "+$h"
    }
}
assert_complete $hosts "xhost +$char"


sync_after_int


set test "Tab should complete hostnames prefixed with -"
    # Build string list of hostnames, prefix with minus (-)
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
    lappend hosts "-$h"
}
assert_complete $hosts "xhost -" $test


sync_after_int


set test "Tab should complete partial hostname prefixed with -"
    # Build list of hostnames, starting with character of first host
set hosts {}
foreach h [exec bash -c "compgen -A hostname"] {
    if {$char == ""} {set char [string range $h 0 0]}
        # Only append hostname if starting with $char
    if {[string range $h 0 0] == "$char"} {
        lappend hosts "-$h"
    }
}
assert_complete $hosts "xhost -$char" $test


sync_after_int


teardown