aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2017-03-04 00:39:01 +0300
committerBen Hilburn <bhilburn@gmail.com>2017-03-08 22:57:24 +0300
commit44eaa0ef33b2ad02d2fe8f4043c93f41bcc42dcb (patch)
tree30238e06c053e87ea64068d24d365b5d07954b30 /test
parent17671d3ee3775fabeb454f0f6b850cf2287ae491 (diff)
Add tests for `truncate_with_package_name` strategy of dir segment
This is a backport from #344
Diffstat (limited to 'test')
-rwxr-xr-xtest/segments/dir.spec106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/segments/dir.spec b/test/segments/dir.spec
index ce6869b7..b2991175 100755
--- a/test/segments/dir.spec
+++ b/test/segments/dir.spec
@@ -114,6 +114,112 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() {
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
+function testTruncateWithPackageNameWorks() {
+ local p9kFolder=$(pwd)
+ local BASEFOLDER=/tmp/powerlevel9k-test
+ local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+
+ cd /tmp/powerlevel9k-test
+ echo '
+{
+ "name": "My_Package"
+}
+' > package.json
+ # Unfortunately: The main folder must be a git repo..
+ git init &>/dev/null
+
+ # Go back to deeper folder
+ cd "${FOLDER}"
+
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ assertEquals "%K{blue} %F{black}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{blue}%f " "$(build_left_prompt)"
+
+ # Go back
+ cd $p9kFolder
+ rm -fr $BASEFOLDER
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+}
+
+function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() {
+ local p9kFolder=$(pwd)
+ local BASEFOLDER=/tmp/powerlevel9k-test
+ local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ # Unfortunately: The main folder must be a git repo..
+ git init &>/dev/null
+
+ echo '
+{
+ "name": "My_Package"
+}
+' > package.json
+
+ # Create a subdir inside the repo
+ mkdir -p asdfasdf/qwerqwer
+
+ cd $BASEFOLDER
+ ln -s ${FOLDER} linked-repo
+
+ # Go to deep folder inside linked repo
+ cd linked-repo/asdfasdf/qwerqwer
+
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)"
+
+ # Go back
+ cd $p9kFolder
+ rm -fr $BASEFOLDER
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+}
+
+function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() {
+ local p9kFolder=$(pwd)
+ local BASEFOLDER=/tmp/powerlevel9k-test
+ local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567/12345678/123456789
+ mkdir -p $FOLDER
+ cd $FOLDER
+
+ # Unfortunately: The main folder must be a git repo..
+ git init &>/dev/null
+
+ echo '
+{
+ "name": "My_Package"
+}
+' > package.json
+
+ cd $BASEFOLDER
+ ln -s ${FOLDER} linked-repo
+
+ cd linked-repo/.git/refs/heads
+
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
+ POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
+ POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
+
+ assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)"
+
+ # Go back
+ cd $p9kFolder
+ rm -fr $BASEFOLDER
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_SHORTEN_STRATEGY
+ unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
+}
+
function testHomeFolderDetectionWorks() {
POWERLEVEL9K_HOME_ICON='home-icon'