aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/segments/command_execution_time.spec12
-rwxr-xr-xtest/segments/dir.spec217
-rwxr-xr-xtest/segments/go_version.spec2
-rwxr-xr-xtest/segments/kubecontext.spec38
-rwxr-xr-xtest/segments/rust_version.spec3
-rwxr-xr-xtest/segments/vcs.spec86
6 files changed, 337 insertions, 21 deletions
diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec
index 09738859..e8be508f 100755
--- a/test/segments/command_execution_time.spec
+++ b/test/segments/command_execution_time.spec
@@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
_P9K_COMMAND_DURATION=2.03
- assertEquals "%K{red} %F{226%}Dur%f %F{226}2.03 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
_P9K_COMMAND_DURATION=0.03
- assertEquals "%K{red} %F{226%}Dur%f %F{226}0.03 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
_P9K_COMMAND_DURATION=0.0001
- assertEquals "%K{red} %F{226%}Dur%f %F{226}0.0001 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
_P9K_COMMAND_DURATION=23.5001
- assertEquals "%K{red} %F{226%}Dur%f %F{226}23 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=180
- assertEquals "%K{red} %F{226%}Dur%f %F{226}03:00 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=7200
- assertEquals "%K{red} %F{226%}Dur%f %F{226}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
+ assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
diff --git a/test/segments/dir.spec b/test/segments/dir.spec
index ef27e160..e8bbaf93 100755
--- a/test/segments/dir.spec
+++ b/test/segments/dir.spec
@@ -18,6 +18,16 @@ function tearDown() {
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
+function testDirPathAbsoluteWorks() {
+ POWERLEVEL9K_DIR_PATH_ABSOLUTE=true
+
+ cd ~
+ assertEquals "%K{blue} %F{black}/home/travis %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_ABSOLUTE
+}
+
function testTruncateFoldersWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
@@ -36,6 +46,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 +103,60 @@ function testTruncationFromRightWorks() {
unset POWERLEVEL9K_SHORTEN_STRATEGY
}
+function testTruncateToLastWorks() {
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last"
+
+ FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ assertEquals "%K{blue} %F{black}123456789 %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset FOLDER
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+}
+
+function testTruncateToFirstAndLastWorks() {
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last"
+
+ FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ assertEquals "%K{blue} %F{black}/tmp/powerlevel9k-test/…/…/…/…/…/…/…/12345678/123456789 %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset FOLDER
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+}
+
+function testTruncateAbsoluteWorks() {
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute"
+
+ FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ assertEquals "%K{blue} %F{black}…89 %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset FOLDER
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+}
+
function testTruncationFromRightWithEmptyDelimiter() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_DELIMITER=""
@@ -427,4 +512,136 @@ function testTruncateToUniqueWorks() {
unset POWERLEVEL9K_SHORTEN_STRATEGY
}
+function testBoldHomeDirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ cd ~
+
+ assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
+}
+
+function testBoldHomeSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ mkdir -p ~/powerlevel9k-test
+ cd ~/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}~/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr ~/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
+}
+
+function testBoldRootDirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ cd /
+
+ assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
+}
+
+function testBoldRootSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ cd /tmp
+
+ assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
+}
+
+function testBoldRootSubSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
+ mkdir -p /tmp/powerlevel9k-test
+ cd /tmp/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}/tmp/%Bpowerlevel9k-test%b %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
+}
+
+function testHighlightHomeWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ cd ~
+
+ assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
+}
+
+function testHighlightHomeSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ mkdir -p ~/powerlevel9k-test
+ cd ~/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}~/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr ~/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
+}
+
+function testHighlightRootWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ cd /
+
+ assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
+}
+
+function testHighlightRootSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ cd /tmp
+
+ assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
+}
+
+function testHighlightRootSubSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
+ mkdir /tmp/powerlevel9k-test
+ cd /tmp/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}/tmp/%F{red}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
+}
+
+function testDirSeparatorColorHomeSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+ mkdir -p ~/powerlevel9k-test
+ cd ~/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}~%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr ~/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
+}
+
+function testDirSeparatorColorRootSubSubdirWorks() {
+ POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red'
+ mkdir -p /tmp/powerlevel9k-test
+ cd /tmp/powerlevel9k-test
+
+ assertEquals "%K{blue} %F{black}%F{red}/%F{black}tmp%F{red}/%F{black}powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+ unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
+}
+
source shunit2/source/2.1/src/shunit2
diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec
index 2aac460b..347ba4c0 100755
--- a/test/segments/go_version.spec
+++ b/test/segments/go_version.spec
@@ -40,7 +40,7 @@ function testGo() {
PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
- assertEquals "%K{green} %F{255%}%f %F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
+ assertEquals "%K{green} %F{grey93%}%f %F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_GO_ICON
unset PWD
diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec
index eaaa2300..4f1d2c5e 100755
--- a/test/segments/kubecontext.spec
+++ b/test/segments/kubecontext.spec
@@ -18,11 +18,19 @@ function mockKubectl() {
;;
'config')
case "$2" in
- 'current-context')
- echo 'minikube'
- ;;
- 'get-contexts')
- echo '* minikube minikube minikube '
+ 'view')
+ case "$3" in
+ '-o=jsonpath={.current-context}')
+ echo 'minikube'
+ ;;
+ '-o=jsonpath={.contexts'*)
+ echo ''
+ ;;
+ *)
+ echo "Mock value missed"
+ exit 1
+ ;;
+ esac
;;
esac
;;
@@ -36,11 +44,21 @@ function mockKubectlOtherNamespace() {
;;
'config')
case "$2" in
- 'current-context')
- echo 'minikube'
- ;;
- 'get-contexts')
- echo '* minikube minikube minikube kube-system'
+ 'view')
+ case "$3" in
+ # Get Current Context
+ '-o=jsonpath={.current-context}')
+ echo 'minikube'
+ ;;
+ # Get current namespace
+ '-o=jsonpath={.contexts'*)
+ echo 'kube-system'
+ ;;
+ *)
+ echo "Mock value missed"
+ exit 1
+ ;;
+ esac
;;
esac
;;
diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec
index c945f8ae..eb1db35e 100755
--- a/test/segments/rust_version.spec
+++ b/test/segments/rust_version.spec
@@ -19,7 +19,8 @@ function testRust() {
alias rustc=mockRust
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version)
- assertEquals "%K{208} %F{black%}Rust%f %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)"
+ assertEquals "%K{208} %F{black%}Rust%f %F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)"
+
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias rustc
diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec
index 4467145e..f6474f61 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
@@ -78,4 +78,84 @@ function testColorOverridingForUntrackedStateWorks() {
unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
}
+function testBranchNameTruncatingShortenLength() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ POWERLEVEL9K_VCS_SHORTEN_LENGTH=6
+ POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
+ POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
+
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p $FOLDER
+ cd $FOLDER
+ git init 1>/dev/null
+ touch testfile
+
+ assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
+
+ POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
+ assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
+}
+
+function testBranchNameTruncatingMinLength() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
+ POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=6
+ POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
+
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p $FOLDER
+ cd $FOLDER
+ git init 1>/dev/null
+ touch testfile
+
+ assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
+
+ POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7
+
+ assertEquals "%K{green} %F{black} master ? %k%F{green}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
+}
+
+function testBranchNameTruncatingShortenStrategy() {
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
+ POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
+ POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
+ POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"
+
+ FOLDER=/tmp/powerlevel9k-test/vcs-test
+ mkdir -p $FOLDER
+ cd $FOLDER
+ git init 1>/dev/null
+ touch testfile
+
+ assertEquals "%K{green} %F{black} mas… ? %k%F{green}%f " "$(build_left_prompt)"
+
+ POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle"
+
+ assertEquals "%K{green} %F{black} mas…ter ? %k%F{green}%f " "$(build_left_prompt)"
+
+ cd -
+ rm -fr /tmp/powerlevel9k-test
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
+ unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
+}
+
source shunit2/source/2.1/src/shunit2