diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/segments/dir.spec | 87 | ||||
-rwxr-xr-x | test/segments/kubecontext.spec | 80 | ||||
-rwxr-xr-x | test/segments/vcs.spec | 6 |
3 files changed, 170 insertions, 3 deletions
diff --git a/test/segments/dir.spec b/test/segments/dir.spec index b2991175..97bc857c 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -36,6 +36,27 @@ function testTruncateFoldersWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncateFolderWithHomeDirWorks() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + CURRENT_DIR=$(pwd) + + cd ~ + FOLDER="powerlevel9k-test-${RANDOM}" + mkdir -p $FOLDER + cd $FOLDER + # Switch back to home folder as this causes the problem. + cd .. + + assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + + rmdir $FOLDER + cd ${CURRENT_DIR} + + unset CURRENT_DIR + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH +} + function testTruncateMiddleWorks() { POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' @@ -72,6 +93,26 @@ function testTruncationFromRightWorks() { unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncationFromRightWithEmptyDelimiter() { + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_DELIMITER="" + POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + mkdir -p $FOLDER + cd $FOLDER + + assertEquals "%K{blue} %F{black}/tmp/po/1/12/123/12/12/12/12/12/123456789 %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + + unset FOLDER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_DELIMITER + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + function testTruncateWithFolderMarkerWorks() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" @@ -272,6 +313,31 @@ function testChangingDirPathSeparator() { unset POWERLEVEL9K_DIR_PATH_SEPARATOR } +function testHomeFolderAbbreviation() { + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION + local dir=$PWD + + cd ~/ + # default + POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + assertEquals "%K{blue} %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + + # substituted + POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + assertEquals "%K{blue} %F{black}qQq %k%F{blue}%f " "$(build_left_prompt)" + + cd /tmp + # default + POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + + # substituted + POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + assertEquals "%K{blue} %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + + cd "$dir" +} + function testOmittingFirstCharacterWorks() { POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true POWERLEVEL9K_FOLDER_ICON='folder-icon' @@ -361,4 +427,25 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat unset POWERLEVEL9K_SHORTEN_STRATEGY } +function testTruncateToUniqueWorks() { + POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + mkdir -p /tmp/powerlevel9k-test/adam/devl + mkdir -p /tmp/powerlevel9k-test/alice/devl + mkdir -p /tmp/powerlevel9k-test/alice/docs + mkdir -p /tmp/powerlevel9k-test/bob/docs + cd /tmp/powerlevel9k-test/alice/devl + + assertEquals "%K{blue} %F{black}txXxpxXxalxXxde %k%F{blue}%f " "$(build_left_prompt)" + + cd - + rm -fr /tmp/powerlevel9k-test + unset POWERLEVEL9K_DIR_PATH_SEPARATOR + unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER + unset POWERLEVEL9K_SHORTEN_DIR_LENGTH + unset POWERLEVEL9K_SHORTEN_STRATEGY +} + source shunit2/source/2.1/src/shunit2 diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec new file mode 100755 index 00000000..eaaa2300 --- /dev/null +++ b/test/segments/kubecontext.spec @@ -0,0 +1,80 @@ +#!/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 mockKubectl() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'current-context') + echo 'minikube' + ;; + 'get-contexts') + echo '* minikube minikube minikube ' + ;; + esac + ;; + esac +} + +function mockKubectlOtherNamespace() { + case "$1" in + 'version') + echo 'non-empty text' + ;; + 'config') + case "$2" in + 'current-context') + echo 'minikube' + ;; + 'get-contexts') + echo '* minikube minikube minikube kube-system' + ;; + esac + ;; + esac +} + +function testKubeContext() { + alias kubectl=mockKubectl + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + + assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unalias kubectl +} +function testKubeContextOtherNamespace() { + alias kubectl=mockKubectlOtherNamespace + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) + + assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unalias kubectl +} +function testKubeContextPrintsNothingIfKubectlNotAvailable() { + alias kubectl=noKubectl + POWERLEVEL9K_CUSTOM_WORLD='echo world' + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) + + assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" + + unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset POWERLEVEL9K_CUSTOM_WORLD + unalias kubectl +} + +source shunit2/source/2.1/src/shunit2 diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec index 4467145e..c33b564d 100755 --- a/test/segments/vcs.spec +++ b/test/segments/vcs.spec @@ -21,7 +21,7 @@ function testColorOverridingForCleanStateWorks() { cd $FOLDER git init 1>/dev/null - assertEquals "%K{white} %F{cyan}master %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -47,7 +47,7 @@ function testColorOverridingForModifiedStateWorks() { git commit -m "test" 1>/dev/null echo "test" > testfile - assertEquals "%K{yellow} %F{red}master ● %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -68,7 +68,7 @@ function testColorOverridingForUntrackedStateWorks() { git init 1>/dev/null touch testfile - assertEquals "%K{yellow} %F{cyan}master ? %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test |