-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function replace all chars to a defined string. The `string_replace` function was changed to pass an empty value as "replacement".
- Loading branch information
1 parent
9933a4e
commit 5e8f64b
Showing
5 changed files
with
52 additions
and
11 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
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,13 @@ | ||
# @depends string_escape | ||
# @depends string_replace | ||
string_replace_all() | ||
{ | ||
local replacement="${1}" | ||
local string="${2}" | ||
|
||
if [[ -z "${string}" ]] && [ ! -t 0 ]; then | ||
string=$(cat /dev/stdin) | ||
fi | ||
|
||
string_replace --type regex "." "$(echo "${replacement}" | string_escape --type regex)" "${string}" | ||
} |
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,21 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../../source | ||
|
||
@test "Replace all chars to defined argument" { | ||
run string_replace_all '*' 'Henrique Moody' | ||
|
||
[[ "${output}" = '**************' ]] | ||
} | ||
|
||
@test "Replace all chars to defined argument in a pipe" { | ||
output=$(echo "Henrique Moody" | string_replace_all '*') | ||
|
||
[[ "${output}" = '**************' ]] | ||
} | ||
|
||
@test "Replace all chars to defined argument in a pipe even if it if empty" { | ||
output=$(echo "Henrique Moody" | string_replace_all) | ||
|
||
[[ -z "${output}" ]] | ||
} |