Commit 01d525a8 authored by reinerp's avatar reinerp

Add tests for view patterns in template haskell (Trac #2399)

parent b2750260
{-# 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)|] }
{-# 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
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', '' ])
{-# LANGUAGE ViewPatterns, QuasiQuotes #-}
module Main where
import Language.Haskell.TH
main = do
p <- runQ [p|(id -> x)|]
print p
putStrLn (pprint p)
ViewP (VarE GHC.Base.id) (VarP x)
(GHC.Base.id -> x)
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment