diff --git a/.github/ISSUE_TEMPLATE/ask_question.md b/.github/ISSUE_TEMPLATE/ask_question.md index bf31a5e..5385b4f 100644 --- a/.github/ISSUE_TEMPLATE/ask_question.md +++ b/.github/ISSUE_TEMPLATE/ask_question.md @@ -1,10 +1,9 @@ --- name: Question about: Ask a question. -title: '' +title: "" labels: question -assignees: '' - +assignees: "" --- **Question** diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 0b9badc..d23c653 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve -title: '' +title: "" labels: bug assignees: Gazorby - --- **Describe the bug** @@ -20,8 +19,9 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **System (please complete the following information):** - - fish version - - Distribution `cat /etc/os-release` + +- fish version +- Distribution `cat /etc/os-release` **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11fc491..d883b8f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' +title: "" labels: enhancement -assignees: '' - +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ed857fd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + + steps: + - uses: actions/checkout@v3 + - uses: fish-actions/install-fish@v1.1.0 + + - name: Install abbreviation-tips with Fisher + uses: fish-shop/install-plugin@v1 + with: + plugin-manager: fisher + plugins: gazorby/fish-abbreviation-tips + + - name: Run Fishtape tests + uses: fish-shop/run-fishtape-tests@v1 + with: + pattern: tests/**.fish + + syntax-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: fish-actions/install-fish@v1 + + - uses: fish-actions/syntax-check@v1 + + # Check Fish format + format-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: fish-actions/install-fish@v1 + + - uses: fish-actions/format-check@v1 + + # Check Markdown and Yaml format + prettier: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actionsx/prettier@v2 + with: + args: --check . diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index ca16781..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: Checkout - uses: actions/checkout@v2 - - # Runs a set of commands using the runners shell - - name: Install fish - run: | - sudo add-apt-repository ppa:fish-shell/release-3 - sudo apt-get update - sudo apt-get -y install fish - - - name: Install fisher - run: | - fish --version - fish -c "curl -sL git.io/fisher | source && fisher install jorgebucaran/fisher" - - # Runs a single command using the runners shell - - name: Run tests - run: | - fish -c "fisher install jorgebucaran/fishtape; and fisher install ." - fish -c "fishtape test/*.fish" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..bc046c0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-toml + - id: mixed-line-ending + - id: check-case-conflict + - id: check-merge-conflict + - id: check-docstring-first + - id: check-added-large-files + - id: check-executables-have-shebangs + - id: debug-statements + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: trailing-whitespace + + - repo: https://github.com/hugoh/pre-commit-fish.git + rev: v1.2 + hooks: + - id: fish_syntax + - id: fish_indent + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v2.7.1" + hooks: + - id: prettier + types: [markdown] diff --git a/CHANGELOG.md b/CHANGELOG.md index db86096..b2a32e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,50 +1,53 @@ ## 0.5.1 (2020-05-12) -- ā™»ļø ref: prefix with '__' for private scope + +- ā™»ļø ref: prefix with '\_\_' for private scope - šŸ› fix(regex): don't treat '-' as a word separator ## 0.5.0 (2020-05-12) + - āœØ feat: customize regexes - ā™»ļø ref: use verbose conditional operators ## 0.4.0 (2020-04-20) + - āš” perf: update abbreviations list incrementally # [0.3.1](https://github.com/Gazorby/abbr-tips/compare/v0.3.0...v0.3.1) (2020-04-17) ### šŸ› Bug Fixes -* fix: test variable existence instead of value ([f33cf23](https://github.com/Gazorby/abbr-tips/commit/f33cf23)) -* fix: update function to erase on uninstall ([ba239d1](https://github.com/Gazorby/abbr-tips/commit/ba239d1)) +- fix: test variable existence instead of value ([f33cf23](https://github.com/Gazorby/abbr-tips/commit/f33cf23)) +- fix: update function to erase on uninstall ([ba239d1](https://github.com/Gazorby/abbr-tips/commit/ba239d1)) # [0.3.0](https://github.com/Gazorby/abbr-tips/compare/v0.2.0...v0.3.0) (2020-04-16) ### ā™»ļø Refactor -* refactor: remove flock dependency ([376072d](https://github.com/Gazorby/abbr-tips/commit/376072d)) +- refactor: remove flock dependency ([376072d](https://github.com/Gazorby/abbr-tips/commit/376072d)) # [0.2.0](https://github.com/Gazorby/abbr-tips/compare/v0.1.0...v0.2.0) (2020-04-13) ### šŸ› Bug Fixes -* fix: don't use universal scope by default ([832691a](https://github.com/Gazorby/abbr-tips/commit/832691a)) -* fix: erase functions on uninstall ([cd1a75a](https://github.com/Gazorby/abbr-tips/commit/cd1a75a)) -* fix: fix uninstall function ([b58971f](https://github.com/Gazorby/abbr-tips/commit/b58971f)) -* fix: still need univresal scope for abbr lists ([6a700a0](https://github.com/Gazorby/abbr-tips/commit/6a700a0)) +- fix: don't use universal scope by default ([832691a](https://github.com/Gazorby/abbr-tips/commit/832691a)) +- fix: erase functions on uninstall ([cd1a75a](https://github.com/Gazorby/abbr-tips/commit/cd1a75a)) +- fix: fix uninstall function ([b58971f](https://github.com/Gazorby/abbr-tips/commit/b58971f)) +- fix: still need univresal scope for abbr lists ([6a700a0](https://github.com/Gazorby/abbr-tips/commit/6a700a0)) # [0.1.0](https://github.com/Gazorby/abbr-tips/compare/f5ab8ed...v0.1.0) (2020-04-13) ### āœØ Features -* feat: customize tips prompt ([ae29fca](https://github.com/Gazorby/abbr-tips/commit/ae29fca)) -* feat: customize tips update mode ([4681009](https://github.com/Gazorby/abbr-tips/commit/4681009)) -* feat: don't show tips if an abbr was used ([5f2e6ac](https://github.com/Gazorby/abbr-tips/commit/5f2e6ac)) -* feat: prettier tips ([f5ab8ed](https://github.com/Gazorby/abbr-tips/commit/f5ab8ed)) +- feat: customize tips prompt ([ae29fca](https://github.com/Gazorby/abbr-tips/commit/ae29fca)) +- feat: customize tips update mode ([4681009](https://github.com/Gazorby/abbr-tips/commit/4681009)) +- feat: don't show tips if an abbr was used ([5f2e6ac](https://github.com/Gazorby/abbr-tips/commit/5f2e6ac)) +- feat: prettier tips ([f5ab8ed](https://github.com/Gazorby/abbr-tips/commit/f5ab8ed)) ### šŸ› Bug Fixes -* fix: check for abbr status in on whitespace input ([421ede5](https://github.com/Gazorby/abbr-tips/commit/421ede5)) -* fix: delete keybindings when uninstalling ([11ce0ae](https://github.com/Gazorby/abbr-tips/commit/11ce0ae)) -* fix: don't show tips if abbr was used and options added ([a2b5214](https://github.com/Gazorby/abbr-tips/commit/a2b5214)) -* fix: prompt variable not properly set ([1cc43e0](https://github.com/Gazorby/abbr-tips/commit/1cc43e0)) -* fix: properly resetting abbr status ([59e90e2](https://github.com/Gazorby/abbr-tips/commit/59e90e2)) -* fix: reset abbr status after displaying tip ([46c70c1](https://github.com/Gazorby/abbr-tips/commit/46c70c1)) +- fix: check for abbr status in on whitespace input ([421ede5](https://github.com/Gazorby/abbr-tips/commit/421ede5)) +- fix: delete keybindings when uninstalling ([11ce0ae](https://github.com/Gazorby/abbr-tips/commit/11ce0ae)) +- fix: don't show tips if abbr was used and options added ([a2b5214](https://github.com/Gazorby/abbr-tips/commit/a2b5214)) +- fix: prompt variable not properly set ([1cc43e0](https://github.com/Gazorby/abbr-tips/commit/1cc43e0)) +- fix: properly resetting abbr status ([59e90e2](https://github.com/Gazorby/abbr-tips/commit/59e90e2)) +- fix: reset abbr status after displaying tip ([46c70c1](https://github.com/Gazorby/abbr-tips/commit/46c70c1)) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed591bb..c4ed673 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,5 +22,6 @@ You can use (and enhance!) scripts in `test` folder to test your code. You need ## IDE If you are using Visual Studio Code, i recommend these extensions : + - [fish-vscode](https://marketplace.visualstudio.com/items?itemName=skyapps.fish-vscode) for syntax highlighting - [fish-ide](https://marketplace.visualstudio.com/items?itemName=lunaryorn.fish-ide) for syntax errors checking diff --git a/README.md b/README.md index db86613..baf973b 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ gcm => git commit -m So you want a tip when typing `git commit -m "my commit"`, but the command doesn't match exactly `git commit -m`. To tackle this, we have a default regex that will match commands with arguments removed, so your `git commit -m "my commit"` will be tested as `git commit -m`. -You can add such regexes to the `ABBR_TIPS_REGEXES` list, and they will be tested in the order in which they have been added (see [default configuration](#default-configuration)). Matching is lazy, so if the string extracted with the first regex matches an abbreviation/alias, it won't go further. Remember that only the *first matching group* will be tested. (so you must have at least one per regex) +You can add such regexes to the `ABBR_TIPS_REGEXES` list, and they will be tested in the order in which they have been added (see [default configuration](#default-configuration)). Matching is lazy, so if the string extracted with the first regex matches an abbreviation/alias, it won't go further. Remember that only the _first matching group_ will be tested. (so you must have at least one per regex) ## šŸŽ„ Behind the scenes @@ -95,4 +95,5 @@ The plugin will create lists once during installation by calling `__abbr_tips_in Inspired by [zsh-fast-alias-tips](https://github.com/sei40kr/zsh-fast-alias-tips) and [alias-tips](https://github.com/djui/alias-tips) zsh plugins ## šŸ“ License + [MIT](https://github.com/Gazorby/fish-abbreviation-tips/blob/master/LICENSE) diff --git a/conf.d/abbr_tips.fish b/conf.d/abbr_tips.fish index 848ee6d..1c6f180 100644 --- a/conf.d/abbr_tips.fish +++ b/conf.d/abbr_tips.fish @@ -1,7 +1,7 @@ for mode in default insert - bind --mode $mode " " '__abbr_tips_bind_space' - bind --mode $mode \n '__abbr_tips_bind_newline' - bind --mode $mode \r '__abbr_tips_bind_newline' + bind --mode $mode " " __abbr_tips_bind_space + bind --mode $mode \n __abbr_tips_bind_newline + bind --mode $mode \r __abbr_tips_bind_newline end set -g __abbr_tips_used 0 @@ -21,13 +21,9 @@ function __abbr_tips_install --on-event abbr_tips_install set -a ABBR_TIPS_REGEXES '(^(\s?(\w-?)+){1}).*' set -Ux ABBR_TIPS_PROMPT "\nšŸ’” \e[1m{{ .abbr }}\e[0m => {{ .cmd }}" - set -gx ABBR_TIPS_AUTO_UPDATE 'background' + set -gx ABBR_TIPS_AUTO_UPDATE background - # Locking mechanism - # Prevent this file to spawn more than one subshell - if test "$USER" != 'root' - fish -c '__abbr_tips_init' & - end + __abbr_tips_init end function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the current command" @@ -35,9 +31,9 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the set -l cmd (string replace -r -a '\\s+' ' ' -- "$argv" ) # Update abbreviations lists when adding/removing abbreviations - if test "$command[1]" = "abbr" + if test "$command[1]" = abbr # Parse args as abbr options - argparse --name 'abbr' --ignore-unknown 'a/add' 'e/erase' 'g/global' 'U/universal' -- $command + argparse --name abbr --ignore-unknown a/add e/erase g/global U/universal -- $command if set -q _flag_a and not contains -- "$argv[2]" $__ABBR_TIPS_KEYS @@ -48,21 +44,18 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the set -e __ABBR_TIPS_KEYS[$abb] set -e __ABBR_TIPS_VALUES[$abb] end - else if test "$command[1]" = "alias" + else if test "$command[1]" = alias # Update abbreviations list when adding aliases set -l alias_key set -l alias_value # Parse args as `alias` options - argparse --name 'alias' --ignore-unknown 's/save' -- $command + argparse --name alias --ignore-unknown s/save -- $command if string match -q '*=*' -- "$argv[2]" - if test (count $argv) = 2 - set command_split (string split '=' -- $argv[2]) - set alias_key "a__$command_split[1]" - set alias_value $command_split[2] - set -a alias_value $command[3..-1] - end + set command_split (string split '=' -- $argv[2]) + set alias_key "a__$command_split[1]" + set alias_value $command_split[2..-1] else set alias_key "a__$argv[2]" set alias_value $argv[3..-1] @@ -77,9 +70,9 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the set -a __ABBR_TIPS_KEYS $alias_key set -a __ABBR_TIPS_VALUES $alias_value end - else if test "$command[1]" = "functions" + else if test "$command[1]" = functions # Parse args as `functions` options - argparse --name 'functions' 'e/erase' -- $command + argparse --name functions e/erase -- $command # Update abbreviations list when removing aliases if set -q _flag_e @@ -102,7 +95,7 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the return else if string match -q -- "alias $cmd *" (alias) return - else if test (type -t "$command[1]") = 'function' + else if test (type -t "$command[1]") = function and count $ABBR_TIPS_ALIAS_WHITELIST >/dev/null and not contains "$command[1]" $ABBR_TIPS_ALIAS_WHITELIST return @@ -136,20 +129,12 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the return end +function __abbr_tips_update --on-event abbr_tips_update + __abbr_tips_clean + __abbr_tips_install +end + function __abbr_tips_uninstall --on-event abbr_tips_uninstall - bind --erase \n - bind --erase \r - bind --erase " " - set --erase __abbr_tips_used - set --erase __abbr_tips_run_once - set --erase __ABBR_TIPS_VALUES - set --erase __ABBR_TIPS_KEYS - set --erase ABBR_TIPS_PROMPT - set --erase ABBR_TIPS_AUTO_UPDATE - set --erase ABBR_TIPS_ALIAS_WHITELIST - set --erase ABBR_TIPS_REGEXES + __abbr_tips_clean functions --erase __abbr_tips_init - functions --erase __abbr_tips_bind_newline - functions --erase __abbr_tips_bind_space - functions --erase __abbr_tips end diff --git a/functions/__abbr_tips_bind_newline.fish b/functions/__abbr_tips_bind_newline.fish index 8cc8992..6d91aeb 100644 --- a/functions/__abbr_tips_bind_newline.fish +++ b/functions/__abbr_tips_bind_newline.fish @@ -6,5 +6,5 @@ function __abbr_tips_bind_newline set -g __abbr_tips_used 0 end end - commandline -f 'execute' + commandline -f execute end diff --git a/functions/__abbr_tips_bind_space.fish b/functions/__abbr_tips_bind_space.fish index 0f37103..e83caf6 100644 --- a/functions/__abbr_tips_bind_space.fish +++ b/functions/__abbr_tips_bind_space.fish @@ -7,5 +7,5 @@ function __abbr_tips_bind_space set -g __abbr_tips_used 0 end end - commandline -f 'expand-abbr' + commandline -f expand-abbr end diff --git a/functions/__abbr_tips_clean.fish b/functions/__abbr_tips_clean.fish new file mode 100644 index 0000000..772bcc6 --- /dev/null +++ b/functions/__abbr_tips_clean.fish @@ -0,0 +1,16 @@ +function __abbr_tips_clean -d "Clean plugin variables and functions" + bind --erase \n + bind --erase \r + bind --erase " " + set --erase __abbr_tips_used + set --erase __abbr_tips_run_once + set --erase __ABBR_TIPS_VALUES + set --erase __ABBR_TIPS_KEYS + set --erase ABBR_TIPS_PROMPT + set --erase ABBR_TIPS_AUTO_UPDATE + set --erase ABBR_TIPS_ALIAS_WHITELIST + set --erase ABBR_TIPS_REGEXES + functions --erase __abbr_tips_bind_newline + functions --erase __abbr_tips_bind_space + functions --erase __abbr_tips +end diff --git a/test/fish-abbreviation-tips.fish b/test/fish-abbreviation-tips.fish deleted file mode 100644 index 4df19f8..0000000 --- a/test/fish-abbreviation-tips.fish +++ /dev/null @@ -1,194 +0,0 @@ -# Use with jorgebucaran/fishtape to run tests -# i.e. fishtape test/fish-abbreviation-tips.fish - -function setup - # Source plugin - source functions/__abbr_tips_init.fish - source conf.d/abbr_tips.fish - source functions/__abbr_tips_bind_newline.fish - source functions/__abbr_tips_bind_space.fish - # Backup settings variables - set -g tmp_keys $__ABBR_TIPS_KEYS - set -g tmp_values $__ABBR_TIPS_VALUES - set -g tmp_tips_prompt $ABBR_TIPS_PROMPT - set -g ABBR_TIPS_PROMPT "{{ .abbr }} => {{ .cmd }}" -end - -function teardown - # Restore variables - set __ABBR_TIPS_KEYS $tmp_keys - set __ABBR_TIPS_VALUES $tmp_values - set ABBR_TIPS_PROMPT "$tmp_tips_prompt" -end - -function clear_test_var - # Clear variables to prevent the results - # of each unit test from affecting each other - set -g __ABBR_TIPS_KEYS - set -g __ABBR_TIPS_VALUES - abbr -e __abbr_test - abbr -e __abbr_test_one - abbr -e __abbr_test_two -end - -setup - -# Tests - -# Initialization -@test "initial tip key" ( - clear_test_var - abbr -a __abbr_test ps - set -e __ABBR_TIPS_KEYS - __abbr_tips_init - contains "__abbr_test" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "initial tip value" ( - clear_test_var - abbr -a __abbr_test ps - set -e __ABBR_TIPS_VALUES - __abbr_tips_init - contains "ps" $__ABBR_TIPS_VALUES -) "$status" = 0 - - -# Add abbreviation -@test "add abbreviation tip key" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test grep -q' - contains "__abbr_test" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "add abbreviation tip value" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test grep -q' - contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - -@test "add abbreviation tip key with simple quotes" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test \'grep -q\'' - contains "__abbr_test" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "add abbreviation tip value with simple quotes" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test \'grep -q\'' - contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - -@test "add abbreviation tip key with double quotes" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test "grep -q"' - contains "__abbr_test" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "add abbreviation tip value with double quotes" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test "grep -q"' - contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - - -# Remove abbreviation -@test "remove abbreviation tip key" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test ps' - __abbr_tips 'abbr -e __abbr_test' - not contains "__abbr_test" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "remove abbreviation tip value" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test ps' - __abbr_tips 'abbr -e __abbr_test' - not contains "ps" $__ABBR_TIPS_VALUES -) "$status" = 0 - - -# Add alias -@test "add alias tip key simple quotes" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias \'grep -q\'' - contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "add alias tip value simple quotes" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias \'grep -q\'' - contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - -@test "add alias tip key double quotes" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias "grep -q"' - contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "add alias tip value double quotes" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias "grep -q"' - contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - -@test "add alias tip value with =" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias=grep"' - contains "grep" $__ABBR_TIPS_VALUES -) "$status" = 0 - -@test "add alias tip key with =" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias=grep"' - contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS -) "$status" = 0 - - -# Remove alias -@test "remove alias tip key" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias "grep -q"' - __abbr_tips 'functions --erase __abbr_test_alias' - not contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS -) "$status" = 0 - -@test "remove alias tip value" ( - clear_test_var - __abbr_tips 'alias __abbr_test_alias "grep -q"' - __abbr_tips 'functions --erase __abbr_test_alias' - not contains "grep -q" $__ABBR_TIPS_VALUES -) "$status" = 0 - - -# Test tip -@test "abbreviation tip match" ( - clear_test_var - __abbr_tips 'abbr -a __abbr_test ps' - echo (__abbr_tips 'ps') -) = "__abbr_test => ps" - -@test "alias tip match" ( - clear_test_var - alias __abbr_test_alias "grep -q" - __abbr_tips 'alias __abbr_test_alias "grep -q"' - echo (__abbr_tips 'grep -q') -) = "__abbr_test_alias => grep -q" - -@test "multiple abbreviation tip match" ( - clear_test_var - abbr -a __abbr_test_one ps - abbr -a __abbr_test_two "grep -q" - __abbr_tips_init - echo (__abbr_tips 'grep -q') -) = "__abbr_test_two => grep -q" - -@test "multiple alias tip match" ( - clear_test_var - alias abbr_test_alias_one ps - alias abbr_test_alias_two "grep -q" - __abbr_tips_init - echo (__abbr_tips 'grep -q') -) = "abbr_test_alias_two => grep -q" - -teardown diff --git a/tests/common.fish b/tests/common.fish new file mode 100644 index 0000000..f182a71 --- /dev/null +++ b/tests/common.fish @@ -0,0 +1,33 @@ +# Use with jorgebucaran/fishtape to run tests +# i.e. fishtape test/fish-abbreviation-tips.fish + +function setup + # Source plugin + source functions/__abbr_tips_init.fish + source functions/__abbr_tips_clean.fish + source conf.d/abbr_tips.fish + source functions/__abbr_tips_bind_newline.fish + source functions/__abbr_tips_bind_space.fish + # Backup settings variables + set -g tmp_keys $__ABBR_TIPS_KEYS + set -g tmp_values $__ABBR_TIPS_VALUES + set -g tmp_tips_prompt $ABBR_TIPS_PROMPT + set -g ABBR_TIPS_PROMPT "{{ .abbr }} => {{ .cmd }}" +end + +function teardown + # Restore variables + set __ABBR_TIPS_KEYS $tmp_keys + set __ABBR_TIPS_VALUES $tmp_values + set ABBR_TIPS_PROMPT "$tmp_tips_prompt" +end + +function clear_test_var + # Clear variables to prevent the results + # of each unit test from affecting each other + set -g __ABBR_TIPS_KEYS + set -g __ABBR_TIPS_VALUES + abbr -e __abbr_test + abbr -e __abbr_test_one + abbr -e __abbr_test_two +end diff --git a/tests/test_abbr.fish b/tests/test_abbr.fish new file mode 100644 index 0000000..8d38228 --- /dev/null +++ b/tests/test_abbr.fish @@ -0,0 +1,59 @@ +source (string join "/" (dirname (status --current-filename)) "common.fish") + +setup + +# Add abbreviation +@test "add abbreviation tip key" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test grep -q' + contains "__abbr_test" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add abbreviation tip value" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test grep -q' + contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add abbreviation tip key with simple quotes" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test \'grep -q\'' + contains "__abbr_test" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add abbreviation tip value with simple quotes" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test \'grep -q\'' + contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add abbreviation tip key with double quotes" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test "grep -q"' + contains "__abbr_test" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add abbreviation tip value with double quotes" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test "grep -q"' + contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + + +# Remove abbreviation +@test "remove abbreviation tip key" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test ps' + __abbr_tips 'abbr -e __abbr_test' + not contains "__abbr_test" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "remove abbreviation tip value" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test ps' + __abbr_tips 'abbr -e __abbr_test' + not contains "ps" $__ABBR_TIPS_VALUES +) "$status" = 0 + + +teardown diff --git a/tests/test_alias.fish b/tests/test_alias.fish new file mode 100644 index 0000000..bd5a9be --- /dev/null +++ b/tests/test_alias.fish @@ -0,0 +1,70 @@ +source (string join "/" (dirname (status --current-filename)) "common.fish") + +setup + +# Add alias +@test "add alias tip key simple quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias \'grep -q\'' + contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add alias tip value simple quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias \'grep -q\'' + contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add alias tip key double quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias "grep -q"' + contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add alias tip value double quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias "grep -q"' + contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add alias tip value with =" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias=grep' + contains "grep" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add alias tip key with =" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias=grep' + contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "add alias tip value with = and quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias="grep "' + contains "grep" $__ABBR_TIPS_VALUES +) "$status" = 0 + +@test "add alias tip key with = and quotes" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias="grep "' + contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS +) "$status" = 0 + +# Remove alias +@test "remove alias tip key" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias "grep -q"' + __abbr_tips 'functions --erase __abbr_test_alias' + not contains "a____abbr_test_alias" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "remove alias tip value" ( + clear_test_var + __abbr_tips 'alias __abbr_test_alias "grep -q"' + __abbr_tips 'functions --erase __abbr_test_alias' + not contains "grep -q" $__ABBR_TIPS_VALUES +) "$status" = 0 + + +teardown diff --git a/tests/test_plugin_init.fish b/tests/test_plugin_init.fish new file mode 100644 index 0000000..3b52b92 --- /dev/null +++ b/tests/test_plugin_init.fish @@ -0,0 +1,22 @@ +source (string join "/" (dirname (status --current-filename)) "common.fish") + +setup + +# Initialization +@test "initial tip key" ( + clear_test_var + abbr -a __abbr_test ps + set -e __ABBR_TIPS_KEYS + __abbr_tips_init + contains "__abbr_test" $__ABBR_TIPS_KEYS +) "$status" = 0 + +@test "initial tip value" ( + clear_test_var + abbr -a __abbr_test ps + set -e __ABBR_TIPS_VALUES + __abbr_tips_init + contains "ps" $__ABBR_TIPS_VALUES +) "$status" = 0 + +teardown diff --git a/tests/test_plugin_update.fish b/tests/test_plugin_update.fish new file mode 100644 index 0000000..b0dec2f --- /dev/null +++ b/tests/test_plugin_update.fish @@ -0,0 +1,44 @@ +source (string join "/" (dirname (status --current-filename)) "common.fish") + +# Test that plugin update reset tip keys + +setup + +@test "plugin update __ABBR_TIPS_KEYS length" ( + set len_keys (count $__ABBR_TIPS_KEYS) + set -a __ABBR_TIPS_KEYS __wrong_key + __abbr_tips_update + test (count $__ABBR_TIPS_KEYS) -eq $len_keys +) "$status" = 0 + +setup + +@test "plugin update __ABBR_TIPS_KEYS value" ( + set last_key "$__ABBR_TIPS_KEYS[-1]" + set -a __ABBR_TIPS_KEYS __wrong_key + __abbr_tips_update + test "$__ABBR_TIPS_KEYS[-1]" = "$last_key" +) "$status" = 0 + +setup + +# Test that plugin update reset tip values + +@test "plugin update __ABBR_TIPS_VALUES length" ( + set len_keys (count $__ABBR_TIPS_VALUES) + set -a __ABBR_TIPS_VALUES __wrong_key + __abbr_tips_update + test (count $__ABBR_TIPS_VALUES) -eq $len_keys +) "$status" = 0 + +setup + +@test "plugin update __ABBR_TIPS_VALUES value" ( + set last_key "$__ABBR_TIPS_VALUES[-1]" + set -a __ABBR_TIPS_VALUES __wrong_key + __abbr_tips_update + test "$__ABBR_TIPS_VALUES[-1]" = "$last_key" +) "$status" = 0 + + +teardown diff --git a/tests/test_tips.fish b/tests/test_tips.fish new file mode 100644 index 0000000..11f6e7f --- /dev/null +++ b/tests/test_tips.fish @@ -0,0 +1,35 @@ +source (string join "/" (dirname (status --current-filename)) "common.fish") + +setup + +# Test tip +@test "abbreviation tip match" ( + clear_test_var + __abbr_tips 'abbr -a __abbr_test ps' + echo (__abbr_tips 'ps') +) = "__abbr_test => ps" + +@test "alias tip match" ( + clear_test_var + alias __abbr_test_alias "grep -q" + __abbr_tips 'alias __abbr_test_alias "grep -q"' + echo (__abbr_tips 'grep -q') +) = "__abbr_test_alias => grep -q" + +@test "multiple abbreviation tip match" ( + clear_test_var + abbr -a __abbr_test_one ps + abbr -a __abbr_test_two "grep -q" + __abbr_tips_init + echo (__abbr_tips 'grep -q') +) = "__abbr_test_two => grep -q" + +@test "multiple alias tip match" ( + clear_test_var + alias abbr_test_alias_one ps + alias abbr_test_alias_two "grep -q" + __abbr_tips_init + echo (__abbr_tips 'grep -q') +) = "abbr_test_alias_two => grep -q" + +teardown