diff --git a/lib/search.bash b/lib/search.bash index 9afe3a3c..aa9a13ea 100644 --- a/lib/search.bash +++ b/lib/search.bash @@ -98,7 +98,7 @@ _bash-it-search-component() { [[ "${term:0:1}" == "-" ]] && negative_terms=(${negative_terms[@]} ${term:1}) && continue # print asterisk next to each result that is already enabled by the user - local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | cut -b -30 | sed 's/ *\[ \]//g;s/ *\[x\]/*/g;' )) + local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | egrep '\[( |x)\]' | cut -b -30 | sed 's/ *\[ \]//g;s/ *\[x\]/*/g;' )) [[ "${#term_match[@]}" -gt 0 ]] && { matches=(${matches[@]} ${term_match[@]}) # append to the list of results } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats new file mode 100644 index 00000000..4f3e4ffa --- /dev/null +++ b/test/lib/helpers.bats @@ -0,0 +1,10 @@ +#!/usr/bin/env bats + +load ../../lib/composure +load ../../plugins/available/base.plugin + +cite _about _param _example _group _author _version + +load ../../lib/helpers + +## TODO: write some tests. diff --git a/test/lib/search.bats b/test/lib/search.bats index 35b68d86..dc4ba59a 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -15,19 +15,39 @@ NO_COLOR=true [[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]] } -@test "helpers search all ruby et al" { +@test "helpers search ruby gem bundle rake rails" { + # first disable them all, so that the output does not appear with a checkbox + # and we can compoare the result run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' + # Now perform the search run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' - [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] - [[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto ruby' ]] + # And verify + [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \ + [[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto ruby' ]] && \ [[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]] } -@test "search enable and disable" { +@test "search ruby gem bundle -chruby rake rails" { + run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' + run _bash-it-search 'ruby' 'gem' 'bundle' '-chruby' 'rake' 'rails' + [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \ + [[ "${lines[1]/✓/}" == ' plugins => ruby' ]] && \ + [[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]] +} + +@test "search (rails enabled) ruby gem bundle rake rails" { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _enable-alias 'rails' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' - [[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] - [[ "${lines[1]}" == ' plugins => chruby chruby-auto ruby' ]] - [[ "${lines[2]}" == ' completions => bundler gem rake' ]] + [[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] && \ + [[ "${lines[1]}" == ' plugins => chruby chruby-auto ruby' ]] && \ + [[ "${lines[2]}" == ' completions => bundler gem rake' ]] +} + +@test "search (all enabled) ruby gem bundle rake rails" { + run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable' + run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' + [[ "${lines[0]}" == ' aliases => ✓bundler ✓rails' ]] && \ + [[ "${lines[1]}" == ' plugins => ✓ruby' ]] && \ + [[ "${lines[2]}" == ' completions => ✓bundler ✓gem ✓rake' ]] }