aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/segments/dir.spec21
-rwxr-xr-xtest/segments/rust_version.spec22
-rwxr-xr-xtest/segments/vcs.spec80
3 files changed, 117 insertions, 6 deletions
diff --git a/test/segments/dir.spec b/test/segments/dir.spec
index 66009a86..e8bbaf93 100755
--- a/test/segments/dir.spec
+++ b/test/segments/dir.spec
@@ -46,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'
diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec
index a9668671..2a344f64 100755
--- a/test/segments/rust_version.spec
+++ b/test/segments/rust_version.spec
@@ -5,28 +5,39 @@
setopt shwordsplit
SHUNIT_PARENT=$0
+TEST_BASE_FOLDER=/tmp/powerlevel9k-test
+RUST_TEST_FOLDER="${TEST_BASE_FOLDER}/rust-test"
+
function setUp() {
+ OLDPATH="${PATH}"
+ mkdir -p "${RUST_TEST_FOLDER}"
+ PATH="${RUST_TEST_FOLDER}:${PATH}"
+
export TERM="xterm-256color"
# Load Powerlevel9k
source powerlevel9k.zsh-theme
}
+function tearDown() {
+ PATH="${OLDPATH}"
+ rm -fr "${TEST_BASE_FOLDER}"
+}
+
function mockRust() {
- echo 'rustc 0.4.1a-alpha'
+ echo "#!/bin/sh\n\necho 'rustc 0.4.1a-alpha'" > "${RUST_TEST_FOLDER}/rustc"
+ chmod +x "${RUST_TEST_FOLDER}/rustc"
}
function testRust() {
- alias rustc=mockRust
+ mockRust
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version)
- assertEquals "%K{208} %F{black}Rust 0.4.1a-alpha %k%F{darkorange}%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
}
function testRustPrintsNothingIfRustIsNotAvailable() {
- alias rustc=noRust
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version)
@@ -34,7 +45,6 @@ function testRustPrintsNothingIfRustIsNotAvailable() {
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
- unalias rustc
}
source shunit2/source/2.1/src/shunit2
diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec
index c33b564d..f6474f61 100755
--- a/test/segments/vcs.spec
+++ b/test/segments/vcs.spec
@@ -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