-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add __lp_line_count() function and tests
This functions as a "poor man's" "wc -l". It's faster, but due to shell quirks, it can be more difficult to use. The trick is that, like 'wc -l', this function counts newline characters, which means if the input string has none, it will return 0. The double underscore ("__") marks the function as "private" or Liquidprompt only. Themes and users should not use it, as it should only be run when the current directory changes, and Liquidprompt will control that.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
. ../liquidprompt --no-activate | ||
|
||
function test_line_count { | ||
typeset test_string="a normal string" | ||
__lp_line_count "$test_string" | ||
assertEquals "normal 1 line string" $(printf %s "$test_string" | wc -l) $count | ||
|
||
test_string="\ | ||
a | ||
longer | ||
string" | ||
__lp_line_count "$test_string" | ||
assertEquals "3 line string" $(printf %s "$test_string" | wc -l) $count | ||
|
||
test_string="\ | ||
a | ||
longer | ||
string | ||
with many consecutive breaks" | ||
__lp_line_count "$test_string" | ||
assertEquals "consecutive blank lines string" $(printf %s "$test_string" | wc -l) $count | ||
|
||
test_string="" | ||
__lp_line_count "$test_string" | ||
assertEquals "null string" $(printf %s "$test_string" | wc -l) $count | ||
} | ||
|
||
if [ -n "${ZSH_VERSION-}" ]; then | ||
SHUNIT_PARENT="$0" | ||
setopt shwordsplit | ||
fi | ||
|
||
. ./shunit2 |