diff --git a/Data/CaseInsensitive/Internal.hs b/Data/CaseInsensitive/Internal.hs index cfe1291..1295577 100644 --- a/Data/CaseInsensitive/Internal.hs +++ b/Data/CaseInsensitive/Internal.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP, DeriveDataTypeable #-} +{-# LANGUAGE CPP, DeriveDataTypeable, TemplateHaskell #-} #if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE Unsafe #-} @@ -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 @@ -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 -------------------------------------------------------------------------------- diff --git a/case-insensitive.cabal b/case-insensitive.cabal index 3746959..6493f69 100644 --- a/case-insensitive.cabal +++ b/case-insensitive.cabal @@ -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 @@ -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 diff --git a/test/test.hs b/test/test.hs index 3a6cf30..14507b9 100644 --- a/test/test.hs +++ b/test/test.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TemplateHaskell #-} module Main ( main ) where import Data.ByteString ( ByteString ) @@ -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 @@ -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") + ] ]