diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 14 | ||||
-rwxr-xr-x | debug/iterm.zsh | 86 | ||||
-rw-r--r-- | functions/icons.zsh | 59 | ||||
-rwxr-xr-x | test/functions/icons.spec | 362 |
5 files changed, 506 insertions, 17 deletions
diff --git a/.travis.yml b/.travis.yml index 1b2f6d02..134f31f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,9 @@ script: - test/powerlevel9k.spec - test/functions/utilities.spec - test/functions/colors.spec + - test/functions/icons.spec - test/segments/command_execution_time.spec - test/segments/dir.spec - test/segments/rust_version.spec - test/segments/go_version.spec - test/segments/vcs.spec - diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cfcd4a3..cbb9d16b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## next + +### Add debug script for iTerm2 issues + +A new script `debug/iterm.zsh` was added for easier spotting problems with your iTerm2 configuration. + +### Add debug script for font issues + +A new script `debug/font-issues.zsh` was added, so that problems with your font could be spotted easier. + +### `ram` changes + +The `ram` segment now shows the available ram instead of free. + ## v0.6.0 - Fixed a bug where the tag display was broken on detached HEADs. diff --git a/debug/iterm.zsh b/debug/iterm.zsh new file mode 100755 index 00000000..702175ff --- /dev/null +++ b/debug/iterm.zsh @@ -0,0 +1,86 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +if [[ "$TERM_PROGRAM" != "iTerm.app" ]]; then + print "Your Terminal Emulator does not appear to be iTerm2!" + print "This debug script is intended only for iTerm2 terminals." + exit 1 +fi + +if [[ ! -x "/usr/libexec/PlistBuddy" ]]; then + print "To use this debug script, you need to install XCode!" + exit 2 +fi + +local normalFont +local type +local command +local ambiguousDoubleWidth +local minimumContrast +local useDifferentFont + +# Unfortunately the profile name is not unique, but it seems to be the only +# thing that identifies an active profile. There is the "ID of current session +# of current window" though, but that does not match to a `guid` in the plist. +# So, be warned - collisions may occur! +# See: https://groups.google.com/forum/#!topic/iterm2-discuss/0tO3xZ4Zlwg +local currentProfileName=$(osascript -e 'tell application "iTerm2" to profile name of current session of current window') + +# Warning: Dynamic profiles are not taken into account here! +# https://www.iterm2.com/documentation-dynamic-profiles.html + +# Count `guids` in "New Bookmarks"; they should be unique +local profilesCount=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null | grep -c "Guid") +for idx in $(seq 0 "${profilesCount}"); do + local profileName=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Name:" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null) + if [[ "${profileName}" == "${currentProfileName}" ]]; then + # "Normal Font" + normalFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Normal\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + type=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Terminal\ Type:" ~/Library/Preferences/com.googlecode.iterm2.plist) + command=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Command:" ~/Library/Preferences/com.googlecode.iterm2.plist) + ambiguousDoubleWidth=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Ambiguous\ Double\ Width:" ~/Library/Preferences/com.googlecode.iterm2.plist) + minimumContrast=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Minimum\ Contrast:" ~/Library/Preferences/com.googlecode.iterm2.plist) + + # Font for non-ascii characters + # Only check for a different non-ASCII font, if the user checked + # the "use a different font for non-ascii text" switch. + useDifferentFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Use\ Non-ASCII\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$useDifferentFont" == "true" ]]; then + nonAsciiFont=$(/usr/libexec/PlistBuddy -c "Print :New\ Bookmarks:${idx}:Non\ Ascii\ Font:" ~/Library/Preferences/com.googlecode.iterm2.plist) + if [[ "$normalFont" != "$nonAsciiFont" ]]; then + normalFont="$normalFont (normal) / $nonAsciiFont (non-ascii)" + fi + fi + break + fi +done + +print -P "You use %F{blue}iTerm2%f with the following settings:" +print -P " Font: ${normalFont}" +print -P " Terminal-Type: ${type}" +print -P " Command: ${command}" + +############################# +# Analyse possible problems # +############################# +local problemsFound +if [[ "${ambiguousDoubleWidth}" == "true" ]]; then + problemsFound="${problemsFound}\n * Please uncheck 'Treat ambiguous characters as double-width'." +fi +if (( minimumContrast > 0 )); then + problemsFound="${problemsFound}\n * Please set minimum contrast to zero." +fi +if [[ $(echo "${normalFont}" | grep -c -E "Powerline|Awesome|Nerd|Source Code Pro") -eq 0 ]]; then + problemsFound="${problemsFound}\n * It does not seem like you use an Powerline-enabled or Awesome Terminal Font!" +fi + +############################# +# Output problems # +############################# +if [[ -n "${problemsFound}" ]]; then + print -P "\n" + print -P "%F{yellow}Possible Problems found:%f" + print -P "${problemsFound}" +else + print -P "%F{green}No Problems found%f. Yay!" +fi diff --git a/functions/icons.zsh b/functions/icons.zsh index 26412543..413ea19b 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -86,6 +86,8 @@ case $POWERLEVEL9K_MODE in 'awesome-fontconfig') # fontconfig with awesome-font required! See # https://github.com/gabrielelana/awesome-terminal-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( LEFT_SEGMENT_SEPARATOR $'\uE0B0' # RIGHT_SEGMENT_SEPARATOR $'\uE0B2' # @@ -149,6 +151,8 @@ case $POWERLEVEL9K_MODE in 'nerdfont-fontconfig') # nerd-font patched (complete) font required! See # https://github.com/ryanoasis/nerd-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( LEFT_SEGMENT_SEPARATOR $'\uE0B0' # RIGHT_SEGMENT_SEPARATOR $'\uE0B2' # @@ -156,22 +160,23 @@ case $POWERLEVEL9K_MODE in LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' # RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # CARRIAGE_RETURN_ICON $'\u21B5' # ↵ - ROOT_ICON $'\u26A1' # ⚡ + ROOT_ICON $'\uE614 ' # RUBY_ICON $'\uF219 ' # AWS_ICON $'\uF270' # - AWS_EB_ICON $'\U1F331 ' # 🌱 + AWS_EB_ICON $'\UF1BD ' # BACKGROUND_JOBS_ICON $'\uF013 ' # TEST_ICON $'\uF188' # - TODO_ICON $'\u2611' # ☑ - BATTERY_ICON $'\uF241 ' # - OK_ICON $'\u2713' # ✓ - FAIL_ICON $'\u2718' # ✘ + TODO_ICON $'\uF133' # + BATTERY_ICON $'\UF240 ' # + DISK_ICON $'\uF0A0' # + OK_ICON $'\uF00C' # + FAIL_ICON $'\uF00D' # SYMFONY_ICON $'\uE757' # - NODE_ICON $'\u2B22' # ⬢ + NODE_ICON $'\uE617 ' # MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─ MULTILINE_SECOND_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─ APPLE_ICON $'\uF179' # - FREEBSD_ICON $'\U1F608 ' # 😈 + FREEBSD_ICON $'\UF30E ' # LINUX_ICON $'\uF17C' # SUNOS_ICON $'\uF185 ' # HOME_ICON $'\uF015' # @@ -189,22 +194,30 @@ case $POWERLEVEL9K_MODE in VCS_INCOMING_CHANGES_ICON $'\uF01A ' # VCS_OUTGOING_CHANGES_ICON $'\uF01B ' # VCS_TAG_ICON $'\uF02B ' # - VCS_BOOKMARK_ICON $'\uF462' # + VCS_BOOKMARK_ICON $'\uF461 ' # VCS_COMMIT_ICON $'\uE729 ' # - VCS_BRANCH_ICON $'\uF126' # + VCS_BRANCH_ICON $'\uF126 ' # VCS_REMOTE_BRANCH_ICON $'\uE728 ' # VCS_GIT_ICON $'\uF113 ' # + VCS_GIT_GITHUB_ICON $'\uE709 ' # + VCS_GIT_BITBUCKET_ICON $'\uE703 ' # + VCS_GIT_GITLAB_ICON $'\uF296 ' # VCS_HG_ICON $'\uF0C3 ' # - VCS_SVN_ICON '(svn) ' - RUST_ICON $'\uE7A8' # - PYTHON_ICON $'\uE73C' # + VCS_SVN_ICON $'\uE72D ' # + RUST_ICON $'\uE7A8 ' # + PYTHON_ICON $'\UE73C ' # SWIFT_ICON $'\uE755' # - PUBLIC_IP_ICON '' + PUBLIC_IP_ICON $'\UF0AC' # + LOCK_ICON $'\UF023' # + EXECUTION_TIME_ICON $'\uF252' # + SSH_ICON $'\uF489' # ) ;; *) # Powerline-Patched Font required! # See https://github.com/Lokaltog/powerline-fonts + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( LEFT_SEGMENT_SEPARATOR $'\uE0B0' # RIGHT_SEGMENT_SEPARATOR $'\uE0B2' # @@ -270,6 +283,8 @@ esac # Override the above icon settings with any user-defined variables. case $POWERLEVEL9K_MODE in 'flat') + # Set the right locale to protect special characters + local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons[LEFT_SEGMENT_SEPARATOR]='' icons[RIGHT_SEGMENT_SEPARATOR]='' icons[LEFT_SUBSEGMENT_SEPARATOR]='|' @@ -300,8 +315,20 @@ function print_icon() { fi } +# Get a list of configured icons +# * $1 string - If "original", then the original icons are printed, +# otherwise "print_icon" is used, which takes the users +# overrides into account. get_icon_names() { - for key in ${(@k)icons}; do - echo "POWERLEVEL9K_$key: ${icons[$key]}" + # Iterate over a ordered list of keys of the icons array + for key in ${(@kon)icons}; do + echo -n "POWERLEVEL9K_$key: " + if [[ "${1}" == "original" ]]; then + # print the original icons as they are defined in the array above + echo "${icons[$key]}" + else + # print the icons as they are configured by the user + echo "$(print_icon "$key")" + fi done } diff --git a/test/functions/icons.spec b/test/functions/icons.spec new file mode 100755 index 00000000..c8d88644 --- /dev/null +++ b/test/functions/icons.spec @@ -0,0 +1,362 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + # Store old value for LC_CTYPE + _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" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { + POWERLEVEL9K_MODE="awesome-patched" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { + POWERLEVEL9K_MODE="awesome-fontconfig" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { + POWERLEVEL9K_MODE="nerdfont-fontconfig" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInFlatMode() { + POWERLEVEL9K_MODE="flat" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +function testLcCtypeIsSetCorrectlyInCompatibleMode() { + POWERLEVEL9K_MODE="compatible" + # Load Powerlevel9k + source functions/icons.zsh + + assertEquals 'en_US.UTF-8' "${LC_CTYPE}" +} + +# Go through all icons defined in default mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInDefaultMode() { + # Always compare against this mode + local _P9K_TEST_MODE="default" + 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 + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in awesome-patched mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInAwesomePatchedMode() { + # Always compare against this mode + local _P9K_TEST_MODE="awesome-patched" + 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 + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in awesome-fontconfig mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInAwesomeFontconfigMode() { + # Always compare against this mode + local _P9K_TEST_MODE="awesome-fontconfig" + 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 + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "nerdfont-fontconfig" mode + POWERLEVEL9K_MODE="nerdfont-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +# Go through all icons defined in nerdfont-fontconfig mode, and +# check if all of them are defined in the other modes. +function testAllIconsAreDefinedLikeInNerdfontFontconfigMode() { + # Always compare against this mode + local _P9K_TEST_MODE="nerdfont-fontconfig" + 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 + # is in the values of our flat array. + typeset -ah _ICONS_UNDER_TEST + _ICONS_UNDER_TEST=(${(k)icons[@]}) + + # Switch to "default" mode + POWERLEVEL9K_MODE="default" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + # Iterate over all keys found in the _ICONS_UNDER_TEST + # array and compare it with the icons array of the + # current POWERLEVEL9K_MODE. + # Use parameter expansion, to directly check if the + # key exists in the flat current array of keys. That + # is quite complicated, but there seems no easy way + # to check the mere existance of a key in an array. + # The usual way would always return the value, so that + # would do the wrong thing as we have some (on purpose) + # empty values. + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-patched" mode + POWERLEVEL9K_MODE="awesome-patched" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "awesome-fontconfig" mode + POWERLEVEL9K_MODE="awesome-fontconfig" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "flat" mode + POWERLEVEL9K_MODE="flat" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + # Switch to "compatible" mode + POWERLEVEL9K_MODE="compatible" + source functions/icons.zsh + typeset -ah current_icons + current_icons=(${(k)icons[@]}) + for key in ${_ICONS_UNDER_TEST}; do + assertTrue "The key ${key} does exist in ${_P9K_TEST_MODE} mode, but not in ${POWERLEVEL9K_MODE}!" "(( ${+current_icons[(r)$key]} ))" + done + + unset current_icons + unset _ICONS_UNDER_TEST +} + +source shunit2/source/2.1/src/shunit2
\ No newline at end of file |