@@ -8,14 +8,16 @@ import Data.Argonaut.Core (Json())
8
8
import Data.Either
9
9
import Data.Tuple
10
10
import Data.Maybe
11
- import Data.Array
11
+ import Data.Array
12
12
import Data.List (toList )
13
13
import Control.Monad.Eff.Console
14
14
import qualified Data.StrMap as M
15
15
16
16
import Test.StrongCheck
17
17
import Test.StrongCheck.Gen
18
18
19
+ newtype TestJson = TestJson Json
20
+
19
21
genJNull :: Gen Json
20
22
genJNull = pure jsonNull
21
23
@@ -48,30 +50,38 @@ genJson n = frequency (Tuple 1.0 genJNull) rest where
48
50
Tuple 1.0 (genJArray n),
49
51
Tuple 1.0 (genJObject n)]
50
52
51
- instance arbitraryJson :: Arbitrary Json where
52
- arbitrary = sized genJson
53
53
54
- prop_encode_then_decode :: Json -> Boolean
55
- prop_encode_then_decode json =
54
+ instance arbitraryJson :: Arbitrary TestJson where
55
+ arbitrary = TestJson <$> sized genJson
56
+
57
+ prop_encode_then_decode :: TestJson -> Boolean
58
+ prop_encode_then_decode (TestJson json) =
56
59
Right json == (decodeJson $ encodeJson $ json)
57
60
58
- prop_decode_then_encode :: Json -> Boolean
59
- prop_decode_then_encode json =
61
+ prop_decode_then_encode :: TestJson -> Boolean
62
+ prop_decode_then_encode ( TestJson json) =
60
63
let decoded = (decodeJson json) :: Either String Json in
61
64
Right json == (decoded >>= (encodeJson >>> pure))
62
65
63
- prop_toPrims_fromPrims :: Json -> Result
64
- prop_toPrims_fromPrims j = Just j == fromPrims (toPrims j) <?> " fromPrims.toPrims: " ++ show (toPrims j) ++ " \n\n " ++ show (fromPrims (toPrims j))
66
+ prop_toPrims_fromPrims :: TestJson -> Result
67
+ prop_toPrims_fromPrims (TestJson j) =
68
+ Just j == fromPrims (toPrims j) <?> " fromPrims.toPrims: " ++ show (toPrims j) ++ " \n\n " ++ show (fromPrims (toPrims j))
69
+
70
+ newtype TestJCursor = TestJCursor JCursor
65
71
66
- instance arbJCursor :: Arbitrary JCursor where
67
- arbitrary = do i <- chooseInt 0.0 2.0
68
- r <- if i == 0 then pure JCursorTop
69
- else if i == 1 then JField <$> arbitrary <*> arbitrary
70
- else JIndex <$> arbitrary <*> arbitrary
71
- return r
72
+ runTestJCursor :: TestJCursor -> JCursor
73
+ runTestJCursor (TestJCursor j) = j
72
74
73
- prop_jcursor_serialization :: JCursor -> Result
74
- prop_jcursor_serialization c =
75
+ instance arbJCursor :: Arbitrary TestJCursor where
76
+ arbitrary = do
77
+ i <- chooseInt 0.0 2.0
78
+ r <- if i == 0 then pure JCursorTop
79
+ else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary)
80
+ else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary)
81
+ return $ TestJCursor r
82
+
83
+ prop_jcursor_serialization :: TestJCursor -> Result
84
+ prop_jcursor_serialization (TestJCursor c) =
75
85
(decodeJson (encodeJson c) == Right c) <?> " JCursor: " ++ show c
76
86
77
87
main = do
@@ -91,6 +101,5 @@ main = do
91
101
quickCheck' 20 prop_jcursor_serialization
92
102
93
103
log " Testing .? combinator"
94
- assert $ let bar = fromString " bar"
95
- in (M .singleton " foo" bar) .? " foo" == Right bar
96
-
104
+ assert $ let bar = fromString " bar"
105
+ in (M .singleton " foo" bar) .? " foo" == Right bar
0 commit comments