hyperlink.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # Test --hyperlink processing
  3. # Copyright (C) 2017-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ls
  16. # lookup based on first letter
  17. encode() {
  18. printf '%s\n' \
  19. 'sp%20ace' 'ques%3ftion' 'back%5cslash' 'encoded%253Fquestion' 'testdir' \
  20. "$1" |
  21. sort -k1,1.1 -s | uniq -w1 -d
  22. }
  23. ls_encoded() {
  24. ef=$(encode "$1")
  25. echo "$ef" | grep -q 'dir$' && dir=: || dir=''
  26. printf '\033]8;;file:///%s\a%s\033]8;;\a%s\n' \
  27. "$ef" "$1" "$dir"
  28. }
  29. # These could be encoded, so remove from consideration
  30. strip_host_and_path() {
  31. sed 's|file://.*/|file:///|'
  32. }
  33. mkdir testdir || framework_failure_
  34. (
  35. cd testdir
  36. ls_encoded "testdir" > ../exp.t || framework_failure_
  37. for f in 'back\slash' 'encoded%3Fquestion' 'ques?tion' 'sp ace'; do
  38. touch "$f" || framework_failure_
  39. ls_encoded "$f" >> ../exp.t || framework_failure_
  40. done
  41. )
  42. ln -s testdir testdirl || framework_failure_
  43. (cat exp.t && printf '\n' && sed 's/[^\/]testdir/&l/' exp.t) > exp \
  44. || framework_failure_
  45. ls --hyper testdir testdirl >out.t || fail=1
  46. strip_host_and_path <out.t >out || framework_failure_
  47. compare exp out || fail=1
  48. ln -s '/probably_missing' testlink || framework_failure_
  49. ls -l --hyper testlink > out.t || fail=1
  50. strip_host_and_path <out.t >out || framework_failure_
  51. grep 'file:///probably_missing' out || fail=1
  52. Exit $fail