You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.6 KiB

  1. #!/usr/bin/env zunit
  2. @setup {
  3. load "../fast-highlight"
  4. setopt interactive_comments
  5. -fast-highlight-fill-option-variables
  6. }
  7. @test 'ls /usr/bin' {
  8. reply=()
  9. PREBUFFER=""
  10. BUFFER="ls /usr/bin"
  11. evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  12. assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}"
  13. assert "$reply[2]" same_as "3 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}"
  14. assert "$reply[3]" same_as ""
  15. }
  16. @test 'ls /bin/df' {
  17. reply=()
  18. PREBUFFER=""
  19. BUFFER="ls /bin/df"
  20. evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  21. assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}"
  22. assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}"
  23. assert "$reply[3]" same_as ""
  24. }
  25. @test 'ls /bin/ls\\n # a comment\\nls /usr/bin' {
  26. reply=()
  27. PREBUFFER=""
  28. BUFFER=$'ls /bin/df\n # a comment\nls /usr/bin'
  29. evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  30. assert "$reply[1]" same_as "0 2 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}"
  31. assert "$reply[2]" same_as "3 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]}"
  32. assert "$reply[3]" same_as "12 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}comment]}"
  33. assert "$reply[4]" same_as "24 26 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}"
  34. assert "$reply[5]" same_as "27 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path-to-dir]}"
  35. assert "$reply[6]" same_as ""
  36. }
  37. @test 'exec {FD}< <( ls /bin )' {
  38. reply=()
  39. PREBUFFER=""
  40. BUFFER=$'exec {FD}< <( ls /bin )'
  41. evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  42. assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}"
  43. assert "$reply[2]" same_as "5 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}exec-descriptor]}"
  44. assert "$reply[3]" same_as ""
  45. }
  46. @test 'case x in x) a;; (y) ;; esac' {
  47. reply=()
  48. PREBUFFER=""
  49. BUFFER=$'case x in\nx) a;;\n(y)\n;;\nesac'
  50. evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  51. assert "$reply[1]" same_as "0 4 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}"
  52. assert "$reply[2]" same_as "5 6 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-input]}"
  53. assert "$reply[3]" same_as "7 9 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}"
  54. assert "$reply[4]" same_as "10 11 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}"
  55. assert "$reply[5]" same_as "11 12 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}"
  56. assert "$reply[6]" same_as "13 14 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}unknown-token]}"
  57. assert "$reply[7]" same_as "17 18 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}"
  58. assert "$reply[8]" same_as "18 19 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-condition]}"
  59. assert "$reply[9]" same_as "19 20 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}case-parentheses]}"
  60. assert "$reply[10]" same_as "24 28 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}reserved-word]}"
  61. assert "$reply[11]" same_as ""
  62. }
  63. @test '-fast-highlight-process "$PREBUFFER" "$BUFFER" 0' {
  64. reply=()
  65. PREBUFFER=""
  66. BUFFER='-fast-highlight-process "$PREBUFFER" "$BUFFER" 0'
  67. evl -fast-highlight-process "\$PREBUFFER" "\$BUFFER" 0
  68. assert "$reply[1]" same_as "0 23 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}function]}"
  69. assert "$reply[2]" same_as "24 36 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}"
  70. assert "$reply[3]" same_as "25 35 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}"
  71. assert "$reply[4]" same_as "37 46 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}"
  72. assert "$reply[5]" same_as "38 45 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}"
  73. assert "$reply[6]" same_as ""
  74. }
  75. @test 'tr : \\\\n <<<$PATH' {
  76. reply=()
  77. PREBUFFER=""
  78. BUFFER='command tr : \\n <<<test$PATH'
  79. evl -fast-highlight-process "\$PREBUFFER" "\$BUFFER" 0
  80. assert "$reply[1]" same_as "0 7 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}precommand]}"
  81. assert "$reply[2]" same_as "8 10 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}command]}"
  82. assert "$reply[3]" same_as "16 19 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-tri]}"
  83. # BUG?: the text spans over non-text (i.e. var) part
  84. assert "$reply[4]" same_as "19 28 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-text]}"
  85. assert "$reply[5]" same_as "23 28 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-var]}"
  86. assert "$reply[6]" same_as ""
  87. }
  88. @test 'local var1; (( var + var1 + $var + $var1 + 123 ))' {
  89. reply=()
  90. PREBUFFER=""
  91. BUFFER='local var1; (( var + var1 + $var + $var1 + 123 ))'
  92. evl -fast-highlight-process "\$PREBUFFER" "\$BUFFER" 0
  93. # Should actually be `reserved-word', but the type -w call returns `builtin'…
  94. assert "$reply[1]" same_as "0 5 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}builtin]}"
  95. assert "$reply[2]" same_as "12 14 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}"
  96. assert "$reply[3]" same_as "15 18 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}matherr]}"
  97. assert "$reply[4]" same_as "21 25 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathvar]}"
  98. assert "$reply[5]" same_as "28 32 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}matherr]}"
  99. assert "$reply[6]" same_as "35 40 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}"
  100. assert "$reply[7]" same_as "43 46 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]}"
  101. assert "$reply[8]" same_as "47 49 ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}"
  102. assert "$reply[9]" same_as ""
  103. }
  104. # vim:ft=zsh:sw=4:sts=4:et