wc.test 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. cat >file1 <<EOF
  5. some words .
  6. some
  7. lines
  8. EOF
  9. testing "wc" "wc >/dev/null && echo yes" "yes\n" "" ""
  10. testing "empty file" "wc" " 0 0 0\n" "" ""
  11. testing "standard input" "wc" " 1 3 5\n" "" "a b\nc"
  12. testing "standard input -c" "wc -c" "5\n" "" "a b\nc"
  13. testing "standard input -cl" "wc -cl" " 1 5\n" "" "a b\nc"
  14. testing "-c" "wc -c file1" "26 file1\n" "" ""
  15. testing "-l" "wc -l file1" "4 file1\n" "" ""
  16. testing "-w" "wc -w file1" "5 file1\n" "" ""
  17. testing "one file" "wc file1" "4 5 26 file1\n" "" ""
  18. testing "multiple files" "wc input - file1" \
  19. " 1 2 3 input\n 0 2 3 -\n 4 5 26 file1\n 5 9 32 total\n" "a\nb" "a b"
  20. #Tests for wc -m
  21. echo -n " " > file1
  22. for i in $(seq 1 512); do echo -n "üüüüüüüüüüüüüüüü" >> file1; done
  23. testing "-m" "wc -m file1" "8193 file1\n" "" ""
  24. testing "-m 2" 'cat "$FILES/utf8/test2.txt" | wc -m' "169\n" "" ""
  25. echo -n " " > file1
  26. testing "-mlw" "wc -mlw input" "1 2 11 input\n" "hello, 世界!\n" ""
  27. rm file1