aboutsummaryrefslogtreecommitdiff
path: root/test/core/prompt.spec
blob: 47d3ac7bbd45299b89db1d671f652db398314f1f (plain) (blame)
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
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8

# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0

function setUp() {
  export TERM="xterm-256color"
  # Load Powerlevel9k
  source powerlevel9k.zsh-theme
}

function testSegmentOnRightSide() {
    # Reset RPROMPT, so a running P9K does not interfere with the test
    local RPROMPT=
    local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
    local POWERLEVEL9K_CUSTOM_WORLD2='echo world2'

    powerlevel9k_prepare_prompts

    local reset_attributes=$'\e[00m'
    assertEquals "%f%b%k%F{007}%f%K{007}%F{000} world1 %f%F{000}%f%K{007}%F{000} world2%E%{${reset_attributes}%}" "${(e)RPROMPT}"
}

function testDisablingRightPrompt() {
    # Reset RPROMPT, so a running P9K does not interfere with the test
    local RPROMPT=
    local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
    local POWERLEVEL9K_CUSTOM_WORLD2='echo world2'
    local POWERLEVEL9K_DISABLE_RPROMPT=true

    powerlevel9k_prepare_prompts

    assertEquals "" "${(e)RPROMPT}"
}

function testLeftMultilinePrompt() {
    local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'
    local POWERLEVEL9K_PROMPT_ON_NEWLINE=true

    powerlevel9k_prepare_prompts

    local nl=$'\n'
    assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}"
}

function testRightPromptOnSameLine() {
    # Reset RPROMPT, so a running P9K does not interfere with the test
    local RPROMPT=
    local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'

    local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
    local POWERLEVEL9K_RPROMPT_ON_NEWLINE=false # We want the RPROMPT on the same line as our left prompt

    # Skip test, as this cannot be tested properly.
    # The "go one line up" instruction does not get
    # printed as real characters in RPROMPT.
    # On command line the assert statement produces
    # a visually identical output as we expect, but
    # it fails anyway. :(
    startSkipping

    powerlevel9k_prepare_prompts
    assertEquals "%{\e[1A%}%F{007}%f%K{007}%F{000} world1 %f%{\e[1B%}" "${(e)RPROMPT}"
}

function testPrefixingFirstLineOnLeftPrompt() {
    local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'

    local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
    local POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX='XXX'

    powerlevel9k_prepare_prompts

    local nl=$'\n'
    assertEquals "XXX%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}╰─ " "${(e)PROMPT}"
}

function testPrefixingSecondLineOnLeftPrompt() {
    local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1)
    local POWERLEVEL9K_CUSTOM_WORLD1='echo world1'

    local POWERLEVEL9K_PROMPT_ON_NEWLINE=true
    local POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX='XXX'

    powerlevel9k_prepare_prompts

    local nl=$'\n'
    assertEquals "╭─%f%b%k%K{007} %F{000}world1 %k%F{007}%f ${nl}XXX" "${(e)PROMPT}"
}

source shunit2/shunit2