test_run.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env zunit
  2. @setup {
  3. load ../alias-finder.plugin.zsh
  4. set_git_aliases() {
  5. unalias -a # all
  6. alias g="git"
  7. alias gc="git commit"
  8. alias gcv="git commit -v"
  9. alias gcvs="git commit -v -S"
  10. }
  11. }
  12. @test 'find aliases that contain input' {
  13. set_git_aliases
  14. run alias-finder "git"
  15. assert "${#lines[@]}" equals 1
  16. assert "${lines[1]}" same_as "g=git"
  17. }
  18. @test 'find aliases that contain input with whitespaces at ends' {
  19. set_git_aliases
  20. run alias-finder " git "
  21. assert "${#lines[@]}" equals 1
  22. assert "${lines[1]}" same_as "g=git"
  23. }
  24. @test 'find aliases that contain multiple words' {
  25. set_git_aliases
  26. run alias-finder "git commit -v"
  27. assert "${#lines[@]}" equals 3
  28. assert "${lines[1]}" same_as "gcv='git commit -v'"
  29. assert "${lines[2]}" same_as "gc='git commit'"
  30. assert "${lines[3]}" same_as "g=git"
  31. }
  32. @test 'find alias that is the same with input when --exact option is set' {
  33. set_git_aliases
  34. run alias-finder -e "git"
  35. assert "${#lines[@]}" equals 1
  36. assert "${lines[1]}" same_as "g=git"
  37. }
  38. @test 'find alias that is the same with multiple words input when --exact option is set' {
  39. set_git_aliases
  40. run alias-finder -e "git commit -v"
  41. assert "${#lines[@]}" equals 1
  42. assert "${lines[1]}" same_as "gcv='git commit -v'"
  43. }
  44. @test 'find alias that is the same with or longer than input when --longer option is set' {
  45. set_git_aliases
  46. run alias-finder -l "git"
  47. assert "${#lines[@]}" equals 4
  48. assert "${lines[1]}" same_as "g=git"
  49. assert "${lines[2]}" same_as "gc='git commit'"
  50. assert "${lines[3]}" same_as "gcv='git commit -v'"
  51. assert "${lines[4]}" same_as "gcvs='git commit -v -S'"
  52. }
  53. @test 'find alias that is the same with or longer than multiple words input when --longer option is set' {
  54. set_git_aliases
  55. run alias-finder -l "git commit -v"
  56. assert "${#lines[@]}" equals 2
  57. assert "${lines[1]}" same_as "gcv='git commit -v'"
  58. assert "${lines[2]}" same_as "gcvs='git commit -v -S'"
  59. }
  60. @test 'find aliases including expensive (longer) than input' {
  61. set_git_aliases
  62. alias expensiveCommands="git commit"
  63. run alias-finder "git commit -v"
  64. assert "${#lines[@]}" equals 4
  65. assert "${lines[1]}" same_as "gcv='git commit -v'"
  66. assert "${lines[2]}" same_as "expensiveCommands='git commit'"
  67. assert "${lines[3]}" same_as "gc='git commit'"
  68. assert "${lines[4]}" same_as "g=git"
  69. }
  70. @test 'find aliases excluding expensive (longer) than input when --cheap option is set' {
  71. set_git_aliases
  72. alias expensiveCommands="git commit"
  73. run alias-finder -c "git commit -v"
  74. assert "${#lines[@]}" equals 3
  75. assert "${lines[1]}" same_as "gcv='git commit -v'"
  76. assert "${lines[2]}" same_as "gc='git commit'"
  77. assert "${lines[3]}" same_as "g=git"
  78. }