Skip to content

Commit 51d5d04

Browse files
authored
Fixed: Dasherize tests (#7)
* Fixed: Remove uppercase test This PR removes the uppercase text test. The dasherize function was previously modified to not put the leading dash in the case of a capital letter starting the string, so this test is no longer needed. Any other cases are covered by existing tests. * Fixed: Dasherize tests Breaks dasherize tests out into two separate ones. One checks that there is no whitespace in the resulting string. The second checks that there are no consecutive dashes in the resulting string. This replaces a previous test that was failing on bad input.
1 parent 9d3a1f8 commit 51d5d04

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

tests/String/DasherizeTest.elm

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module String.DasherizeTest exposing (dasherizeTest)
22

3-
import Char
3+
import Char.Extra
44
import Expect
55
import Fuzz exposing (..)
6-
import String exposing (replace)
7-
import String.Extra exposing (..)
8-
import String.TestData as TestData
6+
import Regex exposing (Regex)
7+
import String
8+
import String.Extra exposing (dasherize)
99
import Test exposing (..)
1010

1111

@@ -17,40 +17,29 @@ dasherizeTest =
1717
dasherize s
1818
|> String.toLower
1919
|> Expect.equal (dasherize s)
20-
, fuzz string "It replaces spaces and underscores with a dash" <|
20+
, fuzz string "It has no spaces in the resulting string" <|
2121
\s ->
2222
let
23-
expected =
24-
String.toLower
25-
>> String.trim
26-
>> replace " " " "
27-
>> replace " " "-"
28-
>> replace "\t" "-"
29-
>> replace "\n" "-"
30-
>> replace "_" "-"
31-
>> replace "--" "-"
32-
>> replace "--" "-"
23+
whiteSpaceChecker =
24+
List.any Char.Extra.isSpace
3325
in
3426
dasherize (String.toLower s)
35-
|> String.toLower
36-
|> Expect.equal (expected s)
37-
, fuzz TestData.randomStrings "It puts dash before every single uppercase character" <|
27+
|> String.toList
28+
|> whiteSpaceChecker
29+
|> Expect.equal False
30+
, fuzz string "It has no consecutive dashes in the resulting string" <|
3831
\s ->
39-
dasherize s
40-
|> Expect.equal (replaceUppercase s |> String.toLower)
32+
let
33+
consecutiveDashesChecker =
34+
Regex.contains consecutiveDashesRegex
35+
in
36+
dasherize (String.toLower s)
37+
|> consecutiveDashesChecker
38+
|> Expect.equal False
4139
]
4240

4341

44-
replaceUppercase : String -> String
45-
replaceUppercase string =
46-
string
47-
|> String.toList
48-
|> List.map
49-
(\c ->
50-
if Char.isUpper c then
51-
"-" ++ String.fromChar c
52-
53-
else
54-
String.fromChar c
55-
)
56-
|> String.concat
42+
consecutiveDashesRegex : Regex
43+
consecutiveDashesRegex =
44+
Regex.fromString "\\-{2,}"
45+
|> Maybe.withDefault Regex.never

0 commit comments

Comments
 (0)