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

Make Lift Text work under RebindableSyntax #534

Merged
merged 1 commit into from
Jul 28, 2023
Merged
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
6 changes: 4 additions & 2 deletions src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ instance TH.Lift Text where
#if MIN_VERSION_template_haskell(2,16,0)
lift txt = do
let (ptr, len) = unsafePerformIO $ asForeignPtr txt
let lenInt = P.fromIntegral len
TH.appE (TH.appE (TH.varE 'unpackCStringLen#) (TH.litE . TH.bytesPrimL $ TH.mkBytes ptr 0 lenInt)) (TH.lift lenInt)
bytesQ = TH.litE . TH.bytesPrimL $ TH.mkBytes ptr 0 (P.fromIntegral len)
lenQ = liftInt (P.fromIntegral len)
liftInt n = (TH.appE (TH.conE 'Exts.I#) (TH.litE (TH.IntPrimL n)))
TH.varE 'unpackCStringLen# `TH.appE` bytesQ `TH.appE` lenQ
#else
lift = TH.appE (TH.varE 'pack) . TH.stringE . unpack
#endif
Expand Down
2 changes: 2 additions & 0 deletions tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import Test.Tasty (defaultMain, testGroup)
import qualified Tests.Lift as Lift
import qualified Tests.Properties as Properties
import qualified Tests.Regressions as Regressions
import qualified Tests.RebindableSyntaxTest as RST

main :: IO ()
main = defaultMain $ testGroup "All"
[ Lift.tests
, Properties.tests
, Regressions.tests
, RST.tests
]
14 changes: 14 additions & 0 deletions tests/Tests/RebindableSyntaxTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{-# LANGUAGE RebindableSyntax, TemplateHaskell #-}

module Tests.RebindableSyntaxTest where

import qualified Data.Text as Text
import Language.Haskell.TH.Syntax (lift)
import Test.Tasty.HUnit (testCase, assertEqual)
import Test.Tasty (TestTree, testGroup)
import Prelude (($))

tests :: TestTree
tests = testGroup "RebindableSyntax"
[ testCase "test" $ assertEqual "a" $(lift (Text.pack "a")) (Text.pack "a")
]
1 change: 1 addition & 0 deletions text.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ test-suite tests
Tests.Properties.Text
Tests.Properties.Transcoding
Tests.QuickCheckUtils
Tests.RebindableSyntaxTest
Tests.Regressions
Tests.SlowFunctions
Tests.Utils
Expand Down
Loading