summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/th
diff options
context:
space:
mode:
authorReiner Pope <reiner.pope@gmail.com>2010-10-10 12:09:43 +0000
committerReiner Pope <reiner.pope@gmail.com>2010-10-10 12:09:43 +0000
commit01d525a8a9acab10ba0d4563e7b300f012db679e (patch)
tree360caa264d46fd16a3883c4d6bf8f29a25bdb18d /testsuite/tests/ghc-regress/th
parentb275026081e986f78812061a0d5a9730f4f4788f (diff)
downloadhaskell-01d525a8a9acab10ba0d4563e7b300f012db679e.tar.gz
Add tests for view patterns in template haskell (Trac #2399)
Diffstat (limited to 'testsuite/tests/ghc-regress/th')
-rw-r--r--testsuite/tests/ghc-regress/th/TH_spliceViewPat/A.hs11
-rw-r--r--testsuite/tests/ghc-regress/th/TH_spliceViewPat/Main.hs11
-rw-r--r--testsuite/tests/ghc-regress/th/TH_spliceViewPat/TH_spliceViewPat.stdout2
-rw-r--r--testsuite/tests/ghc-regress/th/TH_spliceViewPat/test.T11
-rw-r--r--testsuite/tests/ghc-regress/th/TH_viewPatPrint.hs10
-rw-r--r--testsuite/tests/ghc-regress/th/TH_viewPatPrint.stdout2
-rw-r--r--testsuite/tests/ghc-regress/th/all.T2
7 files changed, 49 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-regress/th/TH_spliceViewPat/A.hs b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/A.hs
new file mode 100644
index 0000000000..0147d2eca2
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/A.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE ViewPatterns #-}
+module A where
+
+import Language.Haskell.TH.Quote
+import Language.Haskell.TH
+
+foo :: QuasiQuoter
+foo = QuasiQuoter{quotePat = \s -> viewP [|(*2)|] (varP . mkName $ s)}
+
+bar :: QuasiQuoter
+bar = QuasiQuoter{quotePat = \_ -> [p|((*3) -> fixed_var)|] }
diff --git a/testsuite/tests/ghc-regress/th/TH_spliceViewPat/Main.hs b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/Main.hs
new file mode 100644
index 0000000000..675ae99bf9
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/Main.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE QuasiQuotes, ViewPatterns #-}
+
+module Main where
+
+import A
+
+main = do
+ case 1 of
+ [foo|x|] -> print x
+ case 1 of
+ [bar|<!anything~|] -> print fixed_var
diff --git a/testsuite/tests/ghc-regress/th/TH_spliceViewPat/TH_spliceViewPat.stdout b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/TH_spliceViewPat.stdout
new file mode 100644
index 0000000000..4792e70f33
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/TH_spliceViewPat.stdout
@@ -0,0 +1,2 @@
+2
+3
diff --git a/testsuite/tests/ghc-regress/th/TH_spliceViewPat/test.T b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/test.T
new file mode 100644
index 0000000000..fa50658a6b
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_spliceViewPat/test.T
@@ -0,0 +1,11 @@
+def f(opts):
+ opts.extra_hc_opts = '-XTemplateHaskell -package template-haskell'
+ if (ghc_with_interpreter == 0):
+ opts.skip = 1
+
+setTestOpts(f)
+setTestOpts(only_compiler_types(['ghc']))
+setTestOpts(only_ways(['normal','ghci']))
+setTestOpts(if_compiler_profiled(skip))
+
+test('TH_spliceViewPat', normal, multimod_compile_and_run, [ 'Main', '' ])
diff --git a/testsuite/tests/ghc-regress/th/TH_viewPatPrint.hs b/testsuite/tests/ghc-regress/th/TH_viewPatPrint.hs
new file mode 100644
index 0000000000..f0ef779691
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_viewPatPrint.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE ViewPatterns, QuasiQuotes #-}
+
+module Main where
+
+import Language.Haskell.TH
+
+main = do
+ p <- runQ [p|(id -> x)|]
+ print p
+ putStrLn (pprint p)
diff --git a/testsuite/tests/ghc-regress/th/TH_viewPatPrint.stdout b/testsuite/tests/ghc-regress/th/TH_viewPatPrint.stdout
new file mode 100644
index 0000000000..f520b23008
--- /dev/null
+++ b/testsuite/tests/ghc-regress/th/TH_viewPatPrint.stdout
@@ -0,0 +1,2 @@
+ViewP (VarE GHC.Base.id) (VarP x)
+(GHC.Base.id -> x)
diff --git a/testsuite/tests/ghc-regress/th/all.T b/testsuite/tests/ghc-regress/th/all.T
index c17629cfd2..6aefadbc73 100644
--- a/testsuite/tests/ghc-regress/th/all.T
+++ b/testsuite/tests/ghc-regress/th/all.T
@@ -175,3 +175,5 @@ test('T4188', normal, compile, ['-v0'])
test('T4233', normal, compile, ['-v0'])
test('T4169', normal, compile, ['-v0'])
test('T1835', normal, compile_and_run, ['-v0'])
+
+test('TH_viewPatPrint', normal, compile_and_run, ['']) \ No newline at end of file