From a43ecc61a3082fa33621f39707e5ea9fcfd58283 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:55:27 +0100 Subject: [PATCH 1/7] Add TemplateHaskell test --- test/Spec/TemplateHaskell.stdout | 0 test/Spec/TemplateHaskell.toml | 7 +++++++ test/Spec/TemplateHaskell/TH.hs | 30 ++++++++++++++++++++++++++++++ test/Spec/TemplateHaskell/User.hs | 19 +++++++++++++++++++ weeder.cabal | 3 +++ 5 files changed, 59 insertions(+) create mode 100644 test/Spec/TemplateHaskell.stdout create mode 100644 test/Spec/TemplateHaskell.toml create mode 100644 test/Spec/TemplateHaskell/TH.hs create mode 100644 test/Spec/TemplateHaskell/User.hs diff --git a/test/Spec/TemplateHaskell.stdout b/test/Spec/TemplateHaskell.stdout new file mode 100644 index 0000000..e69de29 diff --git a/test/Spec/TemplateHaskell.toml b/test/Spec/TemplateHaskell.toml new file mode 100644 index 0000000..cd8cbd1 --- /dev/null +++ b/test/Spec/TemplateHaskell.toml @@ -0,0 +1,7 @@ +roots = [ "Spec.TemplateHaskell.User.root" ] + +type-class-roots = false + +unused-types = false + +root-instances = [] diff --git a/test/Spec/TemplateHaskell/TH.hs b/test/Spec/TemplateHaskell/TH.hs new file mode 100644 index 0000000..3c8a19c --- /dev/null +++ b/test/Spec/TemplateHaskell/TH.hs @@ -0,0 +1,30 @@ +module Spec.TemplateHaskell.TH (intQQ, oneQ) where + +import Language.Haskell.TH +import Language.Haskell.TH.Quote + +oneQ :: Q Exp +oneQ = pure . LitE $ IntegerL one + +one :: Integer +one = 1 + +intQQ :: QuasiQuoter +intQQ = QuasiQuoter + { quoteExp = pure . LitE . IntegerL . (zero1 +) . read + , quotePat = pure . LitP . IntegerL . (zero2 +) . read + , quoteType = pure . LitT . NumTyLit . (zero3 +) . read + , quoteDec = pure . pure . (\i -> ValD (VarP $ mkName "quote") (NormalB $ LitE $ IntegerL i) []) . (zero4 +) . read + } + +zero1 :: Integer +zero1 = 0 + +zero2 :: Integer +zero2 = 0 + +zero3 :: Integer +zero3 = 0 + +zero4 :: Integer +zero4 = 0 diff --git a/test/Spec/TemplateHaskell/User.hs b/test/Spec/TemplateHaskell/User.hs new file mode 100644 index 0000000..e9c781b --- /dev/null +++ b/test/Spec/TemplateHaskell/User.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE DataKinds #-} + +module Spec.TemplateHaskell.User where + +import Spec.TemplateHaskell.TH (intQQ, oneQ) +import GHC.TypeLits (Nat) + +newtype T (a :: Nat) = T Int + +root :: T [intQQ|1|] +root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) + where + f [intQQ|1|] = 1 + f _ = 1 + +quote :: Int +[intQQ|2|] diff --git a/weeder.cabal b/weeder.cabal index 3dbaee2..47f48d0 100644 --- a/weeder.cabal +++ b/weeder.cabal @@ -76,6 +76,7 @@ test-suite weeder-test , tasty , tasty-hunit-compat , tasty-golden + , template-haskell , text , toml-reader , weeder @@ -107,6 +108,8 @@ test-suite weeder-test Spec.RangeEnum.RangeEnum Spec.RootClasses.RootClasses Spec.StandaloneDeriving.StandaloneDeriving + Spec.TemplateHaskell.TH + Spec.TemplateHaskell.User Spec.TypeAliasGADT.TypeAliasGADT Spec.TypeDataDecl.TypeDataDecl Spec.Types.Types From 3fc3f7a1d1bdbdd5650f69f195b9052e9cb7f355 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Thu, 11 Apr 2024 23:37:57 +0100 Subject: [PATCH 2/7] Add .failing for TemplateHaskell test --- test/Spec/TemplateHaskell.failing | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/Spec/TemplateHaskell.failing diff --git a/test/Spec/TemplateHaskell.failing b/test/Spec/TemplateHaskell.failing new file mode 100644 index 0000000..57b256d --- /dev/null +++ b/test/Spec/TemplateHaskell.failing @@ -0,0 +1,7 @@ +test/Spec/TemplateHaskell/TH.hs:7: oneQ +test/Spec/TemplateHaskell/TH.hs:10: one +test/Spec/TemplateHaskell/TH.hs:13: intQQ +test/Spec/TemplateHaskell/TH.hs:21: zero1 +test/Spec/TemplateHaskell/TH.hs:24: zero2 +test/Spec/TemplateHaskell/TH.hs:27: zero3 +test/Spec/TemplateHaskell/TH.hs:30: zero4 From 057799f05452489edd8c93f440c729e7979c0473 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:52:30 +0200 Subject: [PATCH 3/7] Add KindSignatures to TemplateHaskell test --- test/Spec/TemplateHaskell/User.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Spec/TemplateHaskell/User.hs b/test/Spec/TemplateHaskell/User.hs index e9c781b..fb931a9 100644 --- a/test/Spec/TemplateHaskell/User.hs +++ b/test/Spec/TemplateHaskell/User.hs @@ -1,6 +1,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE KindSignatures #-} module Spec.TemplateHaskell.User where From 0a5be87c88419837c642840ccff35b440b6d2027 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:55:38 +0200 Subject: [PATCH 4/7] Update TemplateHaskell.failing --- test/Spec/TemplateHaskell.failing | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Spec/TemplateHaskell.failing b/test/Spec/TemplateHaskell.failing index 57b256d..0a64457 100644 --- a/test/Spec/TemplateHaskell.failing +++ b/test/Spec/TemplateHaskell.failing @@ -1,7 +1,7 @@ -test/Spec/TemplateHaskell/TH.hs:7: oneQ -test/Spec/TemplateHaskell/TH.hs:10: one -test/Spec/TemplateHaskell/TH.hs:13: intQQ -test/Spec/TemplateHaskell/TH.hs:21: zero1 -test/Spec/TemplateHaskell/TH.hs:24: zero2 -test/Spec/TemplateHaskell/TH.hs:27: zero3 -test/Spec/TemplateHaskell/TH.hs:30: zero4 +main: test/Spec/TemplateHaskell/TH.hs:7:1: oneQ +main: test/Spec/TemplateHaskell/TH.hs:10:1: one +main: test/Spec/TemplateHaskell/TH.hs:13:1: intQQ +main: test/Spec/TemplateHaskell/TH.hs:21:1: zero1 +main: test/Spec/TemplateHaskell/TH.hs:24:1: zero2 +main: test/Spec/TemplateHaskell/TH.hs:27:1: zero3 +main: test/Spec/TemplateHaskell/TH.hs:30:1: zero4 From b8006fe0c8db22ef095e0980ff8323cd5ca7a66e Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:01:10 +0200 Subject: [PATCH 5/7] Amend TemplateHaskell test for GHC98 --- test/Spec/TemplateHaskell.failing | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Spec/TemplateHaskell.failing b/test/Spec/TemplateHaskell.failing index 0a64457..fa31cd8 100644 --- a/test/Spec/TemplateHaskell.failing +++ b/test/Spec/TemplateHaskell.failing @@ -1,5 +1,3 @@ -main: test/Spec/TemplateHaskell/TH.hs:7:1: oneQ -main: test/Spec/TemplateHaskell/TH.hs:10:1: one main: test/Spec/TemplateHaskell/TH.hs:13:1: intQQ main: test/Spec/TemplateHaskell/TH.hs:21:1: zero1 main: test/Spec/TemplateHaskell/TH.hs:24:1: zero2 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 6/7] 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 From 27ff3674a563be501570657d0f776b60229032a4 Mon Sep 17 00:00:00 2001 From: ryndubei <114586905+ryndubei@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:13:46 +0200 Subject: [PATCH 7/7] Extend TemplateHaskell test further --- test/Spec/TemplateHaskell.failing | 11 ++++++----- test/Spec/TemplateHaskell/TH.hs | 8 +++++++- test/Spec/TemplateHaskell/User.hs | 6 ++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/test/Spec/TemplateHaskell.failing b/test/Spec/TemplateHaskell.failing index fa31cd8..b6f2fdd 100644 --- a/test/Spec/TemplateHaskell.failing +++ b/test/Spec/TemplateHaskell.failing @@ -1,5 +1,6 @@ -main: test/Spec/TemplateHaskell/TH.hs:13:1: intQQ -main: test/Spec/TemplateHaskell/TH.hs:21:1: zero1 -main: test/Spec/TemplateHaskell/TH.hs:24:1: zero2 -main: test/Spec/TemplateHaskell/TH.hs:27:1: zero3 -main: test/Spec/TemplateHaskell/TH.hs:30:1: zero4 +main: test/Spec/TemplateHaskell/TH.hs:22:1: threeQ +main: test/Spec/TemplateHaskell/TH.hs:25:1: intQQ +main: test/Spec/TemplateHaskell/TH.hs:33:1: zero1 +main: test/Spec/TemplateHaskell/TH.hs:36:1: zero2 +main: test/Spec/TemplateHaskell/TH.hs:39:1: zero3 +main: test/Spec/TemplateHaskell/TH.hs:42:1: zero4 diff --git a/test/Spec/TemplateHaskell/TH.hs b/test/Spec/TemplateHaskell/TH.hs index 7555a40..86dedad 100644 --- a/test/Spec/TemplateHaskell/TH.hs +++ b/test/Spec/TemplateHaskell/TH.hs @@ -1,4 +1,4 @@ -module Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two) where +module Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two, three, threeQ) where import Language.Haskell.TH import Language.Haskell.TH.Quote @@ -15,6 +15,12 @@ two = 2 twoQ :: Q Exp twoQ = pure . VarE $ mkName "two" +three :: Int +three = 3 + +threeQ :: Q [Dec] +threeQ = pure [ValD (VarP $ mkName "three'") (NormalB . VarE $ mkName "three") []] + 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 0126298..81e1c55 100644 --- a/test/Spec/TemplateHaskell/User.hs +++ b/test/Spec/TemplateHaskell/User.hs @@ -5,13 +5,15 @@ module Spec.TemplateHaskell.User where -import Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two) +import Spec.TemplateHaskell.TH import GHC.TypeLits (Nat) +$(threeQ) + newtype T (a :: Nat) = T Int root :: T [intQQ|1|] -root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) + $(twoQ) +root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) + $(twoQ) + three' where f [intQQ|1|] = 1 f _ = 1