From c893d4cd9e5f785ed98150e482332697e96b680c Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Thu, 26 Aug 2021 12:28:02 +0200 Subject: [PATCH 1/6] start working on the sound emoji --- src/Data/Char/Emoji.hs | 2 + src/Data/Char/Emoji/Sound.hs | 79 +++++++++++++++++++++++++++++++ test/Data/Char/Emoji/SoundSpec.hs | 26 ++++++++++ unicode-tricks.cabal | 2 + 4 files changed, 109 insertions(+) create mode 100644 src/Data/Char/Emoji/Sound.hs create mode 100644 test/Data/Char/Emoji/SoundSpec.hs diff --git a/src/Data/Char/Emoji.hs b/src/Data/Char/Emoji.hs index 80e6a7dd..bc57c945 100644 --- a/src/Data/Char/Emoji.hs +++ b/src/Data/Char/Emoji.hs @@ -20,6 +20,7 @@ module Data.Char.Emoji ( , module Data.Char.Emoji.Moon , module Data.Char.Emoji.Science , module Data.Char.Emoji.SkinColor + , module Data.Char.Emoji.Sound , module Data.Char.Emoji.Zodiac ) where @@ -31,4 +32,5 @@ import Data.Char.Emoji.Gender import Data.Char.Emoji.Moon import Data.Char.Emoji.Science import Data.Char.Emoji.SkinColor +import Data.Char.Emoji.Sound import Data.Char.Emoji.Zodiac diff --git a/src/Data/Char/Emoji/Sound.hs b/src/Data/Char/Emoji/Sound.hs new file mode 100644 index 00000000..876d142a --- /dev/null +++ b/src/Data/Char/Emoji/Sound.hs @@ -0,0 +1,79 @@ +{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, Safe, TypeApplications #-} + +module Data.Char.Emoji.Sound where + +import Control.DeepSeq(NFData) + +import Data.Char.Core(UnicodeCharacter(toUnicodeChar, fromUnicodeChar, fromUnicodeChar', isInCharRange), UnicodeText(isInTextRange), mapFromEnum, mapToEnumSafe, mapToEnum, generateIsInTextRange') +import Data.Data(Data) +import Data.Hashable(Hashable) + +import GHC.Generics(Generic) + +import Test.QuickCheck.Arbitrary(Arbitrary(arbitrary), arbitraryBoundedEnum) + +_volumeOffset :: Int +_volumeOffset = 0x1f507 + +data Volume + = SilentVolume + | LowVolume + | MediumVolume + | LoudVolume + deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) + +instance Arbitrary Volume where + arbitrary = arbitraryBoundedEnum + +instance Hashable Volume + +instance NFData Volume + +instance UnicodeCharacter Volume where + toUnicodeChar = mapFromEnum _volumeOffset + fromUnicodeChar = mapToEnumSafe _volumeOffset + fromUnicodeChar' = mapToEnum _volumeOffset + isInCharRange c = '\x1f507' <= c && c <= '\x1f50a' + +instance UnicodeText Volume where + isInTextRange = generateIsInTextRange' @Volume + +data Bell + = NoBell + | Bell + deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) + +instance Arbitrary Bell where + arbitrary = arbitraryBoundedEnum + +instance Hashable Bell + +instance NFData Bell + +instance UnicodeCharacter Bell where + toUnicodeChar NoBell = '\x1f515' + toUnicodeChar Bell = '\x1f514' + fromUnicodeChar' '\x1f515' = NoBell + fromUnicodeChar' '\x1f514' = Bell + fromUnicodeChar '\x1f515' = Just NoBell + fromUnicodeChar '\x1f514' = Just Bell + fromUnicodeChar _ = Nothing + isInCharRange c = '\x1f514' <= c && c <= '\x1f515' + +instance UnicodeText Bell where + isInTextRange = generateIsInTextRange' @Bell + +data Sound + = Loudspeaker + | Megaphone + | PostalHorn + deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) + +instance Arbitrary Sound where + arbitrary = arbitraryBoundedEnum + +instance Hashable Sound + +instance NFData Sound + +instance UnicodeCharacter Sound diff --git a/test/Data/Char/Emoji/SoundSpec.hs b/test/Data/Char/Emoji/SoundSpec.hs new file mode 100644 index 00000000..fdcee278 --- /dev/null +++ b/test/Data/Char/Emoji/SoundSpec.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE TypeApplications #-} + +module Data.Char.Emoji.SoundSpec + ( spec + ) where + +import Data.Char.CoreTest +import Data.Char.Emoji.Sound +import Test.Hspec + +spec :: Spec +spec = do + testBounded @Volume + testUnicodeCharacter @Volume + testUnicodeText @Volume + testHashable @Volume + testBounded @Bell + testUnicodeCharacter @Bell + testUnicodeText @Bell + testHashable @Bell + {- + testBounded @Sound + testUnicodeCharacter @Sound + testUnicodeText @Sound + testHashable @Sound + -} diff --git a/unicode-tricks.cabal b/unicode-tricks.cabal index 0f3f7bcb..f24447c4 100644 --- a/unicode-tricks.cabal +++ b/unicode-tricks.cabal @@ -44,6 +44,7 @@ library , Data.Char.Emoji.NoEvilMonkey , Data.Char.Emoji.Science , Data.Char.Emoji.SkinColor + , Data.Char.Emoji.Sound , Data.Char.Emoji.Zodiac , Data.Char.Enclosed , Data.Char.Egyptian @@ -118,6 +119,7 @@ test-suite utricks , Data.Char.Emoji.NoEvilMonkeySpec , Data.Char.Emoji.ScienceSpec , Data.Char.Emoji.SkinColorSpec + , Data.Char.Emoji.SoundSpec , Data.Char.Emoji.ZodiacSpec , Data.Char.FrameSpec , Data.Char.MathSpec From 476ff53963f12fcbf797d4a750ebaacee832fa0d Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Thu, 26 Aug 2021 12:44:22 +0200 Subject: [PATCH 2/6] more documentation --- src/Data/Char/Emoji/Sound.hs | 59 +++++++++++++++++++++++-------- test/Data/Char/Emoji/SoundSpec.hs | 10 +++--- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/Data/Char/Emoji/Sound.hs b/src/Data/Char/Emoji/Sound.hs index 876d142a..3aa0c739 100644 --- a/src/Data/Char/Emoji/Sound.hs +++ b/src/Data/Char/Emoji/Sound.hs @@ -1,5 +1,16 @@ {-# LANGUAGE DeriveDataTypeable, DeriveGeneric, Safe, TypeApplications #-} +{-| +Module : Data.Char.Emoji.Sound +Description : A module that defines emoji that deal with sound, volume and instruments. +Maintainer : hapytexeu+gh@gmail.com +Stability : experimental +Portability : POSIX + +The emoji have nine sound emoji. This modules defines data constructors for these emoji, and aims to +define a sensical 'Ord' relation for example to specify the volume of sound. +-} + module Data.Char.Emoji.Sound where import Control.DeepSeq(NFData) @@ -15,11 +26,12 @@ import Test.QuickCheck.Arbitrary(Arbitrary(arbitrary), arbitraryBoundedEnum) _volumeOffset :: Int _volumeOffset = 0x1f507 +-- ^ There are four emoji that specify the volume of sound. data Volume - = SilentVolume - | LowVolume - | MediumVolume - | LoudVolume + = SilentVolume -- ^ The volume of the sound is set to /silence/, this is denoted with 🔇. + | LowVolume -- ^ The volume of the sound is /low/, this is denoted with 🔈. + | MediumVolume -- ^ The volume of the sound is /medium/, this is denoted with 🔉. + | LoudVolume -- ^ The volume of the sound is set to /loud/, this is denoted with 🔊. deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) instance Arbitrary Volume where @@ -38,9 +50,11 @@ instance UnicodeCharacter Volume where instance UnicodeText Volume where isInTextRange = generateIsInTextRange' @Volume +-- | There are two bell emoji, one with a bell, and one without a bell. This is often used +-- to enable/disable notifications. data Bell - = NoBell - | Bell + = NoBell -- ^ An emoji with a bell and a slash, often used to disable notifcations and denoted with 🔕. + | Bell -- ^ An emoji with a bell, often used to enable notifications and denoted with 🔔. deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) instance Arbitrary Bell where @@ -63,17 +77,34 @@ instance UnicodeCharacter Bell where instance UnicodeText Bell where isInTextRange = generateIsInTextRange' @Bell -data Sound - = Loudspeaker - | Megaphone - | PostalHorn +-- ^ Three emoji that deal with amplifying sound. +data Instrument + = Loudspeaker -- ^ The /loudspeaker/ emoji, denoted with 📢. + | Megaphone -- ^ The /megaphone/ emoji, denoted with 📣. + | PostalHorn -- ^ The /postal horn/ emoji, denoted with 📯. deriving (Bounded, Data, Enum, Eq, Generic, Ord, Read, Show) -instance Arbitrary Sound where +instance Arbitrary Instrument where arbitrary = arbitraryBoundedEnum -instance Hashable Sound +instance Hashable Instrument + +instance NFData Instrument + +instance UnicodeCharacter Instrument where + toUnicodeChar Loudspeaker = '\x1f4e2' + toUnicodeChar Megaphone = '\x1f4e3' + toUnicodeChar PostalHorn = '\x1f4ef' + fromUnicodeChar' '\x1f4e2' = Loudspeaker + fromUnicodeChar' '\x1f4e3' = Megaphone + fromUnicodeChar' '\x1f4ef' = PostalHorn + fromUnicodeChar '\x1f4e2' = Just Loudspeaker + fromUnicodeChar '\x1f4e3' = Just Megaphone + fromUnicodeChar '\x1f4ef' = Just PostalHorn + fromUnicodeChar _ = Nothing + isInCharRange '\x1f4ef' = True + isInCharRange c = '\x1f4e2' <= c && c <= '\x1f4e3' -instance NFData Sound -instance UnicodeCharacter Sound +instance UnicodeText Instrument where + isInTextRange = generateIsInTextRange' @Instrument diff --git a/test/Data/Char/Emoji/SoundSpec.hs b/test/Data/Char/Emoji/SoundSpec.hs index fdcee278..6cfe5c3c 100644 --- a/test/Data/Char/Emoji/SoundSpec.hs +++ b/test/Data/Char/Emoji/SoundSpec.hs @@ -18,9 +18,7 @@ spec = do testUnicodeCharacter @Bell testUnicodeText @Bell testHashable @Bell - {- - testBounded @Sound - testUnicodeCharacter @Sound - testUnicodeText @Sound - testHashable @Sound - -} + testBounded @Instrument + testUnicodeCharacter @Instrument + testUnicodeText @Instrument + testHashable @Instrument From 66087ac7a808039a141a5d15fe32f1ee3c1d8621 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Thu, 26 Aug 2021 13:06:26 +0200 Subject: [PATCH 3/6] added missing comment --- src/Data/Char/Emoji/Sound.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Data/Char/Emoji/Sound.hs b/src/Data/Char/Emoji/Sound.hs index 3aa0c739..ce6c6fa3 100644 --- a/src/Data/Char/Emoji/Sound.hs +++ b/src/Data/Char/Emoji/Sound.hs @@ -11,7 +11,12 @@ The emoji have nine sound emoji. This modules defines data constructors for thes define a sensical 'Ord' relation for example to specify the volume of sound. -} -module Data.Char.Emoji.Sound where +module Data.Char.Emoji.Sound ( + -- * Emoji that deal with sound. + Volume(SilentVolume, LowVolume, MediumVolume, LoudVolume) + , Bell(NoBell, Bell) + , Instrument(Loudspeaker, Megaphone, PostalHorn) + ) where import Control.DeepSeq(NFData) @@ -26,7 +31,7 @@ import Test.QuickCheck.Arbitrary(Arbitrary(arbitrary), arbitraryBoundedEnum) _volumeOffset :: Int _volumeOffset = 0x1f507 --- ^ There are four emoji that specify the volume of sound. +-- | There are four emoji that specify the volume of sound. data Volume = SilentVolume -- ^ The volume of the sound is set to /silence/, this is denoted with 🔇. | LowVolume -- ^ The volume of the sound is /low/, this is denoted with 🔈. @@ -77,7 +82,7 @@ instance UnicodeCharacter Bell where instance UnicodeText Bell where isInTextRange = generateIsInTextRange' @Bell --- ^ Three emoji that deal with amplifying sound. +-- | Three emoji that deal with amplifying sound. data Instrument = Loudspeaker -- ^ The /loudspeaker/ emoji, denoted with 📢. | Megaphone -- ^ The /megaphone/ emoji, denoted with 📣. From aa27f91f5f5cd6a6dff424aac03f98a0fde8f499 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Thu, 26 Aug 2021 13:23:42 +0200 Subject: [PATCH 4/6] fix non-exhaustive patterns --- src/Data/Char/Emoji/Sound.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/Char/Emoji/Sound.hs b/src/Data/Char/Emoji/Sound.hs index ce6c6fa3..c7a71327 100644 --- a/src/Data/Char/Emoji/Sound.hs +++ b/src/Data/Char/Emoji/Sound.hs @@ -73,7 +73,7 @@ instance UnicodeCharacter Bell where toUnicodeChar NoBell = '\x1f515' toUnicodeChar Bell = '\x1f514' fromUnicodeChar' '\x1f515' = NoBell - fromUnicodeChar' '\x1f514' = Bell + fromUnicodeChar' _ = Bell fromUnicodeChar '\x1f515' = Just NoBell fromUnicodeChar '\x1f514' = Just Bell fromUnicodeChar _ = Nothing @@ -102,7 +102,7 @@ instance UnicodeCharacter Instrument where toUnicodeChar PostalHorn = '\x1f4ef' fromUnicodeChar' '\x1f4e2' = Loudspeaker fromUnicodeChar' '\x1f4e3' = Megaphone - fromUnicodeChar' '\x1f4ef' = PostalHorn + fromUnicodeChar' _ = PostalHorn fromUnicodeChar '\x1f4e2' = Just Loudspeaker fromUnicodeChar '\x1f4e3' = Just Megaphone fromUnicodeChar '\x1f4ef' = Just PostalHorn From a018e64fa3fd8a5f9cac68e1fc14dc4799e996c8 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Thu, 26 Aug 2021 14:16:49 +0200 Subject: [PATCH 5/6] fix type applications syntax --- test/Data/Char/Emoji/ClockSpec.hs | 8 ++++---- test/Data/Char/Emoji/HandSpec.hs | 10 +++++----- test/Data/Char/Emoji/ScienceSpec.hs | 4 ++-- test/Data/Char/Emoji/SkinColorSpec.hs | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/Data/Char/Emoji/ClockSpec.hs b/test/Data/Char/Emoji/ClockSpec.hs index a9df445f..5a953e03 100644 --- a/test/Data/Char/Emoji/ClockSpec.hs +++ b/test/Data/Char/Emoji/ClockSpec.hs @@ -10,7 +10,7 @@ import Test.Hspec spec :: Spec spec = do - testBounded @ Clock - testUnicodeCharacter @ Clock - testUnicodeText @ Clock - testHashable @ Clock + testBounded @Clock + testUnicodeCharacter @Clock + testUnicodeText @Clock + testHashable @Clock diff --git a/test/Data/Char/Emoji/HandSpec.hs b/test/Data/Char/Emoji/HandSpec.hs index fb68b4c2..a45a31b6 100644 --- a/test/Data/Char/Emoji/HandSpec.hs +++ b/test/Data/Char/Emoji/HandSpec.hs @@ -10,11 +10,11 @@ import Test.Hspec spec :: Spec spec = do - testUnicodeCharacter @ SingleCharHandGesture - testUnicodeText @ SingleCharHandGesture - testHashable @ SingleCharHandGesture + testUnicodeCharacter @SingleCharHandGesture + testUnicodeText @SingleCharHandGesture + testHashable @SingleCharHandGesture -- testUnicodeCharacter @ MoonFace -- testUnicodeText @ MoonFace -- testHashable @ MoonFace - testUnicodeText @ MultiCharHandGesture - testHashable @ MultiCharHandGesture + testUnicodeText @MultiCharHandGesture + testHashable @MultiCharHandGesture diff --git a/test/Data/Char/Emoji/ScienceSpec.hs b/test/Data/Char/Emoji/ScienceSpec.hs index a63950b9..29e1bddb 100644 --- a/test/Data/Char/Emoji/ScienceSpec.hs +++ b/test/Data/Char/Emoji/ScienceSpec.hs @@ -10,5 +10,5 @@ import Test.Hspec spec :: Spec spec = do - testUnicodeText @ ScienceEmoji - testHashable @ ScienceEmoji + testUnicodeText @ScienceEmoji + testHashable @ScienceEmoji diff --git a/test/Data/Char/Emoji/SkinColorSpec.hs b/test/Data/Char/Emoji/SkinColorSpec.hs index b851d674..db5673cb 100644 --- a/test/Data/Char/Emoji/SkinColorSpec.hs +++ b/test/Data/Char/Emoji/SkinColorSpec.hs @@ -10,7 +10,7 @@ import Test.Hspec spec :: Spec spec = do - testUnicodeCharacter @ SkinColorModifier - testUnicodeText @ SkinColorModifier + testUnicodeCharacter @SkinColorModifier + testUnicodeText @SkinColorModifier testUnicodeCharText @SkinColorModifier - testHashable @ SkinColorModifier + testHashable @SkinColorModifier From 06c538b6b402d486a263940e019935e2c2b396f6 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem <3482343+KommuSoft@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:06:11 +0100 Subject: [PATCH 6/6] comment out moonface emoji --- test/Data/Char/Emoji/HandSpec.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Data/Char/Emoji/HandSpec.hs b/test/Data/Char/Emoji/HandSpec.hs index 4556caa3..4dfda171 100644 --- a/test/Data/Char/Emoji/HandSpec.hs +++ b/test/Data/Char/Emoji/HandSpec.hs @@ -13,8 +13,8 @@ spec = do testUnicodeCharacter @SingleCharHandGesture testUnicodeText @SingleCharHandGesture testHashable @SingleCharHandGesture - testUnicodeCharacter @MoonFace - testUnicodeText @MoonFace - testHashable @MoonFace + -- testUnicodeCharacter @MoonFace + -- testUnicodeText @MoonFace + -- testHashable @MoonFace testUnicodeText @MultiCharHandGesture testHashable @MultiCharHandGesture