blob: ebf536ff04242f6cc87cc98c008536b1bf3399d3 [file] [log] [blame]
Divya Kotharia0f56be2014-06-26 07:25:20 -05001#!/bin/bash
2
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5
6[ -f testing.sh ] && . testing.sh
7
8#testing "name" "command" "result" "infile" "stdin"
Divya Kotharia0f56be2014-06-26 07:25:20 -05009
Rob Landleycc39d952015-01-06 12:07:20 -060010testing "" "printf TEXT" "TEXT" "" ""
11testing "printf escapes" "printf 'one\ntwo\n\v\t\r\f\e\b\athree'" \
12 "one\ntwo\n\v\t\r\f\e\b\athree" "" ""
13testing "printf %b escapes" "printf %b 'one\ntwo\n\v\t\r\f\e\b\athree'" \
14 "one\ntwo\n\v\t\r\f\e\b\athree" "" ""
15testing "printf null" "printf 'x\0y' | od -An -tx1" ' 78 00 79\n' "" ""
16testing "printf trailing slash" "printf 'abc\'" 'abc\' "" ""
17testing "printf octal" "printf ' \1\002\429\045x'" ' \001\002"9%x' "" ""
18testing "printf not octal" "printf '\9'" '\9' "" ""
19testing "printf hex" "printf 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \
20 ' 41 1b 2b 03 51 0a\n' "" ""
21testing "" "printf '%x\\n' 0x2a" "2a\n" "" ""
22
23testing "" "printf %d 42" "42" "" ""
24testing "" "printf %d 0x2a" "42" "" ""
25testing "" "printf %d 052" "42" "" ""
26
Divya Kotharia0f56be2014-06-26 07:25:20 -050027testing "printf '%5d%4d' 1 21 321 4321 54321" \
28 "printf '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" ""
29testing "printf '%c %c' 78 79" "printf '%c %c' 78 79" "7 7" "" ""
30testing "printf '%d %d' 78 79" "printf '%d %d' 78 79" "78 79" "" ""
31testing "printf '%f %f' 78 79" "printf '%f %f' 78 79" \
32 "78.000000 79.000000" "" ""
33testing "printf 'f f' 78 79" "printf 'f f' 78 79" "f f" "" ""
34testing "printf '%i %i' 78 79" "printf '%i %i' 78 79" "78 79" "" ""
35testing "printf '%o %o' 78 79" "printf '%o %o' 78 79" "116 117" "" ""
36testing "printf '%u %u' 78 79" "printf '%u %u' 78 79" "78 79" "" ""
37testing "printf '%u %u' -1 -2" "printf '%u %u' -1 -2" \
38 "18446744073709551615 18446744073709551614" "" ""
39testing "printf '%x %X' 78 79" "printf '%x %X' 78 79" "4e 4F" "" ""
40testing "printf '%g %G' 78 79" "printf '%g %G' 78 79" "78 79" "" ""
41testing "printf '%s %s' 78 79" "printf '%s %s' 78 79" "78 79" "" ""