<commit_before>{- |
Module       : TestMittensSlug
Description  : Test the Mittens.Slug module
Copyright    : 2014, <NAME>
License      : BSD3
Maintainer   : <NAME> <<EMAIL>>
Stability    : experimental
Portability  : Linux

-}

module TestMittensSlug where

import           Control.Applicative
import           Mittens.Slug
import           Data.Text (pack)
import           Test.QuickCheck

-- |This is horrifying, but the alternative is to use
-- unsafePerformIO. This solution keeps everything in the Gen monad.
instance Arbitrary Slug where
  arbitrary = elements [4 .. 32] >>= \ln ->
                                        take ln <$> infiniteListOf (elements slugAcceptChars) >>= \str ->
                                                                                                     case mkSlugEither $ pack str of
                                                                                                       Left err -> fail err
                                                                                                       Right slg -> return slg<commit_msg>Sugarize slug generation<commit_after>{- |
Module       : TestMittensSlug
Description  : Test the Mittens.Slug module
Copyright    : 2014, <NAME>
License      : BSD3
Maintainer   : <NAME> <<EMAIL>>
Stability    : experimental
Portability  : Linux

-}

module TestMittensSlug where

import           Control.Applicative
import           Mittens.Slug
import           Data.Text (pack)
import           Test.QuickCheck

instance Arbitrary Slug where
  arbitrary = do
    slugLength <- elements [4 .. 32]
    slugCandidate <- pack <$> take slugLength <$> infiniteListOf (elements slugAcceptChars)
    case mkSlugEither slugCandidate of
      Left err  -> fail err
      Right slg -> return slg
{'fraction_non_alphanumeric': 0.06625491297024144, 'fraction_numerical': 0.008983717012914094, 'mean_word_length': 1.4818941504178273, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6165954', 'n_tokens_mistral': 451, 'n_tokens_neox': 423, 'n_words': 140}