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