aboutsummaryrefslogtreecommitdiff
path: root/tests/printf.test
blob: ebf536ff04242f6cc87cc98c008536b1bf3399d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

testing "" "printf TEXT" "TEXT" "" ""
testing "printf escapes" "printf 'one\ntwo\n\v\t\r\f\e\b\athree'" \
  "one\ntwo\n\v\t\r\f\e\b\athree" "" ""
testing "printf %b escapes" "printf %b 'one\ntwo\n\v\t\r\f\e\b\athree'" \
  "one\ntwo\n\v\t\r\f\e\b\athree" "" ""
testing "printf null" "printf 'x\0y' | od -An -tx1" ' 78 00 79\n' "" ""
testing "printf trailing slash" "printf 'abc\'" 'abc\' "" ""
testing "printf octal" "printf ' \1\002\429\045x'" ' \001\002"9%x' "" ""
testing "printf not octal" "printf '\9'" '\9' "" ""
testing "printf hex" "printf 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \
  ' 41 1b 2b 03 51 0a\n' "" ""
testing "" "printf '%x\\n' 0x2a" "2a\n" "" ""

testing "" "printf %d 42" "42" "" ""
testing "" "printf %d 0x2a" "42" "" ""
testing "" "printf %d 052" "42" "" ""

testing "printf '%5d%4d' 1 21 321 4321 54321" \
  "printf '%5d%4d' 1 21 321 4321 54321" "    1  21  321432154321   0" "" ""
testing "printf '%c %c' 78 79" "printf '%c %c' 78 79" "7 7" "" ""
testing "printf '%d %d' 78 79" "printf '%d %d' 78 79" "78 79" "" ""
testing "printf '%f %f' 78 79" "printf '%f %f' 78 79" \
  "78.000000 79.000000" "" ""
testing "printf 'f f' 78 79" "printf 'f f' 78 79" "f f" "" ""
testing "printf '%i %i' 78 79" "printf '%i %i' 78 79" "78 79" "" ""
testing "printf '%o %o' 78 79" "printf '%o %o' 78 79" "116 117" "" ""
testing "printf '%u %u' 78 79" "printf '%u %u' 78 79" "78 79" "" ""
testing "printf '%u %u' -1 -2" "printf '%u %u' -1 -2" \
  "18446744073709551615 18446744073709551614" "" ""
testing "printf '%x %X' 78 79" "printf '%x %X' 78 79" "4e 4F" "" ""
testing "printf '%g %G' 78 79" "printf '%g %G' 78 79" "78 79" "" ""
testing "printf '%s %s' 78 79" "printf '%s %s' 78 79" "78 79" "" ""