-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSluggerTest.hs
98 lines (74 loc) · 4.85 KB
/
SluggerTest.hs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Main (main) where
import Test.Hspec
import qualified Data.Text as T
import qualified Data.String.Slugger as SluggerString
import qualified Data.Text.Slugger as SluggerText
main :: IO ()
main = hspec $ do
describe "Data.String.Slugger.toSlug" $ do
it "works" $ do
SluggerString.toSlug "HELLO, WORLD!!!" `shouldBe` "hello-world"
describe "Data.Text.Slugger.toSlug" $ do
context "when an empty string" $ do
it "returns an empty string" $ do
SluggerText.toSlug (T.pack "") `shouldBe` T.pack ""
context "when a string with empty spaces" $ do
it "returns an empty string" $ do
SluggerText.toSlug (T.pack " ") `shouldBe` T.pack ""
context "when uppercase words" $ do
it "returns words lowercased and hyphenated" $ do
SluggerText.toSlug (T.pack "HELLO GREAT WORLD") `shouldBe`
T.pack "hello-great-world"
context "when uppercase words with symbols" $ do
it "returns words lowercased and hyphenated" $ do
SluggerText.toSlug (T.pack "HELLO, WORLD!!!") `shouldBe`
T.pack "hello-world"
context "when contractions are used (single quotes)" $ do
it "keeps words like can't and don't together" $ do
SluggerText.toSlug (T.pack "I can't won't don't want to!")
`shouldBe` T.pack "i-cant-wont-dont-want-to"
context "when leading & trailing whitespace" $ do
it "does nothing with the extra whitespace" $ do
SluggerText.toSlug (T.pack " Hey world! ") `shouldBe`
T.pack "hey-world"
context "when repeated inner whitespace" $ do
it "treats the repeated inner whitespace as a single space" $ do
SluggerText.toSlug (T.pack "Hey there, world!") `shouldBe`
T.pack "hey-there-world"
context "when non US-ASCII letters provided" $ do
it "handles Danish: Være så venlig... Øl" $ do
SluggerText.toSlug (T.pack "Være så venlig... Øl")
`shouldBe` T.pack "vaere-sa-venlig-ol"
it "handles French: GARÇON - déjà , Forêt — Zoë" $ do
SluggerText.toSlug (T.pack "GARÇON - déjà , Forêt — Zoë")
`shouldBe` T.pack "garcon-deja-foret-zoe"
it "handles Finnish: Saisinko leipää? Šakki. Džonkki" $ do
SluggerText.toSlug (T.pack "Saisinko leipää? Šakki. Džonkki")
`shouldBe` T.pack "saisinko-leipaa-sakki-dzonkki"
it "handles German: Straße, müde, Äpfel und Ökologie" $ do
SluggerText.toSlug (T.pack "Straße, müde, Äpfel und Ökologie")
`shouldBe` T.pack "strasse-mude-apfel-und-okologie"
it "handles Icelandic: (Ég) er kominn aftur (á ný) Inn í þig (Það er) svo gott að vera (hér) En stoppa stutt við" $ do
SluggerText.toSlug (T.pack "(Ég) er kominn aftur (á ný) Inn í þig (Það er) svo gott að vera (hér) En stoppa stutt við")
`shouldBe` T.pack "eg-er-kominn-aftur-a-ny-inn-i-thig-thad-er-svo-gott-ad-vera-her-en-stoppa-stutt-vid"
it "handles Italian: Non c’è di che." $ do
SluggerText.toSlug (T.pack "Non c’è di che.")
`shouldBe` T.pack "non-c-e-di-che"
it "handles Polish: Żółć, Szczęście, & Następstw" $ do
SluggerText.toSlug (T.pack "Żółć, Szczęście, & Następstw")
`shouldBe` T.pack "zolc-szczescie-nastepstw"
it "handles Spanish: ¿Qué pasó? Soy de España" $ do
SluggerText.toSlug (T.pack "¿Qué pasó? Soy de España")
`shouldBe` T.pack "que-paso-soy-de-espana"
it "handles Swedish: Varsågod ++ tack så mycket -- ölet" $ do
SluggerText.toSlug (T.pack "Varsågod ++ tack så mycket -- ölet")
`shouldBe` T.pack "varsagod-tack-sa-mycket-olet"
it "handles Turkish: Pijamalı hasta yağız şoföre çabucak güvendi" $ do
SluggerText.toSlug (T.pack "Pijamalı hasta yağız şoföre çabucak güvendi")
`shouldBe` T.pack "pijamali-hasta-yagiz-sofore-cabucak-guvendi"
it "handles Turkish (uppercase): PİJAMALI HASTA YAĞIZ ŞOFÖRE ÇABUCAK GÜVENDİ" $ do
SluggerText.toSlug (T.pack "PİJAMALI HASTA YAĞIZ ŞOFÖRE ÇABUCAK GÜVENDİ")
`shouldBe` T.pack "pijamali-hasta-yagiz-sofore-cabucak-guvendi"
it "handles a bunch we may have left out: æ Æ ð Ð ƒ Ƒ ø Ø œ Œ ł Ł ß þ Þ" $ do
SluggerText.toSlug (T.pack "æ Æ ð Ð ƒ Ƒ ø Ø œ Œ ł Ł ß þ Þ")
`shouldBe` T.pack "ae-ae-d-d-f-f-o-o-oe-oe-l-l-ss-th-th"