diff options
Diffstat (limited to 'test/segments/dir.spec')
-rwxr-xr-x | test/segments/dir.spec | 480 |
1 files changed, 302 insertions, 178 deletions
diff --git a/test/segments/dir.spec b/test/segments/dir.spec index c16e32fc..976e80ef 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -7,32 +7,46 @@ SHUNIT_PARENT=$0 function setUp() { export TERM="xterm-256color" - # Load Powerlevel9k - source powerlevel9k.zsh-theme - # Every test should at least use the dir segment - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + P9K_HOME="${PWD}" } function tearDown() { - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + unset P9K_HOME } function testDirPathAbsoluteWorks() { - POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme cd ~ - assertEquals "%K{012} %F{000}/home/travis %k%F{012}%f " "$(build_left_prompt)" + + # Unfortunately, we cannot fake Linux or OSX here, because + # of /home or /Users path.. That is why we change the test + # according to the OS of the host. + if [[ "${OS}" == 'Linux' ]]; then + assertEquals "%K{012} %F{000}/home/${USER} %k%F{012}%f " "$(build_left_prompt)" + elif [[ "${OS}" == 'OSX' ]]; then + assertEquals "%K{012} %F{000}/Users/${USER} %k%F{012}%f " "$(build_left_prompt)" + fi cd - - unset POWERLEVEL9K_DIR_PATH_ABSOLUTE } function testTruncateFoldersWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -40,18 +54,19 @@ function testTruncateFoldersWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateFolderWithHomeDirWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - CURRENT_DIR=$(pwd) + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 + local CURRENT_DIR=$(pwd) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme cd ~ - FOLDER="powerlevel9k-test-${RANDOM}" + local FOLDER="powerlevel9k-test-${RANDOM}" mkdir -p $FOLDER cd $FOLDER # Switch back to home folder as this causes the problem. @@ -61,17 +76,18 @@ function testTruncateFolderWithHomeDirWorks() { 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' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -79,17 +95,18 @@ function testTruncateMiddleWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncationFromRightWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -97,17 +114,18 @@ function testTruncationFromRightWorks() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateToLastWorks() { - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -115,17 +133,18 @@ function testTruncateToLastWorks() { 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" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -133,17 +152,18 @@ function testTruncateToFirstAndLastWorks() { 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" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -151,18 +171,19 @@ function testTruncateAbsoluteWorks() { 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="" - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_DELIMITER="" + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme - FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 + local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789 mkdir -p $FOLDER cd $FOLDER @@ -170,16 +191,15 @@ function testTruncationFromRightWithEmptyDelimiter() { cd - rm -fr /tmp/powerlevel9k-test - - unset FOLDER - unset POWERLEVEL9K_SHORTEN_DIR_LENGTH - unset POWERLEVEL9K_SHORTEN_DELIMITER - unset POWERLEVEL9K_SHORTEN_STRATEGY } function testTruncateWithFolderMarkerWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 @@ -191,16 +211,16 @@ function testTruncateWithFolderMarkerWorks() { cd - rm -fr $BASEFOLDER - unset BASEFOLDER - unset FOLDER - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testTruncateWithFolderMarkerWithChangedFolderMarker() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" - POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' + local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" + local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme local BASEFOLDER=/tmp/powerlevel9k-test local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 @@ -212,11 +232,6 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() { cd - rm -fr $BASEFOLDER - unset BASEFOLDER - unset FOLDER - unset POWERLEVEL9K_SHORTEN_FOLDER_MARKER - unset POWERLEVEL9K_SHORTEN_STRATEGY - unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } function testTruncateWithPackageNameWorks() { @@ -237,18 +252,19 @@ function testTruncateWithPackageNameWorks() { # Go back to deeper folder cd "${FOLDER}" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{012} %F{000}My_Package/1/12/123/12…/12…/12…/12…/12…/123456789 %k%F{012}%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() { @@ -276,18 +292,19 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { # Go to deep folder inside linked repo cd linked-repo/asdfasdf/qwerqwer + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{012} %F{000}My_Package/as…/qwerqwer %k%F{012}%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() { @@ -311,60 +328,77 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { cd linked-repo/.git/refs/heads + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{012} %F{000}My_Package/.g…/re…/heads %k%F{012}%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' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_ICON='home-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme cd ~ assertEquals "%K{012} %F{000%}home-icon %f%F{000}~ %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_HOME_ICON } function testHomeSubfolderDetectionWorks() { - POWERLEVEL9K_HOME_SUB_ICON='sub-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_HOME_SUB_ICON='sub-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme - FOLDER=~/powerlevel9k-test + local FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER assertEquals "%K{012} %F{000%}sub-icon %f%F{000}~/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER - unset FOLDER - unset POWERLEVEL9K_HOME_SUB_ICON } function testOtherFolderDetectionWorks() { - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_FOLDER_ICON='folder-icon' - FOLDER=/tmp/powerlevel9k-test + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + + local FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER assertEquals "%K{012} %F{000%}folder-icon %f%F{000}/tmp/powerlevel9k-test %k%F{012}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER - unset FOLDER - unset POWERLEVEL9K_FOLDER_ICON } function testChangingDirPathSeparator() { - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local FOLDER="/tmp/powerlevel9k-test/1/2" mkdir -p $FOLDER cd $FOLDER @@ -372,52 +406,77 @@ function testChangingDirPathSeparator() { assertEquals "%K{012} %F{000}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{012}%f " "$(build_left_prompt)" cd - - unset FOLDER rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR } function testHomeFolderAbbreviation() { - local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) local dir=$PWD cd ~/ # default - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{012} %F{000}~ %k%F{012}%f " "$(build_left_prompt)" # substituted - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{012} %F{000}qQq %k%F{012}%f " "$(build_left_prompt)" cd /tmp # default - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='~' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" # substituted - POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION='qQq' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{012} %F{000}/tmp %k%F{012}%f " "$(build_left_prompt)" cd "$dir" } function testOmittingFirstCharacterWorks() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{012} %F{000%}folder-icon %f%F{000}tmp %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_FOLDER_ICON - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER } function testOmittingFirstCharacterWorksWithChangingPathSeparator() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_FOLDER_ICON='folder-icon' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_FOLDER_ICON='folder-icon' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -425,9 +484,6 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_FOLDER_ICON - unset POWERLEVEL9K_DIR_PATH_SEPARATOR - unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER } # This test makes it obvious that combining a truncation strategy @@ -438,10 +494,16 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { # But it does more sense in combination with other truncation # strategies. function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -449,17 +511,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc 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 } function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -467,17 +531,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca 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 } function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncation() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 @@ -485,17 +551,19 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat 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 } function testTruncateToUniqueWorks() { - POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true - POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' - POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 - POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true + local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' + local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 + local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test/adam/devl mkdir -p /tmp/powerlevel9k-test/alice/devl mkdir -p /tmp/powerlevel9k-test/alice/docs @@ -506,24 +574,31 @@ function testTruncateToUniqueWorks() { 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 } function testBoldHomeDirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ assertEquals "%K{012} %F{000}%B~%b %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -531,31 +606,46 @@ function testBoldHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootDirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd / assertEquals "%K{012} %F{000}%B/%b %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{012} %F{000}/%Btmp%b %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testBoldRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -563,21 +653,31 @@ function testBoldRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD } function testHighlightHomeWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd ~ assertEquals "%K{012} %F{000}%F{red}~ %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -585,31 +685,46 @@ function testHighlightHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd / assertEquals "%K{012} %F{000}%F{red}/ %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + cd /tmp assertEquals "%K{012} %F{000}/%F{red}tmp %k%F{012}%f " "$(build_left_prompt)" cd - - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testHighlightRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -617,11 +732,16 @@ function testHighlightRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND } function testDirSeparatorColorHomeSubdirWorks() { - POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p ~/powerlevel9k-test cd ~/powerlevel9k-test @@ -629,11 +749,16 @@ function testDirSeparatorColorHomeSubdirWorks() { cd - rm -fr ~/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND } function testDirSeparatorColorRootSubSubdirWorks() { - POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + local POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND='red' + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + mkdir -p /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test @@ -641,7 +766,6 @@ function testDirSeparatorColorRootSubSubdirWorks() { cd - rm -fr /tmp/powerlevel9k-test - unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND } -source shunit2/source/2.1/src/shunit2 +source shunit2/shunit2 |