@@ -5,10 +5,12 @@ import Prelude
5
5
6
6
import Control.Monad.Reader.Class (class MonadReader , ask , local )
7
7
import Data.Char (fromCharCode )
8
- import Data.Char.Unicode (GeneralCategory (..), digitToInt , generalCategory , isAlpha , isAlphaNum , isAscii , isAsciiLower , isAsciiUpper , isControl , isDigit , isHexDigit , isLatin1 , isLetter , isLower , isMark , isNumber , isOctDigit , isPrint , isPunctuation , isSeparator , isSpace , isSymbol , isUpper )
8
+ import Data.Char.Unicode (GeneralCategory (..), decDigitToInt , hexDigitToInt , octDigitToInt , generalCategory , isAlpha , isAlphaNum , isAscii , isAsciiLower , isAsciiUpper , isControl , isDecDigit , isHexDigit , isLatin1 , isLetter , isLower , isMark , isNumber , isOctDigit , isPrint , isPunctuation , isSeparator , isSpace , isSymbol , isUpper )
9
+ import Data.Foldable (traverse_ )
9
10
import Data.Maybe (Maybe (..), fromJust )
10
11
import Data.Monoid (power , guard )
11
12
import Data.NonEmpty ((:|))
13
+ import Data.String.CodeUnits (singleton )
12
14
import Effect.Console (log )
13
15
import Effect.Class (class MonadEffect , liftEffect )
14
16
import Partial.Unsafe (unsafePartial )
@@ -53,15 +55,17 @@ dataCharUnicodeTests = describe "module Data.Char.Unicode" do
53
55
isUpperTests
54
56
isAlphaTests
55
57
isAlphaNumTests
56
- isDigitTests
57
- isOctDigitTests
58
58
isHexDigitTests
59
+ isDecDigitTests
60
+ isOctDigitTests
59
61
isPunctuationTests
60
62
isSymbolTests
61
63
toUpperTests
62
64
toLowerTests
63
65
toTitleTests
64
- digitToIntTests
66
+ hexDigitToIntTests
67
+ decDigitToIntTests
68
+ octDigitToIntTests
65
69
isLetterTests
66
70
isMarkTests
67
71
isNumberTests
@@ -295,10 +299,10 @@ isAlphaNumTests = describe "isAlphaNum" do
295
299
it " '\\ n' is not AlphaNum" $
296
300
isAlphaNum ' \n ' `shouldEqual` false
297
301
298
- isDigitTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
299
- isDigitTests = describe " isDigit " do
300
- it " digits are digits" $ liftEffect $ quickCheck \(AsciiDigit char) -> isDigit char
301
- it " non digits are not digits" $ liftEffect $ quickCheck \(NonAsciiDigit char) -> not $ isDigit char
302
+ isDecDigitTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
303
+ isDecDigitTests = describe " isDecDigit " do
304
+ it " digits are digits" $ liftEffect $ quickCheck \(AsciiDigit char) -> isDecDigit char
305
+ it " non digits are not digits" $ liftEffect $ quickCheck \(NonAsciiDigit char) -> not $ isDecDigit char
302
306
303
307
isOctDigitTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
304
308
isOctDigitTests = describe " isOctDigit" do
@@ -352,23 +356,38 @@ toLowerTests = pure unit
352
356
toTitleTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
353
357
toTitleTests = pure unit
354
358
355
- digitToIntTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
356
- digitToIntTests = describe " digitToInt" do
359
+ notDigit :: forall m . MonadReader Int m => MonadEffect m =>
360
+ String -> (Char -> Maybe Int ) -> Char -> m Unit
361
+ notDigit base func char =
362
+ it (" '" <> singleton char <> " ' is not a " <> base <> " digit" ) $
363
+ func char `shouldEqual` Nothing
364
+
365
+ hexDigitToIntTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
366
+ hexDigitToIntTests = describe " hexDigitToInt" do
357
367
it " '0'..'9' get mapped correctly" $
358
- map digitToInt [' 0' ,' 1' ,' 2' ,' 3' ,' 4' ,' 5' ,' 6' ,' 7' ,' 8' ,' 9' ] `shouldEqual`
368
+ map hexDigitToInt [' 0' ,' 1' ,' 2' ,' 3' ,' 4' ,' 5' ,' 6' ,' 7' ,' 8' ,' 9' ] `shouldEqual`
359
369
[Just 0 , Just 1 , Just 2 , Just 3 , Just 4 , Just 5 , Just 6 , Just 7 , Just 8 , Just 9 ]
360
370
it " 'a'..'f' get mapped correctly" $
361
- map digitToInt [' a' ,' b' ,' c' ,' d' ,' e' ,' f' ] `shouldEqual`
371
+ map hexDigitToInt [' a' ,' b' ,' c' ,' d' ,' e' ,' f' ] `shouldEqual`
362
372
[Just 10 , Just 11 , Just 12 , Just 13 , Just 14 , Just 15 ]
363
373
it " 'A'..'F' get mapped correctly" $
364
- map digitToInt [' A' ,' B' ,' C' ,' D' ,' E' ,' F' ] `shouldEqual`
374
+ map hexDigitToInt [' A' ,' B' ,' C' ,' D' ,' E' ,' F' ] `shouldEqual`
365
375
[Just 10 , Just 11 , Just 12 , Just 13 , Just 14 , Just 15 ]
366
- it " 'G' is not a digit" $
367
- digitToInt ' G' `shouldEqual` Nothing
368
- it " '♥' is not a digit" $
369
- digitToInt '♥' `shouldEqual` Nothing
370
- it " '国' is not a digit" $
371
- digitToInt '国' `shouldEqual` Nothing
376
+ traverse_ (notDigit " hex" hexDigitToInt) [' g' , ' G' , '♥', '国']
377
+
378
+ decDigitToIntTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
379
+ decDigitToIntTests = describe " decDigitToInt" do
380
+ it " '0'..'9' get mapped correctly" $
381
+ map decDigitToInt [' 0' ,' 1' ,' 2' ,' 3' ,' 4' ,' 5' ,' 6' ,' 7' ,' 8' ,' 9' ] `shouldEqual`
382
+ [Just 0 , Just 1 , Just 2 , Just 3 , Just 4 , Just 5 , Just 6 , Just 7 , Just 8 , Just 9 ]
383
+ traverse_ (notDigit " dec" decDigitToInt) [' a' , ' A' , '♥', '国']
384
+
385
+ octDigitToIntTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
386
+ octDigitToIntTests = describe " octDigitToInt" do
387
+ it " '0'..'7' get mapped correctly" $
388
+ map octDigitToInt [' 0' ,' 1' ,' 2' ,' 3' ,' 4' ,' 5' ,' 6' ,' 7' ] `shouldEqual`
389
+ [Just 0 , Just 1 , Just 2 , Just 3 , Just 4 , Just 5 , Just 6 , Just 7 ]
390
+ traverse_ (notDigit " oct" octDigitToInt) [' 8' , ' 9' , '♥', '国']
372
391
373
392
isLetterTests :: forall m . MonadReader Int m => MonadEffect m => m Unit
374
393
isLetterTests = describe " isLetter" do
0 commit comments