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