Skip to content

Commit

Permalink
is-globstar: native bash solution, grep solution had weird behaviour
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
balupton committed Sep 1, 2023
1 parent d867134 commit 2baf666
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions commands/is-globstar
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
#!/usr/bin/env bash

function is_globstar_test() (
source "$DOROTHY/sources/bash.bash"
echo-segment --h1="TEST: $0"

eval-tester --name='empty' --status=1 \
-- is-globstar

eval-tester --name='empty string' --status=1 \
-- is-globstar ''

eval-tester --name='non-globstar string' --status=1 \
-- is-globstar ' /Users/runner/.cache/dorothy/unziptar/5241/rg'

eval-tester --name='star string' --status=1 \
-- is-globstar ' /Users/runner/.cache/dorothy/*/unziptar/5241/rg'

eval-tester --name='globstar string' --status=0 \
-- is-globstar ' /Users/runner/.cache/dorothy/**/unziptar/5241/rg'

echo-segment --g1="TEST: $0"
return 0
)
function is_globstar() (
source "$DOROTHY/sources/bash.bash"

# https://stackoverflow.com/a/240181
grep --quiet --fixed-strings --regexp='**' <<<"$*"
[[ $* == *'**'* ]]
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
is_globstar "$@"
if test "$*" = '--test'; then
is_globstar_test
else
is_globstar "$@"
fi
fi

0 comments on commit 2baf666

Please sign in to comment.