Skip to content

Commit 831391d

Browse files
committed
+ add uq unit test: uq_test.sh
1 parent 4bd0770 commit 831391d

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

test-cases/uq_test.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
set -eEuo pipefail
3+
4+
BASE="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
5+
cd "$BASE"
6+
7+
#################################################
8+
# commons and test data
9+
#################################################
10+
11+
readonly uq="../bin/uq"
12+
readonly nl=$'\n' # new line
13+
14+
test_input=$(cat uq_test_input)
15+
16+
#################################################
17+
# test cases
18+
#################################################
19+
20+
test_uq_simple() {
21+
assertEquals "c${nl}v${nl}a${nl}u" \
22+
"$(echo "$test_input" | "$uq")"
23+
assertEquals "c${nl}v${nl}a${nl}u" \
24+
"$("$uq" uq_test_input)"
25+
26+
assertEquals "c${nl}a" \
27+
"$(echo "$test_input" | "$uq" -d)"
28+
assertEquals "c${nl}a" \
29+
"$("$uq" -d uq_test_input)"
30+
31+
assertEquals "v${nl}u" "$(echo "$test_input" | "$uq" -u)"
32+
assertEquals "v${nl}u" "$("$uq" -u uq_test_input)"
33+
}
34+
35+
readonly test_output_uq_count=' 4 c
36+
1 v
37+
2 a
38+
1 u'
39+
40+
readonly test_output_uq_D_count=' 4 c
41+
4 c
42+
1 v
43+
2 a
44+
2 a
45+
4 c
46+
4 c
47+
1 u'
48+
49+
test_uq_count() {
50+
assertEquals "$test_output_uq_count" "$(echo "$test_input" | "$uq" -c)"
51+
assertEquals "$test_output_uq_count" "$("$uq" -c uq_test_input)"
52+
53+
assertEquals "$test_output_uq_D_count" "$(echo "$test_input" | "$uq" -D -c)"
54+
assertEquals "$test_output_uq_D_count" "$("$uq" -D -c uq_test_input)"
55+
}
56+
57+
test_uq_only_D_option__same_as_cat() {
58+
assertEquals "$test_input" "$(echo "$test_input" | "$uq" -D)"
59+
assertEquals "$test_input" "$("$uq" -D uq_test_input)"
60+
}
61+
62+
test_multi_input_files__output_file() {
63+
local output_file="$SHUNIT_TMPDIR/uq_output_file_${$}_${RANDOM}_${RANDOM}"
64+
"$uq" uq_test_input uq_test_another_input "$output_file"
65+
assertEquals "c${nl}v${nl}a${nl}u${nl}m${nl}x" \
66+
"$(cat "$output_file")"
67+
68+
local output_file="$SHUNIT_TMPDIR/uq_output_file_${$}_${RANDOM}_${RANDOM}"
69+
"$uq" -d uq_test_input uq_test_another_input "$output_file"
70+
assertEquals "c${nl}a${nl}m" \
71+
"$(cat "$output_file")"
72+
73+
local output_file="$SHUNIT_TMPDIR/uq_output_file_${$}_${RANDOM}_${RANDOM}"
74+
"$uq" -u uq_test_input uq_test_another_input "$output_file"
75+
assertEquals "v${nl}u${nl}x" \
76+
"$(cat "$output_file")"
77+
}
78+
79+
test_multi_input_files__output_stdout() {
80+
assertEquals "c${nl}v${nl}a${nl}u${nl}m${nl}x" "$("$uq" uq_test_input uq_test_another_input -)"
81+
82+
assertEquals "c${nl}a${nl}m" "$("$uq" -d uq_test_input uq_test_another_input -)"
83+
84+
assertEquals "v${nl}u${nl}x" "$("$uq" -u uq_test_input uq_test_another_input -)"
85+
}
86+
87+
test_ignore_case() {
88+
local input="a${nl}b${nl}A"
89+
90+
assertEquals "a${nl}b${nl}A" "$(echo "$input" | "$uq")"
91+
assertEquals "a${nl}b" "$(echo "$input" | "$uq" -i)"
92+
}
93+
94+
test_ignore_case__count() {
95+
local input="a${nl}b${nl}A"
96+
97+
assertEquals " 1 a${nl} 1 b${nl} 1 A" \
98+
"$(echo "$input" | "$uq" -c)"
99+
100+
assertEquals " 2 a${nl} 1 b" \
101+
"$(echo "$input" | "$uq" -i -c)"
102+
103+
assertEquals " 2 a${nl} 1 b${nl} 2 A" \
104+
"$(echo "$input" | "$uq" -i -D -c)"
105+
}
106+
107+
#################################################
108+
# Load and run shUnit2.
109+
#################################################
110+
source "$BASE/shunit2-lib/shunit2"

test-cases/uq_test_another_input

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a
2+
m
3+
m
4+
x

test-cases/uq_test_input

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
c
2+
c
3+
v
4+
a
5+
a
6+
c
7+
c
8+
u

0 commit comments

Comments
 (0)