@@ -8,14 +8,16 @@ import Data.Argonaut.Core (Json())
88import Data.Either
99import Data.Tuple
1010import Data.Maybe
11- import Data.Array
11+ import Data.Array
1212import Data.List (toList )
1313import Control.Monad.Eff.Console
1414import qualified Data.StrMap as M
1515
1616import Test.StrongCheck
1717import Test.StrongCheck.Gen
1818
19+ newtype TestJson = TestJson Json
20+
1921genJNull :: Gen Json
2022genJNull = pure jsonNull
2123
@@ -48,30 +50,38 @@ genJson n = frequency (Tuple 1.0 genJNull) rest where
4850 Tuple 1.0 (genJArray n),
4951 Tuple 1.0 (genJObject n)]
5052
51- instance arbitraryJson :: Arbitrary Json where
52- arbitrary = sized genJson
5353
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) =
5659 Right json == (decodeJson $ encodeJson $ json)
5760
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) =
6063 let decoded = (decodeJson json) :: Either String Json in
6164 Right json == (decoded >>= (encodeJson >>> pure))
6265
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
6571
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
7274
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) =
7585 (decodeJson (encodeJson c) == Right c) <?> " JCursor: " ++ show c
7686
7787main = do
@@ -91,6 +101,5 @@ main = do
91101 quickCheck' 20 prop_jcursor_serialization
92102
93103 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