• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7cat >file1 <<EOF
8some words	. 
9
10some
11lines
12EOF
13
14testing "wc" "wc >/dev/null && echo yes" "yes\n" "" ""
15testing "empty file" "wc" "      0       0       0\n" "" ""
16testing "standard input" "wc" "      1       3       5\n" "" "a b\nc"
17testing "-c" "wc -c file1" "26 file1\n" "" ""
18testing "-l" "wc -l file1" "4 file1\n" "" ""
19testing "-w" "wc -w file1" "5 file1\n" "" ""
20NOSPACE=1 testing "format" "wc file1" " 4 5 26 file1\n" "" ""
21testing "multiple files" "wc input - file1" \
22        "      1       2       3 input\n      0       2       3 -\n      4       5      26 file1\n      5       9      32 total\n" "a\nb" "a b"
23
24#Tests for wc -m
25if printf "%s" "$LANG" | grep -q UTF-8
26then
27
28printf " " > file1
29for i in $(seq 1 8192)
30do
31  printf "ü" >> file1
32done
33testing "-m" "wc -m file1" "8193 file1\n" "" ""
34testing "-m 2" 'cat "$FILES/utf8/test2.txt" | wc -m' "169\n" "" ""
35printf " " > file1
36for i in $(seq 1 8192)
37do
38  printf "ü" >> file1
39done
40testing "-m (invalid chars)" "wc -m file1" "8193 file1\n" "" ""
41NOSPACE=1 testing "-mlw" "wc -mlw input" " 1 2 11 input\n" "hello, 世界!\n" ""
42
43else
44printf "skipping tests for wc -m"
45fi
46
47rm file1
48