|
| 1 | +module Main (main) where |
| 2 | + |
| 3 | +import ASCII.Group |
| 4 | + |
| 5 | +import ASCII.Char (Char (..), allCharacters) |
| 6 | + |
| 7 | +import Control.Monad (Monad (..)) |
| 8 | +import Data.Bool (not) |
| 9 | +import Data.Foldable (all) |
| 10 | +import Data.Function (($)) |
| 11 | +import Data.List (filter, length) |
| 12 | +import System.IO (IO) |
| 13 | +import Control.Monad (when) |
| 14 | +import System.Exit (exitFailure) |
| 15 | + |
| 16 | +import Hedgehog (Property, assert, checkParallel, discover, property, |
| 17 | + withTests, (===)) |
| 18 | + |
| 19 | +main :: IO () |
| 20 | +main = checkParallel $$(discover) >>= \ok -> when (not ok) exitFailure |
| 21 | + |
| 22 | +prop_letter :: Property |
| 23 | +prop_letter = withTests 1 $ property $ |
| 24 | + charGroup CapitalLetterA === Printable |
| 25 | + |
| 26 | +prop_control :: Property |
| 27 | +prop_control = withTests 1 $ property $ |
| 28 | + charGroup EndOfTransmission === Control |
| 29 | + |
| 30 | +prop_not_printable :: Property |
| 31 | +prop_not_printable = withTests 1 $ property $ |
| 32 | + assert $ not $ inGroup Printable EndOfTransmission |
| 33 | + |
| 34 | +prop_is_control :: Property |
| 35 | +prop_is_control = withTests 1 $ property $ |
| 36 | + assert $ inGroup Control EndOfTransmission |
| 37 | + |
| 38 | +-- It is perhaps surprising that space is considered a |
| 39 | +-- "printable" character, since it does not visibly appear. |
| 40 | +prop_space_is_printable :: Property |
| 41 | +prop_space_is_printable = withTests 1 $ property $ |
| 42 | + charGroup Space === Printable |
| 43 | + |
| 44 | +-- It is perhaps surprising that horizontal tab is not |
| 45 | +-- in the same category as space. |
| 46 | +prop_horizontal_tab_is_control :: Property |
| 47 | +prop_horizontal_tab_is_control = withTests 1 $ property $ |
| 48 | + charGroup HorizontalTab === Control |
| 49 | + |
| 50 | +prop_various_printables :: Property |
| 51 | +prop_various_printables = withTests 1 $ property $ |
| 52 | + assert $ all (inGroup Printable) [CapitalLetterA, SmallLetterZ, Digit4, Tilde] |
| 53 | + |
| 54 | +prop_various_controls :: Property |
| 55 | +prop_various_controls = withTests 1 $ property $ |
| 56 | + assert $ all (inGroup Control) [Null, Substitute, UnitSeparator, Delete] |
| 57 | + |
| 58 | +prop_count_printables :: Property |
| 59 | +prop_count_printables = withTests 1 $ property $ |
| 60 | + length (filter (inGroup Printable) allCharacters) === 95 |
| 61 | + |
| 62 | +prop_count_controls :: Property |
| 63 | +prop_count_controls = withTests 1 $ property $ |
| 64 | + length (filter (inGroup Control) allCharacters) === 33 |
0 commit comments