-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHKD1.hs
122 lines (95 loc) · 3.03 KB
/
HKD1.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
module HKD1 (test) where
import Control.Monad (guard)
import Data.Aeson.Types (FromJSON (..), ToJSON (..))
import Data.Functor.Identity (Identity (..))
import GHC.Generics (Generic)
import System.OsString
import System.OsString.Aeson
import Utils
type Mapping = Mapping' Identity
data Mapping' f = Mapping
{ source :: f OsString
, destination :: f OsString
}
deriving (Generic)
deriving instance Eq Mapping
deriving instance Eq (Mapping' (As Binary))
deriving instance Eq (Mapping' (As (Textual Unicode)))
deriving instance Eq (Mapping' (As (Tagged Binary)))
deriving instance Eq (Mapping' (As (Tagged (Textual Unicode))))
instance FromJSON (Mapping' (As Binary))
instance ToJSON (Mapping' (As Binary))
instance FromJSON (Mapping' (As (Textual Unicode)))
instance ToJSON (Mapping' (As (Textual Unicode)))
instance FromJSON (Mapping' (As (Tagged Binary)))
instance ToJSON (Mapping' (As (Tagged Binary)))
instance FromJSON (Mapping' (As (Tagged (Textual Unicode))))
instance ToJSON (Mapping' (As (Tagged (Textual Unicode))))
deriving via (CoercibleRep (Mapping' (As (Textual Unicode))) Mapping) instance FromJSON Mapping
deriving via (CoercibleRep (Mapping' (As (Textual Unicode))) Mapping) instance ToJSON Mapping
example :: Mapping
example =
Mapping
{ source = Identity exampleSource
, destination = Identity exampleDestination
}
testBinary :: IO ()
testBinary = do
putStrLn "## Binary"
let
example' :: Mapping' (As Binary)
example' = coerceViaRep example
json = toJSON example'
printJSON json
mapping <- parseThrow parseJSON json
guard $ mapping == example'
testTextual :: IO ()
testTextual = do
putStrLn "## Textual"
let
example' :: Mapping' (As (Textual Unicode))
example' = coerceViaRep example
json = toJSON example'
printJSON json
mapping <- parseThrow parseJSON json
guard $ mapping == example'
testTaggedBinary :: IO ()
testTaggedBinary = do
putStrLn "## Tagged Binary"
let
example' :: Mapping' (As (Tagged Binary))
example' = coerceViaRep example
json = toJSON example'
printJSON json
mapping <- parseThrow parseJSON json
guard $ mapping == example'
testTaggedTextual :: IO ()
testTaggedTextual = do
putStrLn "## Tagged Textual"
let
example' :: Mapping' (As (Tagged (Textual Unicode)))
example' = coerceViaRep example
json = toJSON example'
printJSON json
mapping <- parseThrow parseJSON json
guard $ mapping == example'
testDerivedDefaultInstances :: IO ()
testDerivedDefaultInstances = do
putStrLn "## Derived default instances"
let
json = toJSON example
printJSON json
mapping <- parseThrow parseJSON json
guard $ mapping == example
test :: IO ()
test = do
putStrLn "# HKD 1"
testBinary
testTextual
testTaggedBinary
testTaggedTextual
testDerivedDefaultInstances