File: indent.fish

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (617 lines) | stat: -rw-r--r-- 10,045 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# RUN: fish_indent=%fish_indent %fish %s
# Test file for fish_indent
# Note that littlecheck ignores leading whitespace, so we have to use {{    }} to explicitly match it.

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

echo 'echo foo |
echo banana' | $fish_indent
#CHECK: echo foo |
#CHECK: echo banana

echo 'echo foo \\
;' | $fish_indent
#CHECK: echo foo

echo 'echo foo \\
' | $fish_indent
#CHECK: echo foo

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
#CHECK:
#CHECK: {{^}}echo bye
#CHECK: end; echo alpha "

# 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


# issue 7252
echo -n '
begin
# comment
end
' | $fish_indent
#CHECK: {{^}}begin
#CHECK: {{^    }}# comment
#CHECK: {{^}}end

echo -n '
begin
cmd
# comment
end
' | $fish_indent
#CHECK: {{^}}begin
#CHECK: {{^    }}cmd
#CHECK: {{^    }}# comment
#CHECK: {{^}}end

echo -n '
cmd \\
continuation
' | $fish_indent
#CHECK: {{^}}cmd \
#CHECK: {{^    }}continuation

echo -n '
begin
cmd \
continuation
end
' | $fish_indent
#CHECK: {{^}}begin
#CHECK: {{^    }}cmd \
#CHECK: {{^    }}{{    }}continuation
#CHECK: {{^}}end


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 |
#CHECK: {{    }}echo bye

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
printf '%s\n' a "; and b" | $fish_indent
#CHECK: a
#CHECK: and b
printf '%s\n' "a; b" | $fish_indent
#CHECK: a
#CHECK: b

echo 'foo &&
  #
bar' | $fish_indent
#CHECK: {{^}}foo &&
#CHECK: {{^    }}#
#CHECK: {{    }}bar

echo 'command 1 |
command 1 cont ||
command 2' | $fish_indent
#CHECK: {{^}}command 1 |
#CHECK: {{^    }}command 1 cont ||
#CHECK: {{^    }}command 2

echo " foo" | $fish_indent --check
echo $status
#CHECK: 1
echo foo | $fish_indent --check
echo $status
#CHECK: 0

echo 'thing | # comment
    thing' | $fish_indent --check
echo $status
#CHECK: 0

echo 'echo \
    # first indented comment
    # second indented comment
    indented argument
echo' | $fish_indent --check
echo $status
#CHECK: 0

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

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

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

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 '{ no semi }'
    # CHECK: { no semi }
    echo '{ semi; }'
    # CHECK: { semi; }

    echo '{ multi; no semi }'
    # CHECK: { multi; no semi }
    echo '{ multi; semi; }'
    # CHECK: { multi; semi; }

    echo '{ conj && no semi }'
    # CHECK: { conj && no semi }
    echo '{ conj && semi; }'
    # CHECK: { conj && semi; }

    echo '{ }'
    # CHECK: { }
    echo '{ ; }'
    # CHECK: { }

    echo '
{
echo \\
# continuation comment
}'
    # CHECK: {
    # CHECK: {{^    }}echo \
    # CHECK: {{^        }}# continuation comment
    # TODO: This is currently broken; so this the begin/end equivalent.
    # CHECK: {{^    [}]}}

    echo '{  {  }  }'
    # CHECK: { { } }

    echo '{{}}'
    # CHECK: { { } }

    echo '
{

{
}

}
'
    # CHECK: {{^\{$}}
    # CHECK: {{^    \{$}}
    # CHECK: {{^    \}$}}
    # CHECK: {{^\}$}}

    echo '
{ level 1; {
level 2 } }
'
    # TODO Should add a line break here.
    # CHECK: {{^{ level 1$}}
    # CHECK: {{^    \{$}}
    # CHECK: {{^        level 2$}}
    # CHECK: {{^    \}$}}
    # CHECK: {{^\}$}}
} | $fish_indent

echo 'multiline-\\
-word' | $fish_indent --check
echo $status #CHECK: 0

echo 'PATH={$PATH[echo " "' | $fish_indent --ansi
# CHECK: PATH={$PATH[echo " "

echo a\> | $fish_indent
# CHECK: a >

echo a\<\) | $fish_indent
# CHECK: a < )
echo b\|\{ | $fish_indent
# CHECK: b | {

echo "\'\\\\\x00\'" | string unescape | $fish_indent | string escape
# CHECK: \'\\\x00\'

echo '\"\"\|\x00' | string unescape | $fish_indent | string unescape
# CHECK: |

echo 'a


;


b
' | $fish_indent
#CHECK: a
#CHECK:
#CHECK: b

echo "



echo this file starts late
" | $fish_indent
#CHECK: echo this file starts late

echo 'foo|bar; begin
echo' | $fish_indent --only-indent
# CHECK: foo|bar; begin
# CHECK: {{^}}    echo

echo 'begin
    echo
end' | $fish_indent --only-unindent
# CHECK: {{^}}begin
# CHECK: {{^}}echo
# CHECK: {{^}}end

echo 'if true
    begin
        echo
    end
end' | $fish_indent --only-unindent
# CHECK: {{^}}if true
# CHECK: {{^}}begin
# CHECK: {{^}}echo
# CHECK: {{^}}end
# CHECK: {{^}}end

echo 'begin
    echo
  not indented properly
end' | $fish_indent --only-unindent
# CHECK: {{^}}begin
# CHECK: {{^}}    echo
# CHECK: {{^}}  not indented properly
# CHECK: {{^}}end


echo 'echo (
if true
echo
end
)' | $fish_indent --only-indent
# CHECK: {{^}}echo (
# CHECK: {{^}}    if true
# CHECK: {{^}}        echo
# CHECK: {{^}}    end
# CHECK: {{^}})

echo 'echo (
if true
echo "
multi
line
"
end
)' | $fish_indent --only-indent
# CHECK: {{^}}echo (
# CHECK: {{^}}    if true
# CHECK: {{^}}        echo "
# CHECK: {{^}}multi
# CHECK: {{^}}line
# CHECK: {{^}}"
# CHECK: {{^}}    end
# CHECK: {{^}})

echo 'echo (
if true
echo "
multi
line
"
end
)' | builtin fish_indent --only-indent
# CHECK: {{^}}echo (
# CHECK: {{^}}    if true
# CHECK: {{^}}        echo "
# CHECK: {{^}}multi
# CHECK: {{^}}line
# CHECK: {{^}}"
# CHECK: {{^}}    end
# CHECK: {{^}})

set -l tmpdir (mktemp -d)
echo 'echo "foo" "bar"' > $tmpdir/indent_test.fish
$fish_indent --write $tmpdir/indent_test.fish
cat $tmpdir/indent_test.fish
# CHECK: echo foo bar

# See that the builtin can be redirected
printf %s\n a b c | builtin fish_indent | grep b
# CHECK: b