-
Notifications
You must be signed in to change notification settings - Fork 1
/
test
executable file
·69 lines (57 loc) · 2.66 KB
/
test
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -o errexit
set -o pipefail
source fdcli
assert() {
local expected=$(printf "$1")
local actual="$(cat)"
diff -u <(printf '%s' "$expected") <(printf '%s' "$actual") | sed 's/\t/__TAB__/g' | colordiff || \
(printf 'expected:\n---------------\n%s\n-------------------\n' "$expected";
printf 'got: \n---------------\n%s\n-------------------\n' "$actual";
false)
}
db() {
cat test-${1}.db
}
echo 'utils'
#echo 'BAR' | prog_template 'echo %s' | assert "BAR\n"
echo 'ü' | prog_template 'echo hello' | assert 'hello'
echo 'ü' | prog_template 'echo %s' | assert 'ü'
echo '<<*''ß%s?`' | prog_template 'echo FOO %s' | assert 'FOO <<*''ß%%s?`'
echo $'foo\tbar\tbaz' | replace_field 1 'REPLACE' | assert 'REPLACE\tbar\tbaz'
echo 'simple db_select'
db users | db_select id | assert '1\n2\n'
db users | db_select id name | assert '1\tsome one\n2\tsome one else\n'
db users | db_select id name nick | assert '1\tsome one\tsomenick\n2\tsome one else\telsenick\n'
db users | db_select name id | assert 'some one\t1\nsome one else\t2\n'
echo 'simple db_where'
db users | db_select id name | db_where 1 | assert 'some one\n'
db users | db_select id name | db_where 2 | assert 'some one else\n'
db users | db_select known id | db_where yes | assert '1\n2\n'
echo 'db_format'
db users | db_select id name | db_format 1 'echo hello | tr -d "\n"' | assert 'hello\tsome one\nhello\tsome one else\n'
db users | db_select id name | db_format 1 "echo '<<%s>>' | tr -d '\n'" | assert '<<1>>\tsome one\n<<2>>\tsome one else\n'
db users | db_select id data | db_format 2 "echo '<<%s>>' | tr -d '\n'" | assert '1\t<<something\\non\\ttwo\\tlines\n2\t`'"'"';~\$\#-"™weirdchars\\n\\n\\t\n'
echo 'nowrap'
printf '12' | nowrap 3 | assert '12\n'
printf '123456789' | nowrap 3 | assert '123\n'
printf '123456789' | nowrap 5 | assert '12345\n'
printf '1234\n5678\n9' | nowrap 5 | assert '1234\n'
printf '1234\n5678\n9' | nowrap 2 | assert '12\n'
printf '1234\n5678\n9' | nowrap 3 | assert '123\n'
printf '1234 5678 9' | nowrap 5 | assert '1234 \n'
printf '1234 5678 9' | nowrap 4 | assert '1234\n'
echo 'wrap'
printf '12' | wrap 3 | assert '12\n'
printf '123456789' | wrap 3 | assert '123\n456\n789\n'
printf '123456789' | wrap 5 | assert '12345\n6789\n'
printf '1234\n5678\n9' | wrap 5 | assert '1234\n5678\n9'
printf '1234\n5678\n9' | wrap 2 | assert '12\n34\n56\n78\n9'
printf '1234\n5678\n9' | wrap 3 | assert '123\n4\n567\n8\n9'
printf '1234 5678 9' | wrap 5 | assert '1234\n5678\n9'
printf '1234 5678 9' | wrap 4 | assert '1234\n5678\n9'
# TODO
# test db_join
# test db_print (SHOULD ALSO DO REPLACEMENT OF \n and \t)
# test json_to_db (should replace \t and \n)
echo ALL GOOD