fmt.test 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. echo "hello world " > en.txt
  4. echo "this is some text " >> en.txt
  5. # https://en.wikipedia.org/wiki/Aegukga
  6. echo "동해물과 백두산이 마르고 닳도록" > kr.txt
  7. echo "하나님이 보우하사 우리나라 만세." >> kr.txt
  8. #testing "name" "command" "result" "infile" "stdin"
  9. testing "join" "fmt en.txt" "hello world this is some text\n" "" ""
  10. testing "split" "fmt -w 10 en.txt" "hello\nworld\nthis is\nsome text\n" "" ""
  11. testing "no room" "echo 'hello world' | fmt -w 1" "hello\nworld\n" "" ""
  12. testing "blank line" "echo -e 'first paragraph of text\n\nand another' | fmt -w 10" "first\nparagraph\nof text\n\nand\nanother\n" "" ""
  13. testing "ws-only line" "echo -e 'hello\n \nworld' | fmt -w 10" "hello\n\nworld\n" "" ""
  14. testing "leading space" "echo ' hello world' | fmt -w 5" " hello\n world\n" "" ""
  15. testing "utf8" "fmt -w 10 kr.txt" "동해물과\n백두산이\n마르고\n닳도록\n하나님이\n보우하사\n우리나라\n만세.\n" "" ""
  16. testing "no newline" "fmt -w 10" "and\nthisisaverylongline\n" \
  17. "" "and thisisaverylongline"
  18. testing "" "fmt -w 9" "1 2 3 4\n5 6 7 8\n9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
  19. testing "" "fmt -w 10" "1 2 3 4 5\n6 7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
  20. testing "" "fmt -w 11" "1 2 3 4 5\n6 7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
  21. testing "" "fmt -w 12" "1 2 3 4 5 6\n7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
  22. testing "matched tab indent" "fmt" "\thello world\n" "" "\thello\n\tworld"
  23. # Version skew: debian is now emitting \t instead of "first line's indent"
  24. toyonly testing "matched tab/space" "fmt" ' hello world\n' "" \
  25. " hello\n\tworld"
  26. testing "matched space/tab" "fmt" "\thello world\n" "" "\thello\n world"
  27. rm en.txt kr.txt