2020-03-15 14:29:23 +00:00
|
|
|
# RUN: %fish -C 'set -g fish_indent %fish_indent' %s
|
|
|
|
# Test file for fish_indent
|
2020-03-16 18:23:44 +00:00
|
|
|
# Note that littlecheck ignores leading whitespace, so we have to use {{ }} to explicitly match it.
|
2020-03-15 14:29:23 +00:00
|
|
|
|
|
|
|
echo 'echo foo \\
|
|
|
|
| cat' | $fish_indent
|
|
|
|
#CHECK: echo foo \
|
|
|
|
#CHECK: | cat
|
|
|
|
|
|
|
|
echo 'echo foo | \\
|
|
|
|
cat' | $fish_indent
|
|
|
|
#CHECK: echo foo | cat
|
|
|
|
|
|
|
|
echo 'echo foo |
|
|
|
|
cat' | $fish_indent
|
|
|
|
#CHECK: echo foo |
|
|
|
|
#CHECK: cat
|
|
|
|
|
|
|
|
echo 'if true; \\
|
|
|
|
or false
|
|
|
|
echo something
|
|
|
|
end' | $fish_indent
|
|
|
|
#CHECK: if true; or false
|
|
|
|
#CHECK: echo something
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
echo '\\
|
|
|
|
echo wurst' | $fish_indent
|
|
|
|
#CHECK: echo wurst
|
|
|
|
|
|
|
|
echo 'echo foo \\
|
|
|
|
brot' | $fish_indent
|
|
|
|
#CHECK: echo foo \
|
|
|
|
#CHECK: brot
|
|
|
|
|
|
|
|
|
|
|
|
echo 'echo rabarber \\
|
|
|
|
banana' | $fish_indent
|
|
|
|
#CHECK: echo rabarber \
|
|
|
|
#CHECK: banana
|
|
|
|
|
|
|
|
echo 'for x in a \\
|
|
|
|
b \\
|
|
|
|
c
|
|
|
|
echo thing
|
|
|
|
end' | $fish_indent
|
|
|
|
#CHECK: for x in a \
|
|
|
|
#CHECK: b \
|
|
|
|
#CHECK: c
|
|
|
|
#CHECK: echo thing
|
|
|
|
#CHECK: end
|
2020-06-28 21:48:16 +00:00
|
|
|
|
2020-03-15 14:29:23 +00:00
|
|
|
echo 'echo foo |
|
|
|
|
echo banana' | $fish_indent
|
|
|
|
#CHECK: echo foo |
|
|
|
|
#CHECK: echo banana
|
|
|
|
|
|
|
|
echo 'echo foo \\
|
|
|
|
;' | $fish_indent
|
2020-06-28 21:48:16 +00:00
|
|
|
#CHECK: echo foo
|
2020-03-15 14:29:23 +00:00
|
|
|
|
|
|
|
echo 'echo foo \\
|
|
|
|
' | $fish_indent
|
2020-06-28 21:48:16 +00:00
|
|
|
#CHECK: echo foo
|
2020-03-16 18:23:44 +00:00
|
|
|
|
|
|
|
echo -n '
|
|
|
|
begin
|
|
|
|
echo hi
|
|
|
|
|
|
|
|
|
|
|
|
end | cat | cat | begin ; echo hi ; end | begin ; begin ; echo hi ; end ; end arg
|
|
|
|
' | $fish_indent
|
|
|
|
|
|
|
|
#CHECK: begin
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: end | cat | cat | begin
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK: end | begin
|
|
|
|
#CHECK: {{ }}begin
|
|
|
|
#CHECK: {{ }}{{ }}echo hi
|
|
|
|
#CHECK: {{ }}end
|
|
|
|
#CHECK: end arg
|
|
|
|
|
|
|
|
echo -n '
|
|
|
|
switch aloha
|
|
|
|
|
|
|
|
case alpha
|
|
|
|
echo sup
|
|
|
|
|
|
|
|
case beta gamma
|
|
|
|
echo hi
|
|
|
|
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
|
|
|
|
|
|
|
#CHECK: switch aloha
|
|
|
|
#CHECK: {{ }}case alpha
|
|
|
|
#CHECK: {{ }}{{ }}echo sup
|
|
|
|
#CHECK: {{ }}case beta gamma
|
|
|
|
#CHECK: {{ }}{{ }}echo hi
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
echo -n '
|
|
|
|
function hello_world
|
|
|
|
|
|
|
|
\'begin\'
|
|
|
|
echo hi
|
|
|
|
end | cat
|
|
|
|
|
|
|
|
echo sup; echo sup
|
|
|
|
echo hello;
|
|
|
|
|
|
|
|
echo hello
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
|
|
|
|
|
|
|
#CHECK: function hello_world
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: {{ }}begin
|
|
|
|
#CHECK: {{ }}{{ }}echo hi
|
|
|
|
#CHECK: {{ }}end | cat
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: {{ }}echo sup
|
|
|
|
#CHECK: {{ }}echo sup
|
|
|
|
#CHECK: {{ }}echo hello
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: {{ }}echo hello
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
echo -n '
|
|
|
|
echo alpha #comment1
|
|
|
|
#comment2
|
|
|
|
|
|
|
|
#comment3
|
|
|
|
for i in abc #comment1
|
|
|
|
#comment2
|
|
|
|
echo hi
|
|
|
|
end
|
|
|
|
|
|
|
|
switch foo #abc
|
|
|
|
# bar
|
|
|
|
case bar
|
|
|
|
echo baz\
|
|
|
|
qqq
|
|
|
|
case "*"
|
|
|
|
echo sup
|
|
|
|
end' | $fish_indent
|
|
|
|
#CHECK: echo alpha #comment1
|
|
|
|
#CHECK: #comment2
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: #comment3
|
|
|
|
#CHECK: for i in abc #comment1
|
|
|
|
#CHECK: {{ }}#comment2
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK: end
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: switch foo #abc
|
|
|
|
#CHECK: {{ }}# bar
|
|
|
|
#CHECK: {{ }}case bar
|
|
|
|
#CHECK: {{ }}{{ }}echo baz\
|
|
|
|
#CHECK: qqq
|
|
|
|
#CHECK: {{ }}case "*"
|
|
|
|
#CHECK: {{ }}{{ }}echo sup
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
# No indent
|
|
|
|
echo -n '
|
|
|
|
if true
|
|
|
|
else if false
|
|
|
|
echo alpha
|
|
|
|
switch beta
|
|
|
|
case gamma
|
|
|
|
echo delta
|
|
|
|
end
|
|
|
|
end
|
|
|
|
' | $fish_indent -i
|
|
|
|
#CHECK: if true
|
|
|
|
#CHECK: else if false
|
|
|
|
#CHECK: {{^}}echo alpha
|
|
|
|
#CHECK: {{^}}switch beta
|
|
|
|
#CHECK: {{^}}case gamma
|
|
|
|
#CHECK: {{^}}echo delta
|
|
|
|
#CHECK: {{^}}end
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
# Test errors
|
|
|
|
echo -n '
|
|
|
|
begin
|
|
|
|
echo hi
|
|
|
|
else
|
|
|
|
echo bye
|
|
|
|
end; echo alpha "
|
|
|
|
' | $fish_indent
|
|
|
|
#CHECK: begin
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK: else
|
2020-06-28 21:48:16 +00:00
|
|
|
#CHECK:
|
2020-03-16 18:23:44 +00:00
|
|
|
#CHECK: {{^}}echo bye
|
2020-06-28 21:48:16 +00:00
|
|
|
#CHECK: end; echo alpha "
|
2020-03-16 18:23:44 +00:00
|
|
|
|
|
|
|
# issue 1665
|
|
|
|
echo -n '
|
|
|
|
if begin ; false; end; echo hi ; end
|
|
|
|
while begin ; false; end; echo hi ; end
|
|
|
|
' | $fish_indent
|
|
|
|
#CHECK: if begin
|
|
|
|
#CHECK: {{ }}{{ }}false
|
|
|
|
#CHECK: {{ }}end
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK: end
|
|
|
|
#CHECK: while begin
|
|
|
|
#CHECK: {{ }}{{ }}false
|
|
|
|
#CHECK: {{ }}end
|
|
|
|
#CHECK: {{ }}echo hi
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
# issue 2899
|
|
|
|
echo -n '
|
|
|
|
echo < stdin >>appended yes 2>&1 no > stdout maybe 2>& 4 | cat 2>| cat
|
|
|
|
' | $fish_indent
|
|
|
|
#CHECK: echo <stdin >>appended yes 2>&1 no >stdout maybe 2>&4 | cat 2>| cat
|
|
|
|
|
2020-08-08 23:16:02 +00:00
|
|
|
|
|
|
|
# issue 7252
|
|
|
|
echo -n '
|
|
|
|
begin
|
|
|
|
# comment
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^}}begin
|
|
|
|
#CHECK: {{^ }}# comment
|
|
|
|
#CHECK: {{^}}end
|
2020-08-08 23:16:02 +00:00
|
|
|
|
|
|
|
echo -n '
|
|
|
|
begin
|
|
|
|
cmd
|
|
|
|
# comment
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^}}begin
|
|
|
|
#CHECK: {{^ }}cmd
|
|
|
|
#CHECK: {{^ }}# comment
|
|
|
|
#CHECK: {{^}}end
|
2020-08-08 23:16:02 +00:00
|
|
|
|
2020-08-09 01:29:50 +00:00
|
|
|
echo -n '
|
|
|
|
cmd \\
|
|
|
|
continuation
|
|
|
|
' | $fish_indent
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^}}cmd \
|
|
|
|
#CHECK: {{^ }}continuation
|
2020-08-09 01:29:50 +00:00
|
|
|
|
|
|
|
echo -n '
|
|
|
|
begin
|
|
|
|
cmd \
|
|
|
|
continuation
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^}}begin
|
|
|
|
#CHECK: {{^ }}cmd \
|
|
|
|
#CHECK: {{^ }}{{ }}continuation
|
|
|
|
#CHECK: {{^}}end
|
2020-08-09 01:29:50 +00:00
|
|
|
|
|
|
|
|
2020-03-16 18:23:44 +00:00
|
|
|
echo -n '
|
|
|
|
i\
|
|
|
|
f true
|
|
|
|
echo yes
|
|
|
|
en\
|
|
|
|
d
|
|
|
|
|
|
|
|
"whil\
|
|
|
|
e" true
|
|
|
|
"builtin" yes
|
|
|
|
en"d"
|
|
|
|
|
|
|
|
alpha | \
|
|
|
|
beta
|
|
|
|
|
|
|
|
gamma | \
|
|
|
|
# comment3
|
|
|
|
delta
|
|
|
|
|
|
|
|
if true
|
|
|
|
echo abc
|
|
|
|
end
|
|
|
|
|
|
|
|
if false # comment4
|
|
|
|
and true && false
|
|
|
|
echo abc;end
|
|
|
|
|
|
|
|
echo hi |
|
|
|
|
|
|
|
|
echo bye
|
|
|
|
' | $fish_indent
|
|
|
|
#CHECK: i\
|
|
|
|
#CHECK: f true
|
|
|
|
#CHECK: {{ }}echo yes
|
|
|
|
#CHECK: en\
|
|
|
|
#CHECK: d
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: while true
|
|
|
|
#CHECK: {{ }}builtin yes
|
|
|
|
#CHECK: end
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: alpha | beta
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: gamma | \
|
|
|
|
#CHECK: # comment3
|
|
|
|
#CHECK: delta
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: if true
|
|
|
|
#CHECK: {{ }}echo abc
|
|
|
|
#CHECK: end
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: if false # comment4
|
|
|
|
#CHECK: {{ }}and true && false
|
|
|
|
#CHECK: {{ }}echo abc
|
|
|
|
#CHECK: end
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: echo hi |
|
2020-06-28 21:48:16 +00:00
|
|
|
#CHECK: {{ }}echo bye
|
2020-03-16 18:23:44 +00:00
|
|
|
|
|
|
|
echo 'a;;;;;;' | $fish_indent
|
|
|
|
#CHECK: a
|
|
|
|
echo 'echo; echo' | $fish_indent
|
|
|
|
#CHECK: echo
|
|
|
|
#CHECK: echo
|
|
|
|
|
|
|
|
# Check that we keep semicolons for and and or, but only on the same line.
|
|
|
|
printf '%s\n' "a; and b" | $fish_indent
|
|
|
|
#CHECK: a; and b
|
|
|
|
printf '%s\n' "a;" "and b" | $fish_indent
|
|
|
|
#CHECK: a
|
|
|
|
#CHECK: and b
|
2020-08-04 19:39:37 +00:00
|
|
|
printf '%s\n' a "; and b" | $fish_indent
|
2020-03-16 18:23:44 +00:00
|
|
|
#CHECK: a
|
|
|
|
#CHECK: and b
|
|
|
|
printf '%s\n' "a; b" | $fish_indent
|
|
|
|
#CHECK: a
|
|
|
|
#CHECK: b
|
2020-08-04 19:39:37 +00:00
|
|
|
|
|
|
|
echo 'foo &&
|
|
|
|
#
|
|
|
|
bar' | $fish_indent
|
|
|
|
#CHECK: {{^}}foo &&
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^ }}#
|
|
|
|
#CHECK: {{ }}bar
|
2020-08-04 19:39:37 +00:00
|
|
|
|
|
|
|
echo 'command 1 |
|
|
|
|
command 1 cont ||
|
|
|
|
command 2' | $fish_indent
|
|
|
|
#CHECK: {{^}}command 1 |
|
|
|
|
#CHECK: {{^ }}command 1 cont ||
|
2020-08-09 19:15:14 +00:00
|
|
|
#CHECK: {{^ }}command 2
|
2020-08-08 18:22:18 +00:00
|
|
|
|
2020-08-09 21:06:41 +00:00
|
|
|
echo " foo" | $fish_indent --check
|
2020-08-08 18:22:18 +00:00
|
|
|
echo $status
|
|
|
|
#CHECK: 1
|
2020-08-09 21:06:41 +00:00
|
|
|
echo foo | $fish_indent --check
|
2020-08-08 18:22:18 +00:00
|
|
|
echo $status
|
|
|
|
#CHECK: 0
|
2020-08-09 19:14:00 +00:00
|
|
|
|
|
|
|
echo 'thing | # comment
|
|
|
|
thing' | $fish_indent --check
|
|
|
|
echo $status
|
|
|
|
#CHECK: 0
|
2020-08-09 21:37:09 +00:00
|
|
|
|
|
|
|
echo 'echo \
|
|
|
|
# first indented comment
|
|
|
|
# second indented comment
|
|
|
|
indented argument
|
|
|
|
echo' | $fish_indent --check
|
|
|
|
echo $status
|
|
|
|
#CHECK: 0
|
2020-08-17 08:43:55 +00:00
|
|
|
|
|
|
|
echo 'if true;
|
|
|
|
end' | $fish_indent
|
|
|
|
#CHECK: if true{{$}}
|
|
|
|
#CHECK: end
|
|
|
|
|
|
|
|
echo 'if true; and false; or true
|
|
|
|
end' | $fish_indent --check
|
|
|
|
echo $status
|
|
|
|
#CHECK: 0
|
2021-02-16 17:29:43 +00:00
|
|
|
|
|
|
|
echo -n '
|
|
|
|
function hello_continuations
|
|
|
|
echo cmd \
|
|
|
|
echo --opt1 \
|
|
|
|
echo --opt2 \
|
|
|
|
echo --opt3
|
|
|
|
end
|
|
|
|
' | $fish_indent
|
|
|
|
|
|
|
|
#CHECK: function hello_continuations
|
|
|
|
#CHECK: {{^}} echo cmd \
|
|
|
|
#CHECK: {{^}} echo --opt1 \
|
|
|
|
#CHECK: {{^}} echo --opt2 \
|
|
|
|
#CHECK: {{^}} echo --opt3
|
|
|
|
#CHECK: end
|
2021-04-26 22:00:32 +00:00
|
|
|
|
|
|
|
echo "\
|
|
|
|
a=1 \\
|
|
|
|
a=2 \\
|
|
|
|
echo" | $fish_indent --check
|
|
|
|
echo $status #CHECK: 0
|
|
|
|
|
|
|
|
echo "\
|
|
|
|
a=1 \\
|
|
|
|
a=2 echo" | $fish_indent --check
|
|
|
|
echo $status #CHECK: 0
|
2021-08-01 16:38:18 +00:00
|
|
|
|
|
|
|
echo 'first-word\\
|
|
|
|
second-word' | $fish_indent
|
|
|
|
# CHECK: first-word \
|
|
|
|
# CHECK: {{^}} second-word
|
|
|
|
|
|
|
|
echo 'begin
|
|
|
|
first-indented-word\\
|
|
|
|
second-indented-word' | $fish_indent
|
|
|
|
# CHECK: begin
|
|
|
|
# CHECK: {{^}} first-indented-word \
|
|
|
|
# CHECK: {{^}} second-indented-word
|
|
|
|
|
|
|
|
echo 'multiline-\\
|
|
|
|
-word' | $fish_indent --check
|
|
|
|
echo $status #CHECK: 0
|
2024-01-09 18:12:16 +00:00
|
|
|
|
|
|
|
echo 'PATH={$PATH[echo " "' | $fish_indent --ansi
|
|
|
|
# CHECK: PATH={$PATH[echo " "
|
2024-01-10 17:54:25 +00:00
|
|
|
|
|
|
|
echo a\> | $fish_indent
|
|
|
|
# CHECK: a >
|
2024-01-10 18:36:06 +00:00
|
|
|
|
|
|
|
echo a\<\) | $fish_indent
|
|
|
|
# CHECK: a < )
|
|
|
|
echo b\|\{ | $fish_indent
|
|
|
|
# CHECK: b | {
|
2024-01-10 19:47:39 +00:00
|
|
|
|
|
|
|
echo "\'\\\\\x00\'" | string unescape | $fish_indent | string escape
|
|
|
|
# CHECK: \'\\\x00\'
|
2024-01-10 19:56:13 +00:00
|
|
|
|
|
|
|
echo '\"\"\|\x00' | string unescape | $fish_indent | string unescape
|
|
|
|
# CHECK: |
|
2024-02-26 15:12:42 +00:00
|
|
|
|
|
|
|
echo 'a
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
b
|
|
|
|
' | $fish_indent
|
|
|
|
#CHECK: a
|
|
|
|
#CHECK:
|
|
|
|
#CHECK: b
|
|
|
|
|
|
|
|
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo this file starts late
|
|
|
|
" | $fish_indent
|
|
|
|
#CHECK: echo this file starts late
|