-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(_comp_split): add a function to split a string into an array
- Loading branch information
1 parent
48acf57
commit 10f0fd8
Showing
3 changed files
with
141 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
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,90 @@ | ||
import pytest | ||
|
||
from conftest import assert_bash_exec, bash_env_saved | ||
|
||
|
||
@pytest.mark.bashcomp( | ||
cmd=None, ignore_env=r"^\+declare -f (dump_array|__tester)$" | ||
) | ||
class TestUtilSplit: | ||
@pytest.fixture | ||
def functions(self, bash): | ||
assert_bash_exec( | ||
bash, "dump_array() { printf '<%s>' \"${arr[@]}\"; echo; }" | ||
) | ||
assert_bash_exec( | ||
bash, | ||
'__tester() { local -a arr=(00); _comp_split "${@:1:$#-1}" arr "${@:$#}"; dump_array; }', | ||
) | ||
|
||
def test_1(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester '12 34 56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_2(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester $'12\\n34\\n56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_3(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester '12:34:56'", want_output=True | ||
) | ||
assert output.strip() == "<12:34:56>" | ||
|
||
def test_option_F_1(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester -F : '12:34:56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_option_F_2(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester -F : '12 34 56'", want_output=True | ||
) | ||
assert output.strip() == "<12 34 56>" | ||
|
||
def test_option_l_1(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester -l $'12\\n34\\n56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_option_l_2(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester -l '12 34 56'", want_output=True | ||
) | ||
assert output.strip() == "<12 34 56>" | ||
|
||
def test_option_a_1(self, bash, functions): | ||
output = assert_bash_exec( | ||
bash, "__tester -aF : '12:34:56'", want_output=True | ||
) | ||
assert output.strip() == "<00><12><34><56>" | ||
|
||
def test_protect_from_failglob(self, bash, functions): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.shopt("failglob", True) | ||
output = assert_bash_exec( | ||
bash, "__tester -F '*' '12*34*56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_protect_from_nullglob(self, bash, functions): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.shopt("nullglob", True) | ||
output = assert_bash_exec( | ||
bash, "__tester -F '*' '12*34*56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" | ||
|
||
def test_protect_from_IFS(self, bash, functions): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable("IFS", "34") | ||
output = assert_bash_exec( | ||
bash, "__tester '12 34 56'", want_output=True | ||
) | ||
assert output.strip() == "<12><34><56>" |