Improve tests by making use of local variables

pull/22/head
Dominik Ritter 6 years ago
parent 822b820a6e
commit 4972f0b8eb

@ -10,21 +10,15 @@ function setUp() {
_OLD_LC_CTYPE="${LC_CTYPE}" _OLD_LC_CTYPE="${LC_CTYPE}"
# Reset actual LC_CTYPE # Reset actual LC_CTYPE
unset LC_CTYPE unset LC_CTYPE
# Store old P9K mode
_OLD_P9K_MODE="${POWERLEVEL9K_MODE}"
} }
function tearDown() { function tearDown() {
# Restore LC_CTYPE # Restore LC_CTYPE
LC_CTYPE="${_OLD_LC_CTYPE}" LC_CTYPE="${_OLD_LC_CTYPE}"
# Restore old P9K mode
POWERLEVEL9K_MODE="${_OLD_P9K_MODE}"
} }
function testLcCtypeIsSetCorrectlyInDefaultMode() { function testLcCtypeIsSetCorrectlyInDefaultMode() {
POWERLEVEL9K_MODE="default" local POWERLEVEL9K_MODE="default"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -32,7 +26,7 @@ function testLcCtypeIsSetCorrectlyInDefaultMode() {
} }
function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() {
POWERLEVEL9K_MODE="awesome-patched" local POWERLEVEL9K_MODE="awesome-patched"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -40,7 +34,7 @@ function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() {
} }
function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() {
POWERLEVEL9K_MODE="awesome-fontconfig" local POWERLEVEL9K_MODE="awesome-fontconfig"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -48,7 +42,7 @@ function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() {
} }
function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() {
POWERLEVEL9K_MODE="nerdfont-fontconfig" local POWERLEVEL9K_MODE="nerdfont-fontconfig"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -56,7 +50,7 @@ function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() {
} }
function testLcCtypeIsSetCorrectlyInFlatMode() { function testLcCtypeIsSetCorrectlyInFlatMode() {
POWERLEVEL9K_MODE="flat" local POWERLEVEL9K_MODE="flat"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -64,7 +58,7 @@ function testLcCtypeIsSetCorrectlyInFlatMode() {
} }
function testLcCtypeIsSetCorrectlyInCompatibleMode() { function testLcCtypeIsSetCorrectlyInCompatibleMode() {
POWERLEVEL9K_MODE="compatible" local POWERLEVEL9K_MODE="compatible"
# Load Powerlevel9k # Load Powerlevel9k
source functions/icons.zsh source functions/icons.zsh
@ -76,7 +70,7 @@ function testLcCtypeIsSetCorrectlyInCompatibleMode() {
function testAllIconsAreDefinedLikeInDefaultMode() { function testAllIconsAreDefinedLikeInDefaultMode() {
# Always compare against this mode # Always compare against this mode
local _P9K_TEST_MODE="default" local _P9K_TEST_MODE="default"
POWERLEVEL9K_MODE="${_P9K_TEST_MODE}" local POWERLEVEL9K_MODE="${_P9K_TEST_MODE}"
source functions/icons.zsh source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons. # _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key # We later check via (r) "subscript" flag that our key
@ -148,7 +142,7 @@ function testAllIconsAreDefinedLikeInDefaultMode() {
function testAllIconsAreDefinedLikeInAwesomePatchedMode() { function testAllIconsAreDefinedLikeInAwesomePatchedMode() {
# Always compare against this mode # Always compare against this mode
local _P9K_TEST_MODE="awesome-patched" local _P9K_TEST_MODE="awesome-patched"
POWERLEVEL9K_MODE="$_P9K_TEST_MODE" local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons. # _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key # We later check via (r) "subscript" flag that our key
@ -220,7 +214,7 @@ function testAllIconsAreDefinedLikeInAwesomePatchedMode() {
function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() {
# Always compare against this mode # Always compare against this mode
local _P9K_TEST_MODE="awesome-fontconfig" local _P9K_TEST_MODE="awesome-fontconfig"
POWERLEVEL9K_MODE="$_P9K_TEST_MODE" local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons. # _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key # We later check via (r) "subscript" flag that our key
@ -292,7 +286,7 @@ function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() {
function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() { function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() {
# Always compare against this mode # Always compare against this mode
local _P9K_TEST_MODE="nerdfont-fontconfig" local _P9K_TEST_MODE="nerdfont-fontconfig"
POWERLEVEL9K_MODE="$_P9K_TEST_MODE" local POWERLEVEL9K_MODE="$_P9K_TEST_MODE"
source functions/icons.zsh source functions/icons.zsh
# _ICONS_UNDER_TEST is an array of just the keys of $icons. # _ICONS_UNDER_TEST is an array of just the keys of $icons.
# We later check via (r) "subscript" flag that our key # We later check via (r) "subscript" flag that our key

@ -12,85 +12,65 @@ function setUp() {
} }
function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() { function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
POWERLEVEL9K_CUSTOM_WORLD='echo world' local POWERLEVEL9K_CUSTOM_WORLD='echo world'
_P9K_COMMAND_DURATION=2 local _P9K_COMMAND_DURATION=2
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
unset _P9K_COMMAND_DURATION
} }
function testCommandExecutionTimeThresholdCouldBeChanged() { function testCommandExecutionTimeThresholdCouldBeChanged() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
_P9K_COMMAND_DURATION=2.03 local _P9K_COMMAND_DURATION=2.03
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
} }
function testCommandExecutionTimeThresholdCouldBeSetToZero() { function testCommandExecutionTimeThresholdCouldBeSetToZero() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
_P9K_COMMAND_DURATION=0.03 local _P9K_COMMAND_DURATION=0.03
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
} }
function testCommandExecutionTimePrecisionCouldBeChanged() { function testCommandExecutionTimePrecisionCouldBeChanged() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
_P9K_COMMAND_DURATION=0.0001 local _P9K_COMMAND_DURATION=0.0001
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION
unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD
} }
function testCommandExecutionTimePrecisionCouldBeSetToZero() { function testCommandExecutionTimePrecisionCouldBeSetToZero() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
_P9K_COMMAND_DURATION=23.5001 local _P9K_COMMAND_DURATION=23.5001
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
unset POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION
} }
function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() { function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=180 local _P9K_COMMAND_DURATION=180
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
} }
function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=7200 local _P9K_COMMAND_DURATION=7200
assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}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
} }
source shunit2/source/2.1/src/shunit2 source shunit2/source/2.1/src/shunit2

@ -17,7 +17,6 @@ function testDetectVirtSegmentPrintsNothingIfSystemdIsNotAvailable() {
local POWERLEVEL9K_CUSTOM_WORLD='echo world' local POWERLEVEL9K_CUSTOM_WORLD='echo world'
alias systemd-detect-virt="novirt" alias systemd-detect-virt="novirt"
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unalias systemd-detect-virt unalias systemd-detect-virt

@ -9,17 +9,12 @@ function setUp() {
export TERM="xterm-256color" export TERM="xterm-256color"
# Load Powerlevel9k # Load Powerlevel9k
source powerlevel9k.zsh-theme source powerlevel9k.zsh-theme
# Every test should at least use the dir segment
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
}
function tearDown() {
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
} }
function testDirPathAbsoluteWorks() { function testDirPathAbsoluteWorks() {
POWERLEVEL9K_DIR_PATH_ABSOLUTE=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_ABSOLUTE=true
cd ~ cd ~
@ -33,14 +28,15 @@ function testDirPathAbsoluteWorks() {
fi fi
cd - cd -
unset POWERLEVEL9K_DIR_PATH_ABSOLUTE
} }
function testTruncateFoldersWorks() { function testTruncateFoldersWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' 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 local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -48,18 +44,16 @@ function testTruncateFoldersWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateFolderWithHomeDirWorks() { function testTruncateFolderWithHomeDirWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
CURRENT_DIR=$(pwd) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
local CURRENT_DIR=$(pwd)
cd ~ cd ~
FOLDER="powerlevel9k-test-${RANDOM}" local FOLDER="powerlevel9k-test-${RANDOM}"
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
# Switch back to home folder as this causes the problem. # Switch back to home folder as this causes the problem.
@ -69,17 +63,15 @@ function testTruncateFolderWithHomeDirWorks() {
rmdir $FOLDER rmdir $FOLDER
cd ${CURRENT_DIR} cd ${CURRENT_DIR}
unset CURRENT_DIR
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
} }
function testTruncateMiddleWorks() { function testTruncateMiddleWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' 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 local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -87,17 +79,15 @@ function testTruncateMiddleWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncationFromRightWorks() { function testTruncationFromRightWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' 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 local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -105,17 +95,15 @@ function testTruncationFromRightWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateToLastWorks() { function testTruncateToLastWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_last" 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 local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -123,17 +111,15 @@ function testTruncateToLastWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateToFirstAndLastWorks() { function testTruncateToFirstAndLastWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last" POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_to_first_and_last"
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 mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -141,17 +127,15 @@ function testTruncateToFirstAndLastWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateAbsoluteWorks() { function testTruncateAbsoluteWorks() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute" POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_absolute"
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 mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -159,18 +143,16 @@ function testTruncateAbsoluteWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncationFromRightWithEmptyDelimiter() { function testTruncationFromRightWithEmptyDelimiter() {
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_SHORTEN_DELIMITER="" POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_DELIMITER=""
local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
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 mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -178,16 +160,12 @@ function testTruncationFromRightWithEmptyDelimiter() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset FOLDER
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
unset POWERLEVEL9K_SHORTEN_DELIMITER
unset POWERLEVEL9K_SHORTEN_STRATEGY
} }
function testTruncateWithFolderMarkerWorks() { function testTruncateWithFolderMarkerWorks() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
local BASEFOLDER=/tmp/powerlevel9k-test local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@ -199,16 +177,13 @@ function testTruncateWithFolderMarkerWorks() {
cd - cd -
rm -fr $BASEFOLDER rm -fr $BASEFOLDER
unset BASEFOLDER
unset FOLDER
unset POWERLEVEL9K_SHORTEN_STRATEGY
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
} }
function testTruncateWithFolderMarkerWithChangedFolderMarker() { function testTruncateWithFolderMarkerWithChangedFolderMarker() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker" local POWERLEVEL9K_SHORTEN_STRATEGY="truncate_with_folder_marker"
POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx' local POWERLEVEL9K_SHORTEN_FOLDER_MARKER='.xxx'
local BASEFOLDER=/tmp/powerlevel9k-test local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567 local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@ -220,11 +195,6 @@ function testTruncateWithFolderMarkerWithChangedFolderMarker() {
cd - cd -
rm -fr $BASEFOLDER rm -fr $BASEFOLDER
unset BASEFOLDER
unset FOLDER
unset POWERLEVEL9K_SHORTEN_FOLDER_MARKER
unset POWERLEVEL9K_SHORTEN_STRATEGY
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
} }
function testTruncateWithPackageNameWorks() { function testTruncateWithPackageNameWorks() {
@ -245,18 +215,16 @@ function testTruncateWithPackageNameWorks() {
# Go back to deeper folder # Go back to deeper folder
cd "${FOLDER}" cd "${FOLDER}"
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' local 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)" 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 # Go back
cd $p9kFolder cd $p9kFolder
rm -fr $BASEFOLDER rm -fr $BASEFOLDER
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_SHORTEN_STRATEGY
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
} }
function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() { function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() {
@ -284,18 +252,16 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideDeepFolder() {
# Go to deep folder inside linked repo # Go to deep folder inside linked repo
cd linked-repo/asdfasdf/qwerqwer cd linked-repo/asdfasdf/qwerqwer
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}My_Package/as…/qwerqwer %k%F{blue}%f " "$(build_left_prompt)"
# Go back # Go back
cd $p9kFolder cd $p9kFolder
rm -fr $BASEFOLDER rm -fr $BASEFOLDER
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_SHORTEN_STRATEGY
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
} }
function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() { function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() {
@ -319,60 +285,61 @@ function testTruncateWithPackageNameIfRepoIsSymlinkedInsideGitDir() {
cd linked-repo/.git/refs/heads cd linked-repo/.git/refs/heads
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name' local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_with_package_name'
assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}My_Package/.g…/re…/heads %k%F{blue}%f " "$(build_left_prompt)"
# Go back # Go back
cd $p9kFolder cd $p9kFolder
rm -fr $BASEFOLDER rm -fr $BASEFOLDER
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_SHORTEN_STRATEGY
unset POWERLEVEL9K_SHORTEN_DIR_LENGTH
} }
function testHomeFolderDetectionWorks() { function testHomeFolderDetectionWorks() {
POWERLEVEL9K_HOME_ICON='home-icon' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_HOME_ICON='home-icon'
cd ~ cd ~
assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_HOME_ICON
} }
function testHomeSubfolderDetectionWorks() { 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'
FOLDER=~/powerlevel9k-test local FOLDER=~/powerlevel9k-test
mkdir $FOLDER mkdir $FOLDER
cd $FOLDER cd $FOLDER
assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
rm -fr $FOLDER rm -fr $FOLDER
unset FOLDER
unset POWERLEVEL9K_HOME_SUB_ICON
} }
function testOtherFolderDetectionWorks() { 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 local FOLDER=/tmp/powerlevel9k-test
mkdir $FOLDER mkdir $FOLDER
cd $FOLDER cd $FOLDER
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
rm -fr $FOLDER rm -fr $FOLDER
unset FOLDER
unset POWERLEVEL9K_FOLDER_ICON
} }
function testChangingDirPathSeparator() { function testChangingDirPathSeparator() {
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local FOLDER="/tmp/powerlevel9k-test/1/2" local FOLDER="/tmp/powerlevel9k-test/1/2"
mkdir -p $FOLDER mkdir -p $FOLDER
cd $FOLDER cd $FOLDER
@ -380,12 +347,12 @@ function testChangingDirPathSeparator() {
assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset FOLDER
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_SEPARATOR
} }
function testHomeFolderAbbreviation() { function testHomeFolderAbbreviation() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
local dir=$PWD local dir=$PWD
@ -411,21 +378,23 @@ function testHomeFolderAbbreviation() {
} }
function testOmittingFirstCharacterWorks() { function testOmittingFirstCharacterWorks() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_FOLDER_ICON='folder-icon' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
local POWERLEVEL9K_FOLDER_ICON='folder-icon'
cd /tmp cd /tmp
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_FOLDER_ICON
unset POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
} }
function testOmittingFirstCharacterWorksWithChangingPathSeparator() { function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_FOLDER_ICON='folder-icon' local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local POWERLEVEL9K_FOLDER_ICON='folder-icon'
mkdir -p /tmp/powerlevel9k-test/1/2 mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2
@ -433,9 +402,6 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
cd - cd -
rm -fr /tmp/powerlevel9k-test 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 # This test makes it obvious that combining a truncation strategy
@ -446,10 +412,12 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() {
# But it does more sense in combination with other truncation # But it does more sense in combination with other truncation
# strategies. # strategies.
function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() { function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTruncation() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders' local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_folders'
mkdir -p /tmp/powerlevel9k-test/1/2 mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2
@ -457,17 +425,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndDefaultTrunc
cd - cd -
rm -fr /tmp/powerlevel9k-test 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() { function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTruncation() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle' local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
mkdir -p /tmp/powerlevel9k-test/1/2 mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2
@ -475,17 +441,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndMiddleTrunca
cd - cd -
rm -fr /tmp/powerlevel9k-test 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() { function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncation() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right' local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_from_right'
mkdir -p /tmp/powerlevel9k-test/1/2 mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2
@ -493,17 +457,15 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparatorAndRightTruncat
cd - cd -
rm -fr /tmp/powerlevel9k-test 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() { function testTruncateToUniqueWorks() {
POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 local POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER=true
POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique' local POWERLEVEL9K_DIR_PATH_SEPARATOR='xXx'
local POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
local POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_unique'
mkdir -p /tmp/powerlevel9k-test/adam/devl mkdir -p /tmp/powerlevel9k-test/adam/devl
mkdir -p /tmp/powerlevel9k-test/alice/devl mkdir -p /tmp/powerlevel9k-test/alice/devl
mkdir -p /tmp/powerlevel9k-test/alice/docs mkdir -p /tmp/powerlevel9k-test/alice/docs
@ -514,24 +476,23 @@ function testTruncateToUniqueWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test 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() { 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
cd ~ cd ~
assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}%B~%b %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
} }
function testBoldHomeSubdirWorks() { 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
mkdir -p ~/powerlevel9k-test mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test cd ~/powerlevel9k-test
@ -539,31 +500,34 @@ function testBoldHomeSubdirWorks() {
cd - cd -
rm -fr ~/powerlevel9k-test rm -fr ~/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
} }
function testBoldRootDirWorks() { 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
cd / cd /
assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}%B/%b %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
} }
function testBoldRootSubdirWorks() { 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
cd /tmp cd /tmp
assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}/%Btmp%b %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
} }
function testBoldRootSubSubdirWorks() { 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
mkdir -p /tmp/powerlevel9k-test mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test
@ -571,21 +535,23 @@ function testBoldRootSubSubdirWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD
} }
function testHighlightHomeWorks() { 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'
cd ~ cd ~
assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}%F{red}~ %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
} }
function testHighlightHomeSubdirWorks() { 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'
mkdir -p ~/powerlevel9k-test mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test cd ~/powerlevel9k-test
@ -593,31 +559,34 @@ function testHighlightHomeSubdirWorks() {
cd - cd -
rm -fr ~/powerlevel9k-test rm -fr ~/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
} }
function testHighlightRootWorks() { 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'
cd / cd /
assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}%F{red}/ %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
} }
function testHighlightRootSubdirWorks() { 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'
cd /tmp cd /tmp
assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)" assertEquals "%K{blue} %F{black}/%F{red}tmp %k%F{blue}%f " "$(build_left_prompt)"
cd - cd -
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
} }
function testHighlightRootSubSubdirWorks() { 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'
mkdir /tmp/powerlevel9k-test mkdir /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test
@ -625,11 +594,12 @@ function testHighlightRootSubSubdirWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
} }
function testDirSeparatorColorHomeSubdirWorks() { 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'
mkdir -p ~/powerlevel9k-test mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test cd ~/powerlevel9k-test
@ -637,11 +607,12 @@ function testDirSeparatorColorHomeSubdirWorks() {
cd - cd -
rm -fr ~/powerlevel9k-test rm -fr ~/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
} }
function testDirSeparatorColorRootSubSubdirWorks() { 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'
mkdir -p /tmp/powerlevel9k-test mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test cd /tmp/powerlevel9k-test
@ -649,7 +620,6 @@ function testDirSeparatorColorRootSubSubdirWorks() {
cd - cd -
rm -fr /tmp/powerlevel9k-test rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
} }
source shunit2/source/2.1/src/shunit2 source shunit2/source/2.1/src/shunit2

@ -35,51 +35,43 @@ function mockGoEmptyGopath() {
function testGo() { function testGo() {
alias go=mockGo alias go=mockGo
POWERLEVEL9K_GO_ICON="" local POWERLEVEL9K_GO_ICON=""
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(go_version)
PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" local PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" assertEquals "%K{green} %F{grey93%} %f%F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_GO_ICON
unset PWD
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias go unalias go
} }
function testGoSegmentPrintsNothingIfEmptyGopath() { function testGoSegmentPrintsNothingIfEmptyGopath() {
alias go=mockGoEmptyGopath local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
alias go=mockGoEmptyGopath
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
} }
function testGoSegmentPrintsNothingIfNotInGopath() { function testGoSegmentPrintsNothingIfNotInGopath() {
alias go=mockGo local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
alias go=mockGo
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
} }
function testGoSegmentPrintsNothingIfGoIsNotAvailable() { function testGoSegmentPrintsNothingIfGoIsNotAvailable() {
alias go=noGo local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world go_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
alias go=noGo
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
unalias go unalias go
} }

@ -66,32 +66,31 @@ function mockKubectlOtherNamespace() {
} }
function testKubeContext() { function testKubeContext() {
alias kubectl=mockKubectl local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
alias kubectl=mockKubectl
assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias kubectl unalias kubectl
} }
function testKubeContextOtherNamespace() { function testKubeContextOtherNamespace() {
alias kubectl=mockKubectlOtherNamespace local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
alias kubectl=mockKubectlOtherNamespace
assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" 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 unalias kubectl
} }
function testKubeContextPrintsNothingIfKubectlNotAvailable() { function testKubeContextPrintsNothingIfKubectlNotAvailable() {
alias kubectl=noKubectl local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
alias kubectl=noKubectl
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
unalias kubectl unalias kubectl
} }

@ -27,42 +27,37 @@ function mockNoLaravelVersion() {
} }
function testLaravelVersionSegment() { function testLaravelVersionSegment() {
alias php=mockLaravelVersion local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LARAVEL_ICON='x'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version)
local POWERLEVEL9K_LARAVEL_ICON='x'
alias php=mockLaravelVersion
assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unalias php unalias php
} }
function testLaravelVersionSegmentIfArtisanIsNotAvailable() { function testLaravelVersionSegmentIfArtisanIsNotAvailable() {
alias php=mockNoLaravelVersion local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LARAVEL_ICON='x'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
local POWERLEVEL9K_LARAVEL_ICON='x'
alias php=mockNoLaravelVersion
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unset POWERLEVEL9K_CUSTOM_WORLD
unalias php unalias php
} }
function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() { function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
alias php=noPhp local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LARAVEL_ICON='x'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world laravel_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
local POWERLEVEL9K_LARAVEL_ICON='x'
alias php=noPhp
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unset POWERLEVEL9K_CUSTOM_WORLD
unalias php unalias php
} }

@ -29,22 +29,19 @@ function mockRust() {
} }
function testRust() { function testRust() {
mockRust local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version)
mockRust
assertEquals "%K{208} %F{black%}Rust %f%F{black}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
} }
function testRustPrintsNothingIfRustIsNotAvailable() { function testRustPrintsNothingIfRustIsNotAvailable() {
POWERLEVEL9K_CUSTOM_WORLD='echo world' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version)
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)" assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
} }
source shunit2/source/2.1/src/shunit2 source shunit2/source/2.1/src/shunit2

Loading…
Cancel
Save