ascii-group 1.0.0.15 → 1.0.0.16
raw patch · 4 files changed
+134/−106 lines, 4 filesdep ~basedep ~hashabledep ~hedgehogPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hashable, hedgehog
API changes (from Hackage documentation)
Files
- ascii-group.cabal +7/−7
- changelog.md +4/−0
- library/ASCII/Group.hs +66/−70
- test/Main.hs +57/−29
ascii-group.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: ascii-group-version: 1.0.0.15+version: 1.0.0.16 synopsis: ASCII character groups category: Data, Text @@ -26,15 +26,15 @@ location: git://github.com/typeclasses/ascii-group.git common base- default-language: Haskell2010+ default-language: GHC2021 ghc-options: -Wall default-extensions: NoImplicitPrelude build-depends:- ascii-char ^>= 1.0- , base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17+ , ascii-char ^>= 1.0+ , base ^>= 4.16 || ^>= 4.17 || ^>= 4.18 library import: base@@ -48,7 +48,7 @@ StandaloneDeriving build-depends:- hashable ^>= 1.3.5 || ^>= 1.4+ , hashable ^>= 1.4.2 exposed-modules: ASCII.Group@@ -60,8 +60,8 @@ main-is: Main.hs build-depends:- ascii-group- , hedgehog ^>= 1.0.5 || ^>= 1.1 || ^>= 1.2+ , ascii-group+ , hedgehog ^>= 1.1.2 || ^>= 1.2 default-extensions: OverloadedStrings
changelog.md view
@@ -1,3 +1,7 @@+### 1.0.0.16 (2023-06-26)++Raise language to GHC2021+ ### 1.0.0.15 (2023-01-02) Minor Cabal correction (change `extra-doc-files` to `extra-source-files`)
library/ASCII/Group.hs view
@@ -1,32 +1,36 @@-{- |--ASCII characters are broadly categorized into two groups: /control codes/ and /printable characters/.+-- | ASCII characters are broadly categorized into two groups:+-- /control codes/ and /printable characters/.+module ASCII.Group+ ( -- * The @Group@ type+ Group (..), --}+ -- * Functions+ charGroup,+ inGroup, -module ASCII.Group- (- {- * The @Group@ type -} Group (..),- {- * Functions -} charGroup, inGroup- {- * Notes -} {- $notes -}+ -- * Notes+ -- $notes )- where+where import ASCII.Char (Char)+import ASCII.Char qualified as Char import Data.Bool (Bool) import Data.Data (Data) import Data.Eq (Eq, (==)) import Data.Hashable (Hashable) import Data.Ord (Ord, (<)) import GHC.Generics (Generic)-import Prelude (Bounded, Enum) import Text.Show (Show)--import qualified ASCII.Char as Char+import Prelude (Bounded, Enum) -data Group =- Control -- ^ 33 of the ASCII characters are /control codes/. A few of these are still in use, but most are obsolete relics of the early days of computing.- | Printable -- ^ 95 of the ASCII characters are /printable characters/ such as letters and numbers, mostly corresponding to the keys on an American English keyboard.+data Group+ = -- | 33 of the ASCII characters are /control codes/.+ -- A few of these are still in use, but most are obsolete relics of the early days of computing.+ Control+ | -- | 95 of the ASCII characters are /printable characters/ such as letters and numbers,+ -- mostly corresponding to the keys on an American English keyboard.+ Printable deriving stock instance Eq Group @@ -44,63 +48,55 @@ deriving anyclass instance Hashable Group -{- | Determine which group a particular character belongs to.-->>> map charGroup [CapitalLetterA,EndOfTransmission]-[Printable,Control]---}-+-- | Determine which group a particular character belongs to+--+-- >>> map charGroup [CapitalLetterA,EndOfTransmission]+-- [Printable,Control] charGroup :: Char -> Group charGroup x =- case x of- _ | (x < Char.Space) -> Control- Char.Delete -> Control- _ -> Printable--{- | Test whether a character belongs to a particular group.-->>> inGroup Printable EndOfTransmission-False-->>> inGroup Control EndOfTransmission-True---}+ case x of+ _ | (x < Char.Space) -> Control+ Char.Delete -> Control+ _ -> Printable +-- | Test whether a character belongs to a particular group+--+-- >>> inGroup Printable EndOfTransmission+-- False+--+-- >>> inGroup Control EndOfTransmission+-- True inGroup :: Group -> Char -> Bool inGroup g x = charGroup x == g -{- $notes--Space is a printable character (perhaps surprisingly, given that it is invisible).-->>> charGroup Space-Printable--Tab is a control code (perhaps surprisingly, given that space is a printable character).-->>> charGroup HorizontalTab-Control--A few examples of printable characters:-->>> all (inGroup Printable) [CapitalLetterA,SmallLetterZ,Digit4,Tilde]-True--A few examples of control characters:-->>> all (inGroup Control) [Null,Substitute,UnitSeparator,Delete]-True--There are 33 control codes.-->>> length (filter (inGroup Control) allCharacters)-33--There are 95 printable characters.-->>> length (filter (inGroup Printable) allCharacters)-95---}+-- $notes+--+-- Space is a printable character (perhaps surprisingly, given that it is invisible).+--+-- >>> charGroup Space+-- Printable+--+-- Tab is a control code (perhaps surprisingly, given that space is a printable character).+--+-- >>> charGroup HorizontalTab+-- Control+--+-- A few examples of printable characters:+--+-- >>> all (inGroup Printable) [CapitalLetterA,SmallLetterZ,Digit4,Tilde]+-- True+--+-- A few examples of control characters:+--+-- >>> all (inGroup Control) [Null,Substitute,UnitSeparator,Delete]+-- True+--+-- There are 33 control codes.+--+-- >>> length (filter (inGroup Control) allCharacters)+-- 33+--+-- There are 95 printable characters.+--+-- >>> length (filter (inGroup Printable) allCharacters)+-- 95
test/Main.hs view
@@ -1,64 +1,92 @@ module Main (main) where -import ASCII.Group- import ASCII.Char (Char (..), allCharacters)--import Control.Monad (Monad (..))+import ASCII.Group+import Control.Monad (Monad (..), when) import Data.Bool (not) import Data.Foldable (all) import Data.Function (($)) import Data.List (filter, length)-import System.IO (IO)-import Control.Monad (when)+import Hedgehog+ ( Property,+ assert,+ checkParallel,+ discover,+ property,+ withTests,+ (===),+ ) import System.Exit (exitFailure)--import Hedgehog (Property, assert, checkParallel, discover, property,- withTests, (===))+import System.IO (IO) main :: IO () main = checkParallel $$(discover) >>= \ok -> when (not ok) exitFailure prop_letter :: Property-prop_letter = withTests 1 $ property $- charGroup CapitalLetterA === Printable+prop_letter =+ withTests 1 $+ property $+ charGroup CapitalLetterA === Printable prop_control :: Property-prop_control = withTests 1 $ property $- charGroup EndOfTransmission === Control+prop_control =+ withTests 1 $+ property $+ charGroup EndOfTransmission === Control prop_not_printable :: Property-prop_not_printable = withTests 1 $ property $- assert $ not $ inGroup Printable EndOfTransmission+prop_not_printable =+ withTests 1 $+ property $+ assert $+ not $+ inGroup Printable EndOfTransmission prop_is_control :: Property-prop_is_control = withTests 1 $ property $- assert $ inGroup Control EndOfTransmission+prop_is_control =+ withTests 1 $+ property $+ assert $+ inGroup Control EndOfTransmission -- It is perhaps surprising that space is considered a -- "printable" character, since it does not visibly appear. prop_space_is_printable :: Property-prop_space_is_printable = withTests 1 $ property $- charGroup Space === Printable+prop_space_is_printable =+ withTests 1 $+ property $+ charGroup Space === Printable -- It is perhaps surprising that horizontal tab is not -- in the same category as space. prop_horizontal_tab_is_control :: Property-prop_horizontal_tab_is_control = withTests 1 $ property $- charGroup HorizontalTab === Control+prop_horizontal_tab_is_control =+ withTests 1 $+ property $+ charGroup HorizontalTab === Control prop_various_printables :: Property-prop_various_printables = withTests 1 $ property $- assert $ all (inGroup Printable) [CapitalLetterA, SmallLetterZ, Digit4, Tilde]+prop_various_printables =+ withTests 1 $+ property $+ assert $+ all (inGroup Printable) [CapitalLetterA, SmallLetterZ, Digit4, Tilde] prop_various_controls :: Property-prop_various_controls = withTests 1 $ property $- assert $ all (inGroup Control) [Null, Substitute, UnitSeparator, Delete]+prop_various_controls =+ withTests 1 $+ property $+ assert $+ all (inGroup Control) [Null, Substitute, UnitSeparator, Delete] prop_count_printables :: Property-prop_count_printables = withTests 1 $ property $- length (filter (inGroup Printable) allCharacters) === 95+prop_count_printables =+ withTests 1 $+ property $+ length (filter (inGroup Printable) allCharacters) === 95 prop_count_controls :: Property-prop_count_controls = withTests 1 $ property $- length (filter (inGroup Control) allCharacters) === 33+prop_count_controls =+ withTests 1 $+ property $+ length (filter (inGroup Control) allCharacters) === 33