xref: /aosp_15_r20/external/toybox/tests/wc.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
6*cf5a6c84SAndroid Build Coastguard Worker
7*cf5a6c84SAndroid Build Coastguard Workerutf8locale
8*cf5a6c84SAndroid Build Coastguard Worker
9*cf5a6c84SAndroid Build Coastguard Workercat >file1 <<EOF
10*cf5a6c84SAndroid Build Coastguard Workersome words	. 
11*cf5a6c84SAndroid Build Coastguard Worker
12*cf5a6c84SAndroid Build Coastguard Workersome
13*cf5a6c84SAndroid Build Coastguard Workerlines
14*cf5a6c84SAndroid Build Coastguard WorkerEOF
15*cf5a6c84SAndroid Build Coastguard Worker
16*cf5a6c84SAndroid Build Coastguard Workertestcmd "wc" ">/dev/null && echo yes" "yes\n" "" ""
17*cf5a6c84SAndroid Build Coastguard Workertestcmd "empty file" "" "      0       0       0\n" "" ""
18*cf5a6c84SAndroid Build Coastguard Workertestcmd "standard input" "" "      1       3       5\n" "" "a b\nc"
19*cf5a6c84SAndroid Build Coastguard Workertestcmd "standard input -c" "-c" "5\n" "" "a b\nc"
20*cf5a6c84SAndroid Build Coastguard Workertestcmd "standard input -cl" "-cl" "      1       5\n" "" "a b\nc"
21*cf5a6c84SAndroid Build Coastguard Workertestcmd "-c" "-c file1" "26 file1\n" "" ""
22*cf5a6c84SAndroid Build Coastguard Workertestcmd "-l" "-l file1" "4 file1\n" "" ""
23*cf5a6c84SAndroid Build Coastguard Workertestcmd "-w" "-w file1" "5 file1\n" "" ""
24*cf5a6c84SAndroid Build Coastguard Workertestcmd "-L" "-L file1" "18 file1\n" "" ""
25*cf5a6c84SAndroid Build Coastguard WorkerNOSPACE=1 testcmd "one file" "file1" "4 5 26 file1\n" "" ""
26*cf5a6c84SAndroid Build Coastguard Workertestcmd "multiple files" "input - file1" \
27*cf5a6c84SAndroid Build Coastguard Worker        "      1       2       3 input\n      0       2       3 -\n      4       5      26 file1\n      5       9      32 total\n" "a\nb" "a b"
28*cf5a6c84SAndroid Build Coastguard Worker
29*cf5a6c84SAndroid Build Coastguard Worker#Tests for wc -m
30*cf5a6c84SAndroid Build Coastguard Workerecho -n " " > file1
31*cf5a6c84SAndroid Build Coastguard Workerfor i in $(seq 1 512); do echo -n "üüüüüüüüüüüüüüüü" >> file1; done
32*cf5a6c84SAndroid Build Coastguard Workertestcmd "-m" "-m file1" "8193 file1\n" "" ""
33*cf5a6c84SAndroid Build Coastguard Workertesting "-m 2" 'cat "$FILES/utf8/test2.txt" | wc -m' "169\n" "" ""
34*cf5a6c84SAndroid Build Coastguard Workerecho -n " " > file1
35*cf5a6c84SAndroid Build Coastguard WorkerNOSPACE=1 testcmd "-mlw" "-mlw input" "1 2 11 input\n" "hello, 世界!\n" ""
36*cf5a6c84SAndroid Build Coastguard Workerrm file1
37*cf5a6c84SAndroid Build Coastguard Worker
38*cf5a6c84SAndroid Build Coastguard Worker# Corner cases for "line length". Not QUITE fold because \b doesn't subtract
39*cf5a6c84SAndroid Build Coastguard Worker
40*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 2' '-L' '1\n' '' 'a\n'
41*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 3' '-L' '1\n' '' 'a'
42*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 4' '-L' '6\n' '' 'first\rsecond\n'
43*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 5' '-L' '9\n' '' '\ta\n'
44*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 6' '-L' '8\n' '' '\t\b\b\b\n'
45*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 7' '-L' '9\n' '' 'abc\td\n'
46*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 8' '-L' '4\n' '' 'abc\bd\n'
47*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 9' '-L' '0\n' '' '\x01\n'
48*cf5a6c84SAndroid Build Coastguard Workertestcmd '-L 10' '-L' '1\n' '' 'w\xcc\x88\n'
49*cf5a6c84SAndroid Build Coastguard WorkerNOSPACE=1 testcmd '-Lm incoherence' '-Lm' '2 0\n' '' '\x01\n'
50*cf5a6c84SAndroid Build Coastguard Worker
51*cf5a6c84SAndroid Build Coastguard Worker# 25 wide chars, also testing field order
52*cf5a6c84SAndroid Build Coastguard WorkerNOSPACE=1 testcmd '-cmlLw wide' '-cmlLw' '0 1 25 75 50\n' '' \
53*cf5a6c84SAndroid Build Coastguard Worker  "$(<"$FILES"/utf8/japan.txt)"
54