1 {-# LANGUAGE DataKinds #-} -- For using P.viewGrammar
2 {-# LANGUAGE FlexibleContexts #-} -- For using P.Grammar Char
3 {-# LANGUAGE Rank2Types #-}
4 {-# LANGUAGE TypeApplications #-}
6 {-# LANGUAGE TemplateHaskell #-}
7 {-# LANGUAGE Rank2Types #-}
8 {-# LANGUAGE ScopedTypeVariables #-}
9 {-# LANGUAGE UnboxedTuples #-}
10 {-# OPTIONS_GHC -Wno-missing-signatures #-}
11 {-# OPTIONS_GHC -Wno-unused-local-binds #-}
12 {-# OPTIONS_GHC -Wno-unused-matches #-}
13 module Golden.Parser where
15 import Control.Monad (Monad(..))
16 import Data.Either (Either(..))
17 import Data.Function (($))
18 import Data.Functor ((<$>))
20 import Data.Semigroup (Semigroup(..))
21 import Data.String (String, IsString(..))
22 import Data.Text (Text)
23 import Data.Text.IO (readFile)
24 import System.FilePath ((<.>), (</>), dropExtensions, takeBaseName)
25 import System.IO.Unsafe (unsafePerformIO)
27 import Test.Tasty.Golden
28 import Text.Show (Show(..))
29 import qualified Control.Exception as IO
30 import qualified Data.List as List
31 import qualified System.Directory as IO
32 import qualified System.IO.Error as IO
33 import qualified Language.Haskell.TH as TH
35 import qualified Symantic.Parser as P
40 goldens = testGroup "Parser" $
41 (\f -> List.zipWith f parsers [1::Int ..]) $ \p g ->
42 -- Collect the existing files: tests/Golden/Parser/G*.input.txt
43 let parserDir = getGoldenDir $ "Parser/G"<>show g in
45 ((parserDir </>) <$>) $
47 List.filter (List.isSuffixOf ".input.txt") $
50 (IO.listDirectory parserDir)
52 if IO.isDoesNotExistError exn
56 testGroup ("G"<>show g) $ (<$> inputs) $ \inp ->
57 goldenVsStringDiff (takeBaseName (dropExtensions inp)) goldenDiff
58 (dropExtensions inp<.>"expected.txt") $ do
65 parsers :: [Text -> Either (P.ParsingError Text) String]
67 [ p1, p2, p3, p4, p5, p6, p7, p8, p9
68 , p10, p11, p12, p13, p14, p15, p16, p17, p18, p19
72 p1 = $$(TH.Code $ TH.runIO s1)
73 p2 = $$(TH.Code $ TH.runIO s2)
74 p3 = $$(TH.Code $ TH.runIO s3)
75 p4 = $$(TH.Code $ TH.runIO s4)
76 p5 = $$(TH.Code $ TH.runIO s5)
77 p6 = $$(TH.Code $ TH.runIO s6)
78 p7 = $$(TH.Code $ TH.runIO s7)
79 p8 = $$(TH.Code $ TH.runIO s8)
80 p9 = $$(TH.Code $ TH.runIO s9)
81 p10 = $$(TH.Code $ TH.runIO s10)
82 p11 = $$(TH.Code $ TH.runIO s11)
83 p12 = $$(TH.Code $ TH.runIO s12)
84 p13 = $$(TH.Code $ TH.runIO s13)
85 p14 = $$(TH.Code $ TH.runIO s14)
86 p15 = $$(TH.Code $ TH.runIO s15)
87 p16 = $$(TH.Code $ TH.runIO s16)
88 p17 = $$(TH.Code $ TH.runIO s17)
89 p18 = $$(TH.Code $ TH.runIO s18)
90 p19 = $$(TH.Code $ TH.runIO s19)
91 p20 = $$(TH.Code $ TH.runIO s20)