From e4df11f12d028f567cd9146c6f8da992e0fed565 Mon Sep 17 00:00:00 2001 From: Sebastian Crane Date: Wed, 23 Feb 2022 21:07:12 +0000 Subject: [PATCH] Use case-insensitive sorting when listing players Signed-off-by: Sebastian Crane --- src/bot.clj | 7 +++++-- test/bot_test.clj | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bot.clj b/src/bot.clj index a4013b2..59928b6 100644 --- a/src/bot.clj +++ b/src/bot.clj @@ -10,11 +10,14 @@ (when (string? game) (keyword (str/lower-case game)))) +(defn sort-case-insensitive [coll] + (sort #(apply compare (map str/lower-case %&)) coll)) + (defn sorted-players-of-game [state game] (->> game (keywordise-game) (game/get-players-of-game state) - (sort))) + (sort-case-insensitive))) (defn match-string [& {:keys [state game]}] (str "Anyone ready for " @@ -48,7 +51,7 @@ (str "Games with a list of players: " (str/join ", " - (sort (map name (game/get-games state)))))) + (sort-case-insensitive (map name (game/get-games state)))))) (defn split-message [message] (let [message-parts (str/split message #"\s") diff --git a/test/bot_test.clj b/test/bot_test.clj index 6d8a470..e0845bb 100644 --- a/test/bot_test.clj +++ b/test/bot_test.clj @@ -13,6 +13,10 @@ (is (= :quasi-rts (keywordise-game "Quasi-RTS")))) +(deftest sort-case-insensitive-test + (is (= ["A" "b" "C"] + (sort-case-insensitive ["C" "A" "b"])))) + (deftest match-string-test (is (= '"Anyone ready for quasi-Rts? 123 abc" (match-string :state test-state :game "quasi-Rts"))))