From 6aa54d64b57186e9a2cb43ab5e2288d9f17b2164 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:06:29 +0200 Subject: [PATCH] Extend TemplateHaskell test --- test/Spec/TemplateHaskell/TH.hs | 8 +++++++- test/Spec/TemplateHaskell/User.hs | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/Spec/TemplateHaskell/TH.hs b/test/Spec/TemplateHaskell/TH.hs index 3c8a19c..7555a40 100644 --- a/test/Spec/TemplateHaskell/TH.hs +++ b/test/Spec/TemplateHaskell/TH.hs @@ -1,4 +1,4 @@ -module Spec.TemplateHaskell.TH (intQQ, oneQ) where +module Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two) where import Language.Haskell.TH import Language.Haskell.TH.Quote @@ -9,6 +9,12 @@ oneQ = pure . LitE $ IntegerL one one :: Integer one = 1 +two :: Int +two = 2 + +twoQ :: Q Exp +twoQ = pure . VarE $ mkName "two" + intQQ :: QuasiQuoter intQQ = QuasiQuoter { quoteExp = pure . LitE . IntegerL . (zero1 +) . read diff --git a/test/Spec/TemplateHaskell/User.hs b/test/Spec/TemplateHaskell/User.hs index fb931a9..0126298 100644 --- a/test/Spec/TemplateHaskell/User.hs +++ b/test/Spec/TemplateHaskell/User.hs @@ -5,13 +5,13 @@ module Spec.TemplateHaskell.User where -import Spec.TemplateHaskell.TH (intQQ, oneQ) +import Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two) import GHC.TypeLits (Nat) newtype T (a :: Nat) = T Int root :: T [intQQ|1|] -root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) +root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) + $(twoQ) where f [intQQ|1|] = 1 f _ = 1