aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2018-07-21 01:01:21 +0300
committerDominik Ritter <dritter03@googlemail.com>2018-07-21 01:01:21 +0300
commit17229ddad762e18cede1c0f7338fec30851f7b9a (patch)
tree55292dc135e0e5880c59dfa4fef285d1bcdcad37
parentf6087199f96d143b4964d65fe8de5b24cbf03bf0 (diff)
Add tests for general prompt functionality
-rwxr-xr-xtest/core/prompt.spec104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/core/prompt.spec b/test/core/prompt.spec
new file mode 100755
index 00000000..42518f06
--- /dev/null
+++ b/test/core/prompt.spec
@@ -0,0 +1,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{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} 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{white} %F{black}world1 %k%F{white}%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{white}%f%K{white}%F{black} 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{white} %F{black}world1 %k%F{white}%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{white} %F{black}world1 %k%F{white}%f ${nl}XXX" "${(e)PROMPT}"
+}
+
+source shunit2/source/2.1/src/shunit2