File: count.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 (50 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (5)
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
#RUN: %fish %s
# Validate the behavior of the `count` command.

# no args
count
# CHECK: 0

# one args
count x
# CHECK: 1

# two args
count x y
# CHECK: 2

# args that look like flags or are otherwise special
count -h
# CHECK: 1
count --help
# CHECK: 1
count --
# CHECK: 1
count -- abc
# CHECK: 2
count def -- abc
# CHECK: 3

# big counts

# See #5611
for i in seq 500
    set c1 (count (seq 1 10000))
    test $c1 -eq 10000
    or begin
        echo "Count $c1 is not 10000"
        break
    end
end

# stdin
# Reading from stdin still counts the arguments
printf '%s\n' 1 2 3 4 5 | count 6 7 8 9 10
# CHECK: 10

# Reading from stdin counts newlines - like `wc -l`.
echo -n 0 | count
# CHECK: 0

echo 1 | count
# CHECK: 1