1
0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-12 19:18:28 +02:00

Improve tests by making use of local variables

This commit is contained in:
Dominik Ritter 2018-07-24 16:24:33 +02:00
parent 822b820a6e
commit 4972f0b8eb
8 changed files with 207 additions and 281 deletions

View File

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

View File

@ -12,85 +12,65 @@ function setUp() {
}
function testCommandExecutionTimeIsNotShownIfTimeIsBelowThreshold() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world command_execution_time)
POWERLEVEL9K_CUSTOM_WORLD='echo world'
_P9K_COMMAND_DURATION=2
local POWERLEVEL9K_CUSTOM_WORLD='echo world'
local _P9K_COMMAND_DURATION=2
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() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
_P9K_COMMAND_DURATION=2.03
local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
local _P9K_COMMAND_DURATION=2.03
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() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
_P9K_COMMAND_DURATION=0.03
local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
local _P9K_COMMAND_DURATION=0.03
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() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
_P9K_COMMAND_DURATION=0.0001
local POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
local _P9K_COMMAND_DURATION=0.0001
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() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
_P9K_COMMAND_DURATION=23.5001
local POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
local _P9K_COMMAND_DURATION=23.5001
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() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
}
function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
}
source shunit2/source/2.1/src/shunit2

View File

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

View File

@ -9,17 +9,12 @@ 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)
}
function tearDown() {
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
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 ~
@ -33,14 +28,15 @@ function testDirPathAbsoluteWorks() {
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
local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@ -48,18 +44,16 @@ 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)
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.
@ -69,17 +63,15 @@ 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
local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@ -87,17 +79,15 @@ 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
local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@ -105,17 +95,15 @@ 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
local FOLDER=/tmp/powerlevel9k-test/1/12/123/1234/12345/123456/1234567/12345678/123456789
mkdir -p $FOLDER
cd $FOLDER
@ -123,17 +111,15 @@ 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"
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
@ -141,17 +127,15 @@ 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"
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
@ -159,18 +143,16 @@ 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'
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
@ -178,16 +160,12 @@ 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"
local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@ -199,16 +177,13 @@ 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'
local BASEFOLDER=/tmp/powerlevel9k-test
local FOLDER=$BASEFOLDER/1/12/123/1234/12345/123456/1234567
@ -220,11 +195,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() {
@ -245,18 +215,16 @@ 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'
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() {
@ -284,18 +252,16 @@ 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'
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() {
@ -319,60 +285,61 @@ 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'
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'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_HOME_ICON='home-icon'
cd ~
assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%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'
FOLDER=~/powerlevel9k-test
local FOLDER=~/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%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
local FOLDER=/tmp/powerlevel9k-test
mkdir $FOLDER
cd $FOLDER
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%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'
local FOLDER="/tmp/powerlevel9k-test/1/2"
mkdir -p $FOLDER
cd $FOLDER
@ -380,12 +347,12 @@ function testChangingDirPathSeparator() {
assertEquals "%K{blue} %F{black}xXxtmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)"
cd -
unset FOLDER
rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_SEPARATOR
}
function testHomeFolderAbbreviation() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
local dir=$PWD
@ -411,21 +378,23 @@ function testHomeFolderAbbreviation() {
}
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'
cd /tmp
assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%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'
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@ -433,9 +402,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
@ -446,10 +412,12 @@ 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'
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@ -457,17 +425,15 @@ 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'
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@ -475,17 +441,15 @@ 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'
mkdir -p /tmp/powerlevel9k-test/1/2
cd /tmp/powerlevel9k-test/1/2
@ -493,17 +457,15 @@ 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'
mkdir -p /tmp/powerlevel9k-test/adam/devl
mkdir -p /tmp/powerlevel9k-test/alice/devl
mkdir -p /tmp/powerlevel9k-test/alice/docs
@ -514,24 +476,23 @@ 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
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
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@ -539,31 +500,34 @@ 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
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
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local 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
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@ -571,21 +535,23 @@ 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'
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'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@ -593,31 +559,34 @@ 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'
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'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local 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'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
local POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND='red'
mkdir /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@ -625,11 +594,12 @@ 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'
mkdir -p ~/powerlevel9k-test
cd ~/powerlevel9k-test
@ -637,11 +607,12 @@ 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'
mkdir -p /tmp/powerlevel9k-test
cd /tmp/powerlevel9k-test
@ -649,7 +620,6 @@ function testDirSeparatorColorRootSubSubdirWorks() {
cd -
rm -fr /tmp/powerlevel9k-test
unset POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
}
source shunit2/source/2.1/src/shunit2

View File

@ -35,51 +35,43 @@ function mockGoEmptyGopath() {
function testGo() {
alias go=mockGo
POWERLEVEL9K_GO_ICON=""
local POWERLEVEL9K_GO_ICON=""
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_GO_ICON
unset PWD
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias go
}
function testGoSegmentPrintsNothingIfEmptyGopath() {
alias go=mockGoEmptyGopath
POWERLEVEL9K_CUSTOM_WORLD='echo world'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
}
function testGoSegmentPrintsNothingIfNotInGopath() {
alias go=mockGo
POWERLEVEL9K_CUSTOM_WORLD='echo world'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
}
function testGoSegmentPrintsNothingIfGoIsNotAvailable() {
alias go=noGo
POWERLEVEL9K_CUSTOM_WORLD='echo world'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
unalias go
}

View File

@ -66,32 +66,31 @@ function mockKubectlOtherNamespace() {
}
function testKubeContext() {
alias kubectl=mockKubectl
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias kubectl
}
function testKubeContextOtherNamespace() {
alias kubectl=mockKubectlOtherNamespace
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias kubectl
}
function testKubeContextPrintsNothingIfKubectlNotAvailable() {
alias kubectl=noKubectl
POWERLEVEL9K_CUSTOM_WORLD='echo world'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
unalias kubectl
}

View File

@ -27,42 +27,37 @@ function mockNoLaravelVersion() {
}
function testLaravelVersionSegment() {
alias php=mockLaravelVersion
POWERLEVEL9K_LARAVEL_ICON='x'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unalias php
}
function testLaravelVersionSegmentIfArtisanIsNotAvailable() {
alias php=mockNoLaravelVersion
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LARAVEL_ICON='x'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unset POWERLEVEL9K_CUSTOM_WORLD
unalias php
}
function testLaravelVersionSegmentPrintsNothingIfPhpIsNotAvailable() {
alias php=noPhp
POWERLEVEL9K_CUSTOM_WORLD='echo world'
POWERLEVEL9K_LARAVEL_ICON='x'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_LARAVEL_ICON
unset POWERLEVEL9K_CUSTOM_WORLD
unalias php
}

View File

@ -29,22 +29,19 @@ function mockRust() {
}
function testRust() {
mockRust
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
}
function testRustPrintsNothingIfRustIsNotAvailable() {
POWERLEVEL9K_CUSTOM_WORLD='echo world'
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
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)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset POWERLEVEL9K_CUSTOM_WORLD
}
source shunit2/source/2.1/src/shunit2