aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-01-24 15:42:06 -0300
committerEuAndreh <eu@euandre.org>2021-01-24 15:42:06 -0300
commit69ecf8718bb742a90a55ab3e9247c83c1a8f7f1f (patch)
treef97b4763c230dcdad01332e2567edddd2984de69 /tests
parenttests: Add logs of which test is running (diff)
downloadremembering-69ecf8718bb742a90a55ab3e9247c83c1a8f7f1f.tar.gz
remembering-69ecf8718bb742a90a55ab3e9247c83c1a8f7f1f.tar.xz
tests/ranking.sh: Add more test scenarions (some are now failing)
Diffstat (limited to '')
-rwxr-xr-xtests/lib.sh2
-rwxr-xr-xtests/ranking.sh97
2 files changed, 96 insertions, 3 deletions
diff --git a/tests/lib.sh b/tests/lib.sh
index 8d77068..251f314 100755
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -23,7 +23,7 @@ assert_empty_stderr() {
assert_stdout() {
if [ "$(cat "$OUT")" != "$1" ]; then
- printf '\nERR: Bad STDOUT (%s)\nexpected: %s\ngot: %s\n' \
+ printf '\nERR: Bad STDOUT (%s)\n\nexpected: %s\ngot: %s\n' \
"$OUT" "$1" "$(cat "$OUT")" >&2
exit 1
fi
diff --git a/tests/ranking.sh b/tests/ranking.sh
index e01692e..d7df451 100755
--- a/tests/ranking.sh
+++ b/tests/ranking.sh
@@ -53,10 +53,10 @@ pick_x() {
ERR="$(mktemp)"
PICK="$1"
- echo "$INPUT" | \
+ echo "${2:-$INPUT}" | \
sh remembering \
-p "$PROFILE" \
- -c "tee -a /dev/stderr | grep $PICK" \
+ -c "tee -a /dev/stderr | grep '$PICK'" \
1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
@@ -157,8 +157,101 @@ s'
test_ok
}
+test_stdin_profile_merging() {
+ testing 'STDIN/profile merging'
+ PROFILE="stdin-profile-merging-$(uuid)"
+ echo '0:a
+0:b
+0:c
+0:z' > "$XDG_DATA_HOME/$PROFILE"
+ INPUT='a
+b
+c
+d
+e'
+ pick_x a "$INPUT"
+ if [ "$(cat "$ERR")" != "$INPUT" ]; then
+ printf '\nERR: Bad profile merge.\n\nExpected:\n%s\nGot:\n%s\n' \
+ "$INPUT" "$(cat "$ERR")" >&2
+ exit 1
+ fi
+ test_ok
+}
+
+BASE_PROFILE='0:a
+0:b
+0:c
+0:d
+0:e'
+BASE_PROFILE_A_PICKED='1:a
+0:b
+0:c
+0:d
+0:e'
+assert_profile() {
+ if [ "$(cat "$XDG_DATA_HOME/$1")" != "$2" ]; then
+ printf '\nERR: Bad profile merge (%s).\n\nExpected:\n%s\nGot\n%s\n' \
+ "$PROFILE" "$2" "$(cat "$XDG_DATA_HOME/$1")" >&2
+ exit 1
+ fi
+}
+
+test_stdin_is_larger_than_profile() {
+ testing 'STDIN is larger than profile'
+ PROFILE="stdin-is-larger-than-profile-$(uuid)"
+ echo '0:a' > "$XDG_DATA_HOME/$PROFILE"
+ INPUT='a
+b
+c
+d
+e'
+ pick_x a "$INPUT"
+ assert_profile "$PROFILE" "$BASE_PROFILE_A_PICKED"
+ test_ok
+}
+
+test_stdin_is_smaller_than_profile() {
+ testing 'STDIN is smaller than profile'
+ PROFILE="stdin-is-smaller-than-profile-$(uuid)"
+ echo "$BASE_PROFILE" > "$XDG_DATA_HOME/$PROFILE"
+ INPUT='a'
+ pick_x a "$INPUT"
+ # echo "err is: $(cat "$ERR")"
+ assert_profile "$PROFILE" "$BASE_PROFILE_A_PICKED"
+ test_ok
+}
+
+test_stdin_is_empty() {
+ testing 'STDIN is empty'
+ PROFILE="stdin-is-empty-$(uuid)"
+ echo "$BASE_PROFILE" > "$XDG_DATA_HOME/$PROFILE"
+ INPUT=''
+ pick_x '' "$INPUT"
+ assert_profile "$PROFILE" "$BASE_PROFILE"
+ test_ok
+}
+
+test_profile_is_empty() {
+ testing 'profile is empty'
+ PROFILE="profile-is-empty-$(uuid)"
+ echo '' > "$XDG_DATA_HOME/$PROFILE"
+ INPUT='a
+b
+c
+d
+e'
+ pick_x a "$INPUT"
+ assert_profile "$PROFILE" "$BASE_PROFILE_A_PICKED"
+ test_ok
+}
+
test_picking_first_makes_it_be_always_first
test_promoting_values
test_higher_values_loose_tie
test_smaller_values_win_tie
test_many_sequential_picks
+test_stdin_profile_merging
+test_stdin_is_larger_than_profile
+test_stdin_is_smaller_than_profile
+test_stdin_is_empty
+test_profile_is_empty