Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lift instance #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Data/CaseInsensitive/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP, DeriveDataTypeable #-}
{-# LANGUAGE CPP, DeriveDataTypeable, TemplateHaskell #-}

#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Unsafe #-}
Expand Down Expand Up @@ -68,6 +68,9 @@ import Control.DeepSeq ( NFData, rnf, deepseq )
-- from hashable:
import Data.Hashable ( Hashable, hashWithSalt )

-- from template-haskell:
import Language.Haskell.TH ( appE, varE )
import Language.Haskell.TH.Syntax ( Lift(lift) )

--------------------------------------------------------------------------------
-- Case Insensitive Strings
Expand Down Expand Up @@ -141,6 +144,9 @@ instance Hashable s => Hashable (CI s) where
instance NFData s => NFData (CI s) where
rnf (CI o f) = o `deepseq` f `deepseq` ()

instance Lift s => Lift (CI s) where
lift = appE (varE 'mk) . lift . original

--------------------------------------------------------------------------------
-- Folding (lowering) cases
--------------------------------------------------------------------------------
Expand Down
12 changes: 7 additions & 5 deletions case-insensitive.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ source-repository head

Library
ghc-options: -Wall
build-depends: base >= 3 && < 5
, bytestring >= 0.9
, text >= 0.3
, deepseq >= 1.1
, hashable >= 1.0
build-depends: base >= 3 && < 5
, bytestring >= 0.9
, text >= 0.3
, deepseq >= 1.1
, hashable >= 1.0
, template-haskell >= 2.2
if !impl(ghc >= 8.0)
build-depends: semigroups >= 0.18
exposed-modules: Data.CaseInsensitive, Data.CaseInsensitive.Unsafe
Expand All @@ -55,6 +56,7 @@ test-suite test-case-insensitive
, HUnit >= 1.2.2
, test-framework >= 0.2.4
, test-framework-hunit >= 0.2.4
, template-haskell >= 2.2

ghc-options: -Wall

Expand Down
6 changes: 6 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
module Main ( main ) where

import Data.ByteString ( ByteString )
Expand All @@ -13,6 +14,7 @@ import qualified Data.Text.Lazy as TL ( pack, toUpper )
import Test.Framework ( defaultMain, testGroup )
import Test.Framework.Providers.HUnit ( testCase )
import Test.HUnit ( assertEqual )
import Language.Haskell.TH.Syntax ( lift )

main :: IO ()
main = defaultMain
Expand Down Expand Up @@ -40,6 +42,10 @@ main = defaultMain
, testCase "Lazy.Text" $ assertEqual "" (CI.mk iso_8859_1LTxt)
(CI.mk ( TL.toUpper iso_8859_1LTxt))
]
, testGroup "Lift Instance"
[ testCase "String" $ assertEqual "" $(lift $ CI.mk "aBc")
(CI.mk "abc")
]
]


Expand Down