From 3c7d1c25f621813dc3480e73b0166d71daeb6adf Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Sat, 28 Dec 2019 22:26:47 -0800 Subject: [PATCH] Fix generation bug: "...a MD-50..." --- .../lemondronor/circlebot/generation.cljc | 4 ++- .../circlebot/generation_test.cljs | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/lemondronor/circlebot/generation.cljc b/src/main/lemondronor/circlebot/generation.cljc index 865cacc..de89e67 100644 --- a/src/main/lemondronor/circlebot/generation.cljc +++ b/src/main/lemondronor/circlebot/generation.cljc @@ -68,7 +68,9 @@ (def filters {:a-an (fn a-an [s] (if (starts-with-consonant? s) - (str "a " s) + (if (re-find #"^[FHLMNRSX](\b|[A-Z0-9])" s) + (str "an " s) + (str "a " s)) (str "an " s)))}) diff --git a/src/test/lemondronor/circlebot/generation_test.cljs b/src/test/lemondronor/circlebot/generation_test.cljs index 0637b05..c0c8307 100644 --- a/src/test/lemondronor/circlebot/generation_test.cljs +++ b/src/test/lemondronor/circlebot/generation_test.cljs @@ -1,5 +1,5 @@ (ns lemondronor.circlebot.generation-test - (:require [cljs.test :refer (deftest is)] + (:require [cljs.test :refer (deftest is testing)] [lemondronor.circlebot.generation :as generation])) (deftest parse-template @@ -27,7 +27,7 @@ (generation/generate-all [(generation/parse-template "Hello!")] {}))) - (is (= "Hello!" + (is (= "Hello!" (generation/generate [(generation/parse-template "Hello!")] {})))) @@ -74,15 +74,26 @@ (deftest filters - (let [templates [(generation/parse-template "It is {thing|a-an}")]] - (is (= "It is a bird" - (generation/generate templates {:thing "bird"}))) - (is (= "It is an animal" - (generation/generate templates {:thing "animal"}))) - (is (= "It is an Animal" - (generation/generate templates {:thing "Animal"}))) - (is (= "It is a Eurocopter" - (generation/generate templates {:thing "Eurocopter"}))))) + (testing "a-an" + (let [templates [(generation/parse-template "It is {thing|a-an}")]] + (is (= "It is a bird" + (generation/generate templates {:thing "bird"}))) + (is (= "It is an animal" + (generation/generate templates {:thing "animal"}))) + (is (= "It is an Animal" + (generation/generate templates {:thing "Animal"}))) + (is (= "It is a Eurocopter" + (generation/generate templates {:thing "Eurocopter"}))) + (is (= "It is an MD-500" + (generation/generate templates {:thing "MD-500"}))) + (is (= "It is an F-15" + (generation/generate templates {:thing "F-15"}))) + (is (= "It is an X-15" + (generation/generate templates {:thing "X-15"}))) + (is (= "It is a KXL-10" + (generation/generate templates {:thing "KXL-10"}))) + + ))) ;; (deftest var-paths ;; (is (= "Hello, John"