File: Main.hs

package info (click to toggle)
haskell-text-manipulate 0.3.1.0-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: haskell: 711; makefile: 6
file content (243 lines) | stat: -rw-r--r-- 7,407 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

-- Module      : Main
-- Copyright   : (c) 2014-2020 Brendan Hay <brendan.g.hay@gmail.com>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)

module Main (main) where

import Data.Text (Text)
import Data.Text.Manipulate
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main =
  defaultMain $
    testGroup
      "tests"
      [ exampleGroup
          "lowerHead"
          lowerHead
          [ "",
            "title cased phrase",
            "camelCasedPhrase",
            "pascalCasedPhrase",
            "snake_cased_phrase",
            "spinal-cased-phrase",
            "train-Cased-Phrase",
            "1-Mixed_string AOK",
            "a  double--stop__phrase",
            "hTML5",
            "είναιΥπάρχουν πολλές-Αντίθετα",
            "je_obecněÚvodní-Španěl"
          ],
        exampleGroup
          "upperHead"
          upperHead
          [ "",
            "Title cased phrase",
            "CamelCasedPhrase",
            "PascalCasedPhrase",
            "Snake_cased_phrase",
            "Spinal-cased-phrase",
            "Train-Cased-Phrase",
            "1-Mixed_string AOK",
            "A  double--stop__phrase",
            "HTML5",
            "ΕίναιΥπάρχουν πολλές-Αντίθετα",
            "Je_obecněÚvodní-Španěl"
          ],
        exampleGroup
          "takeWord"
          takeWord
          [ "",
            "Title",
            "camel",
            "Pascal",
            "snake",
            "spinal",
            "Train",
            "1",
            "a",
            "HTML5",
            "Είναι",
            "Je"
          ],
        exampleGroup
          "dropWord"
          dropWord
          [ "",
            "cased phrase",
            "CasedPhrase",
            "CasedPhrase",
            "cased_phrase",
            "cased-phrase",
            "Cased-Phrase",
            "Mixed_string AOK",
            "double-stop_phrase",
            "",
            "Υπάρχουν πολλές-Αντίθετα",
            "obecněÚvodní-Španěl"
          ],
        exampleGroup
          "stripWord"
          stripWord
          [ Nothing,
            Just "cased phrase",
            Just "CasedPhrase",
            Just "CasedPhrase",
            Just "cased_phrase",
            Just "cased-phrase",
            Just "Cased-Phrase",
            Just "Mixed_string AOK",
            Just "double-stop_phrase",
            Just "",
            Just "Υπάρχουν πολλές-Αντίθετα",
            Just "obecněÚvodní-Španěl"
          ],
        testGroup
          "splitWords"
          [],
        testGroup
          "indentLines"
          [],
        testGroup
          "toAcronym"
          [],
        testGroup
          "toOrdinal"
          [ testCase "1st" ("1st" @=? toOrdinal 1),
            testCase "2nd" ("2nd" @=? toOrdinal 2),
            testCase "3rd" ("3rd" @=? toOrdinal 3),
            testCase "4th" ("4th" @=? toOrdinal 4),
            testCase "5th" ("5th" @=? toOrdinal 5),
            testCase "21st" ("21st" @=? toOrdinal 21),
            testCase "33rd" ("33rd" @=? toOrdinal 33),
            testCase "102nd" ("102nd" @=? toOrdinal 102),
            testCase "203rd" ("203rd" @=? toOrdinal 203)
          ],
        exampleGroup
          "toCamel"
          toCamel
          [ "",
            "titleCasedPhrase",
            "camelCasedPhrase",
            "pascalCasedPhrase",
            "snakeCasedPhrase",
            "spinalCasedPhrase",
            "trainCasedPhrase",
            "1MixedStringAOK",
            "aDoubleStopPhrase",
            "hTML5",
            "είναιΥπάρχουνΠολλέςΑντίθετα",
            "jeObecněÚvodníŠpaněl"
          ],
        exampleGroup
          "toPascal"
          toPascal
          [ "",
            "TitleCasedPhrase",
            "CamelCasedPhrase",
            "PascalCasedPhrase",
            "SnakeCasedPhrase",
            "SpinalCasedPhrase",
            "TrainCasedPhrase",
            "1MixedStringAOK",
            "ADoubleStopPhrase",
            "HTML5",
            "ΕίναιΥπάρχουνΠολλέςΑντίθετα",
            "JeObecněÚvodníŠpaněl"
          ],
        exampleGroup
          "toSnake"
          toSnake
          [ "",
            "title_cased_phrase",
            "camel_cased_phrase",
            "pascal_cased_phrase",
            "snake_cased_phrase",
            "spinal_cased_phrase",
            "train_cased_phrase",
            "1_mixed_string_aok",
            "a_double_stop_phrase",
            "html5",
            "είναι_υπάρχουν_πολλές_αντίθετα",
            "je_obecně_úvodní_španěl"
          ],
        exampleGroup
          "toSpinal"
          toSpinal
          [ "",
            "title-cased-phrase",
            "camel-cased-phrase",
            "pascal-cased-phrase",
            "snake-cased-phrase",
            "spinal-cased-phrase",
            "train-cased-phrase",
            "1-mixed-string-aok",
            "a-double-stop-phrase",
            "html5",
            "είναι-υπάρχουν-πολλές-αντίθετα",
            "je-obecně-úvodní-španěl"
          ],
        exampleGroup
          "toTrain"
          toTrain
          [ "",
            "Title-Cased-Phrase",
            "Camel-Cased-Phrase",
            "Pascal-Cased-Phrase",
            "Snake-Cased-Phrase",
            "Spinal-Cased-Phrase",
            "Train-Cased-Phrase",
            "1-Mixed-String-AOK",
            "A-Double-Stop-Phrase",
            "HTML5",
            "Είναι-Υπάρχουν-Πολλές-Αντίθετα",
            "Je-Obecně-Úvodní-Španěl"
          ],
        exampleGroup
          "toTitle"
          toTitle
          [ "",
            "Title Cased Phrase",
            "Camel Cased Phrase",
            "Pascal Cased Phrase",
            "Snake Cased Phrase",
            "Spinal Cased Phrase",
            "Train Cased Phrase",
            "1 Mixed String AOK",
            "A Double Stop Phrase",
            "HTML5",
            "Είναι Υπάρχουν Πολλές Αντίθετα",
            "Je Obecně Úvodní Španěl"
          ]
      ]

exampleGroup :: (Show a, Eq a) => TestName -> (Text -> a) -> [a] -> TestTree
exampleGroup n f = testGroup n . zipWith run reference
  where
    run (c, x) y = testCase c (f x @=? y)

    reference =
      [ ("Empty", ""),
        ("Title", "Title cased phrase"),
        ("Camel", "camelCasedPhrase"),
        ("Pascal", "PascalCasedPhrase"),
        ("Snake", "snake_cased_phrase"),
        ("Spinal", "spinal-cased-phrase"),
        ("Train", "Train-Cased-Phrase"),
        ("Mixed", "1-Mixed_string AOK"),
        ("Double Stop", "a  double--stop__phrase"),
        ("Acronym", "HTML5"),
        ("Greek", "ΕίναιΥπάρχουν πολλές-Αντίθετα"),
        ("Czech", "Je_obecněÚvodní-Španěl")
      ]