|
1 | 1 | {-# LANGUAGE OverloadedLists #-} |
2 | 2 | {-# LANGUAGE OverloadedStrings #-} |
| 3 | +{-# LANGUAGE TypeData #-} |
| 4 | +{-# LANGUAGE TypeFamilies #-} |
3 | 5 |
|
4 | 6 | {- HLINT ignore "Redundant bracket" -} |
5 | 7 |
|
6 | 8 | module Test.Codec.CBOR.Cuddle.Huddle where |
7 | 9 |
|
8 | 10 | import Codec.CBOR.Cuddle.CDDL (CDDL, fromRules, sortCDDL) |
| 11 | +import Codec.CBOR.Cuddle.Comments (Comment) |
9 | 12 | import Codec.CBOR.Cuddle.Huddle |
10 | 13 | import Codec.CBOR.Cuddle.IndexMappable (IndexMappable (..)) |
11 | 14 | import Codec.CBOR.Cuddle.Parser |
12 | 15 | import Data.Text qualified as T |
| 16 | +import Data.Void (Void) |
| 17 | +import GHC.Generics (Generic) |
13 | 18 | import Test.Codec.CBOR.Cuddle.CDDL.Pretty qualified as Pretty |
14 | 19 | import Test.Hspec |
15 | 20 | import Test.Hspec.Megaparsec |
16 | 21 | import Text.Megaparsec |
17 | 22 | import Prelude hiding ((/)) |
18 | 23 |
|
| 24 | +type data TestStage |
| 25 | + |
| 26 | +newtype instance XCddl TestStage = TestXCddl [Comment] |
| 27 | + deriving (Generic, Show, Eq) |
| 28 | + |
| 29 | +instance IndexMappable XCddl ParserStage TestStage where |
| 30 | + mapIndex (ParserXCddl x) = TestXCddl x |
| 31 | + |
| 32 | +instance IndexMappable XCddl HuddleStage TestStage where |
| 33 | + mapIndex (HuddleXCddl x) = TestXCddl x |
| 34 | + |
| 35 | +newtype instance XTerm TestStage = TestXTerm Comment |
| 36 | + deriving (Generic, Show, Eq) |
| 37 | + |
| 38 | +instance IndexMappable XTerm ParserStage TestStage where |
| 39 | + mapIndex (ParserXTerm x) = TestXTerm x |
| 40 | + |
| 41 | +instance IndexMappable XTerm HuddleStage TestStage where |
| 42 | + mapIndex (HuddleXTerm x) = TestXTerm x |
| 43 | + |
| 44 | +newtype instance XRule TestStage = TestXRule Comment |
| 45 | + deriving (Generic, Show, Eq) |
| 46 | + |
| 47 | +instance IndexMappable XRule ParserStage TestStage where |
| 48 | + mapIndex (ParserXRule x) = TestXRule x |
| 49 | + |
| 50 | +instance IndexMappable XRule HuddleStage TestStage where |
| 51 | + mapIndex (HuddleXRule x _) = TestXRule x |
| 52 | + |
| 53 | +newtype instance XXTopLevel TestStage = TestXXTopLevel Comment |
| 54 | + deriving (Generic, Show, Eq) |
| 55 | + |
| 56 | +instance IndexMappable XXTopLevel ParserStage TestStage where |
| 57 | + mapIndex (ParserXXTopLevel x) = TestXXTopLevel x |
| 58 | + |
| 59 | +instance IndexMappable XXTopLevel HuddleStage TestStage where |
| 60 | + mapIndex (HuddleXXTopLevel x) = TestXXTopLevel x |
| 61 | + |
| 62 | +newtype instance XXType2 TestStage = TestXXType2 Void |
| 63 | + deriving (Generic, Show, Eq) |
| 64 | + |
| 65 | +instance IndexMappable XXType2 ParserStage TestStage where |
| 66 | + mapIndex (ParserXXType2 x) = TestXXType2 x |
| 67 | + |
| 68 | +instance IndexMappable XXType2 HuddleStage TestStage where |
| 69 | + mapIndex (HuddleXXType2 x) = TestXXType2 x |
| 70 | + |
19 | 71 | huddleSpec :: Spec |
20 | 72 | huddleSpec = describe "huddle" $ do |
21 | 73 | basicAssign |
@@ -156,10 +208,10 @@ shouldMatchParse :: |
156 | 208 | shouldMatchParse x parseFun input = parse parseFun "" (T.pack input) `shouldParse` x |
157 | 209 |
|
158 | 210 | shouldMatchParseCDDL :: |
159 | | - CDDL HuddleStage -> |
| 211 | + CDDL TestStage -> |
160 | 212 | String -> |
161 | 213 | Expectation |
162 | 214 | shouldMatchParseCDDL x = shouldMatchParse x . fmap mapIndex $ pCDDL |
163 | 215 |
|
164 | | -toSortedCDDL :: Huddle -> CDDL HuddleStage |
165 | | -toSortedCDDL = fromRules . sortCDDL . toCDDLNoRoot |
| 216 | +toSortedCDDL :: Huddle -> CDDL TestStage |
| 217 | +toSortedCDDL = mapIndex . fromRules . sortCDDL . toCDDLNoRoot |
0 commit comments