aboutsummaryrefslogtreecommitdiff
path: root/scripts/test
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-10-27 02:50:55 -0500
committerRob Landley <rob@landley.net>2013-10-27 02:50:55 -0500
commit2baa73fb0d3999d541b2122b853b56e2bfdea56b (patch)
treed147fd62f4d9ab138e6fb5d7e9e5e0f2ad41d01b /scripts/test
parent710a31f52681234a1a92497009ca08c1026797a1 (diff)
downloadtoybox-2baa73fb0d3999d541b2122b853b56e2bfdea56b.tar.gz
Promote nl from pending to posix, and add tests.
Diffstat (limited to 'scripts/test')
-rw-r--r--scripts/test/nl.test50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/test/nl.test b/scripts/test/nl.test
new file mode 100644
index 00000000..958cb41e
--- /dev/null
+++ b/scripts/test/nl.test
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "nl" "nl" " 1\tone\n 2\ttwo\n 3\tthree\n" \
+ "" "one\ntwo\nthree\n"
+
+testing "nl explicit defaults" "nl -nrn -b a" \
+ " 1\tone\n 2\ttwo\n 3\tthree\n" "" "one\ntwo\nthree\n"
+
+# -n ln rn rz
+
+testing "nl -nln" "nl -nln" "1 \tone\n2 \ttwo\n3 \tthree\n" \
+ "" "one\ntwo\nthree\n"
+testing "nl -nln -w" "nl -nln -w 8" \
+ "1 \tone\n2 \ttwo\n3 \tthree\n" "" "one\ntwo\nthree\n"
+
+testing "nl -nrz" "nl -nrz" "000001\tone\n000002\ttwo\n000003\tthree\n" \
+ "" "one\ntwo\nthree\n"
+
+testing "nl -nrz -w" "nl -w3 -nrz" "001\tone\n002\ttwo\n003\tthree\n" \
+ "" "one\ntwo\nthree\n"
+
+
+# For non-matching lines the separator is "suppressed" meaning it...
+# turns into spaces! And the tab turns into one space, and -d boom turns
+# into 4 spaces, but these:
+# nl -s"$(echo -e 'bo\tom')" -bpand README
+# nl -w 3 -bpthe README
+# Yeah. And I doubt utf8 fontmetrics are used either.
+
+testing "nl -b t" "nl -b t" " \n 1\tone\n \n 2\ttwo\n" \
+ "" "\none\n\ntwo\n"
+testing "nl -b n" "nl -b n" " one\n two\n three\n" \
+ "" "one\ntwo\nthree\n"
+testing "nl -sook -b p" "nl -sook -bpoing" \
+ " one\n 1ookboing\n 2ooksproingy\n" \
+ "" "one\nboing\nsproingy\n"
+
+testing "nl -v" "nl -v 42" " 42\tone\n 43\ttwo\n 44\tthree\n" \
+ "" "one\ntwo\nthree\n"
+testing "nl -l" "nl -ba -l2 -w2 - input" \
+ " 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" \
+ "\n\nbang\n\n" "one\n\n\ntwo\n\n\n\nthree\nfour\n\n"
+testing "nl no space" "nl -w 1 -v 42" "42\tline\n" "" "line\n"
+
+# Should test for -E but no other implementation seems to have it?
+#testing "nl -E" "nl -w2 -sx -Ebp'(one|two)'" " 1x" "one\nand\ntwo\n"