diff --git a/test/Test/Warden/Arbitrary.hs b/test/Test/Warden/Arbitrary.hs index 3e93e13..432a265 100644 --- a/test/Test/Warden/Arbitrary.hs +++ b/test/Test/Warden/Arbitrary.hs @@ -11,10 +11,11 @@ import qualified Data.ByteString.Lazy as BL import Data.Char import Data.Csv import qualified Data.Set as S -import Data.List (nub) +import Data.List ((\\), nub) import qualified Data.List as L import Data.List.NonEmpty (NonEmpty) import qualified Data.List.NonEmpty as NE +import Data.String (String) import qualified Data.Text as T import Data.Text.Encoding (decodeUtf8, decodeUtf8', encodeUtf8) import Data.Time.Calendar (Day(..)) @@ -807,34 +808,45 @@ genSensibleDateTime = do renderedDate :: Gen BS.ByteString renderedDate = do dt <- genSensibleDateTime - render <- frequency [(1, renderNoSeparator), (9, renderSeparator)] + render <- frequency [(1, renderDateNoSeparator), (9, renderDateSeparator)] pure . BSC.pack $ render dt - where - renderNoSeparator = do - tp <- timePart - pure (formatTime defaultTimeLocale ("%Y%m%d" <> tp)) - - renderSeparator = do - tp <- timePart - sep <- elements ["-", ".", "/"] - pure (formatTime defaultTimeLocale ((concat ["%Y", sep, "%m", sep, "%d"]) <> tp)) - - timePart = elements [ - "" - , "%H%M" - , "%H:%M" - , "%H%M%S" - , "%H:%M:%S" - , "T%H:%M:%SZ" - ] + +renderDateNoSeparator :: Gen (UTCTime -> String) +renderDateNoSeparator = do + tp <- timePart + pure (formatTime defaultTimeLocale ("%Y%m%d" <> tp)) + +renderDateSeparator :: Gen (UTCTime -> String) +renderDateSeparator = do + tp <- timePart + sep <- elements ["-", ".", "/"] + pure (formatTime defaultTimeLocale ((concat ["%Y", sep, "%m", sep, "%d"]) <> tp)) + +timePart :: Gen String +timePart = elements [ + "" + , "%H%M" + , "%H:%M" + , "%H%M%S" + , "%H:%M:%S" + , "T%H:%M:%SZ" + ] renderedNonDate :: Gen BS.ByteString renderedNonDate = do - x <- fmap BS.pack $ listOf1 arbitrary + x <- fmap BS.pack $ listOf1 noDigits dt <- renderedDate oneof [ pure $ x <> dt - , pure $ BS.reverse dt + , reversed , encodeUtf8 <$> elements muppets ] + where + reversed = do + dt <- genSensibleDateTime + render <- renderDateSeparator + pure . BSC.pack . reverse $ render dt + + noDigits = + elements $ [0x00..0xff] \\ [0x30..0x39]