nl.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. testing "nl" "nl" " 1\tone\n 2\ttwo\n 3\tthree\n" \
  5. "" "one\ntwo\nthree\n"
  6. testing "explicit defaults" "nl -nrn -b a" \
  7. " 1\tone\n 2\ttwo\n 3\tthree\n" "" "one\ntwo\nthree\n"
  8. # -n ln rn rz
  9. testing "-nln" "nl -nln" "1 \tone\n2 \ttwo\n3 \tthree\n" \
  10. "" "one\ntwo\nthree\n"
  11. testing "-nln -w" "nl -nln -w 8" \
  12. "1 \tone\n2 \ttwo\n3 \tthree\n" "" "one\ntwo\nthree\n"
  13. testing "-nrz" "nl -nrz" "000001\tone\n000002\ttwo\n000003\tthree\n" \
  14. "" "one\ntwo\nthree\n"
  15. testing "-nrz -w" "nl -w3 -nrz" "001\tone\n002\ttwo\n003\tthree\n" \
  16. "" "one\ntwo\nthree\n"
  17. # For non-matching lines the separator is "suppressed" meaning it...
  18. # turns into spaces! And the tab turns into one space, and -d boom turns
  19. # into 4 spaces, but these:
  20. # nl -s"$(echo -e 'bo\tom')" -bpand README
  21. # nl -w 3 -bpthe README
  22. # Yeah. And I doubt utf8 fontmetrics are used either.
  23. testing "-b t" "nl -b t" " \n 1\tone\n \n 2\ttwo\n" \
  24. "" "\none\n\ntwo\n"
  25. testing "-b n" "nl -b n" " one\n two\n three\n" \
  26. "" "one\ntwo\nthree\n"
  27. testing "-sook -b p" "nl -sook -bpoing" \
  28. " one\n 1ookboing\n 2ooksproingy\n" \
  29. "" "one\nboing\nsproingy\n"
  30. testing "-v42" "nl -v 42" " 42\tone\n 43\ttwo\n 44\tthree\n" \
  31. "" "one\ntwo\nthree\n"
  32. testing "-v-1" "nl -v -1" " -1\tone\n 0\ttwo\n 1\tthree\n" \
  33. "" "one\ntwo\nthree\n"
  34. testing "-v0" "nl -v 0" " 0\tone\n 1\ttwo\n 2\tthree\n" \
  35. "" "one\ntwo\nthree\n"
  36. testing "-l" "nl -ba -l2 -w2 - input" \
  37. " 1\tone\n \n 2\t\n 3\ttwo\n \n 4\t\n \n 5\tthree\n 6\tfour\n \n 7\t\n \n 8\tbang\n \n" \
  38. "\n\nbang\n\n" "one\n\n\ntwo\n\n\n\nthree\nfour\n\n"
  39. testing "no space" "nl -w 1 -v 42" "42\tline\n" "" "line\n"
  40. # Should test for -E but no other implementation seems to have it?
  41. toyonly testing "-E" "nl -w2 -sx -Ebp'(one|two)'" " 1xone\n and\n 2xtwo\n" \
  42. "" "one\nand\ntwo\n"