@@ -2,68 +2,43 @@ module Test.Main where
2
2
3
3
import Prelude
4
4
5
- import Control.Monad.Eff.Console (log )
6
-
7
- import Data.Argonaut (Json , decodeJson , encodeJson , fromString , (.?))
8
- import Data.Argonaut.JCursor (JCursor (..), toPrims , fromPrims )
5
+ import Data.Argonaut (Json , decodeJson , encodeJson , stringify )
9
6
import Data.Argonaut.Gen (genJson )
7
+ import Data.Argonaut.JCursor (JCursor (..), toPrims , fromPrims )
10
8
import Data.Either (Either (..))
9
+ import Data.Foldable (foldMap )
11
10
import Data.Maybe (Maybe (..))
12
- import Data.StrMap as M
13
-
14
- import Test.StrongCheck (SC , Result , assert , quickCheck' , (<?>))
15
- import Test.StrongCheck.Arbitrary (class Arbitrary , arbitrary )
16
- import Test.StrongCheck.Gen (chooseInt , resize )
17
-
18
- newtype TestJson = TestJson Json
19
-
20
- instance arbitraryJson :: Arbitrary TestJson where
21
- arbitrary = TestJson <$> (resize 5 genJson)
22
-
23
- prop_encode_then_decode :: TestJson -> Boolean
24
- prop_encode_then_decode (TestJson json) =
25
- Right json == (decodeJson $ encodeJson $ json)
26
-
27
- prop_decode_then_encode :: TestJson -> Boolean
28
- prop_decode_then_encode (TestJson json) =
29
- let decoded = (decodeJson json) :: Either String Json in
30
- Right json == (decoded >>= (encodeJson >>> pure))
31
-
32
- prop_toPrims_fromPrims :: TestJson -> Result
33
- prop_toPrims_fromPrims (TestJson j) =
34
- Just j == fromPrims (toPrims j) <?> " fromPrims.toPrims: " <> show (toPrims j) <> " \n\n " <> show (fromPrims (toPrims j))
35
-
36
- newtype TestJCursor = TestJCursor JCursor
37
-
38
- runTestJCursor :: TestJCursor -> JCursor
39
- runTestJCursor (TestJCursor j) = j
40
-
41
- instance arbJCursor :: Arbitrary TestJCursor where
42
- arbitrary = do
11
+ import Data.String.Gen (genUnicodeString )
12
+ import Effect (Effect )
13
+ import Effect.Console (log )
14
+ import Test.QuickCheck (Result , quickCheck , (<?>))
15
+ import Test.QuickCheck.Gen (Gen , chooseInt , resize )
16
+
17
+ genTestJson :: Gen Json
18
+ genTestJson = resize 5 genJson
19
+
20
+ prop_toPrims_fromPrims :: Gen Result
21
+ prop_toPrims_fromPrims = do
22
+ j <- genTestJson
23
+ pure $ Just j == fromPrims (toPrims j) <?> " fromPrims.toPrims: " <> show (toPrims j) <> " \n\n " <> foldMap stringify (fromPrims (toPrims j))
24
+
25
+ genTestJCursor :: Gen JCursor
26
+ genTestJCursor = do
43
27
i <- chooseInt 0 2
44
28
r <- if i == 0 then pure JCursorTop
45
- else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary)
46
- else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary)
47
- pure $ TestJCursor r
29
+ else if i == 1 then JField <$> genUnicodeString <*> genTestJCursor
30
+ else JIndex <$> chooseInt bottom top <*> genTestJCursor
31
+ pure r
48
32
49
- prop_jcursor_serialization :: TestJCursor -> Result
50
- prop_jcursor_serialization (TestJCursor c) =
51
- (decodeJson (encodeJson c) == Right c) <?> " JCursor: " <> show c
33
+ prop_jcursor_serialization :: Gen Result
34
+ prop_jcursor_serialization = do
35
+ c <- genTestJCursor
36
+ pure $ (decodeJson (encodeJson c) == Right c) <?> " JCursor: " <> show c
52
37
53
- main :: SC () Unit
38
+ main :: Effect Unit
54
39
main = do
55
- log " Testing that any JSON can be encoded and then decoded"
56
- quickCheck' 20 prop_encode_then_decode
57
-
58
- log " Testing that any JSON can be decoded and then encoded"
59
- quickCheck' 20 prop_decode_then_encode
60
-
61
40
log " Testing that toPrims / fromPrims inverses"
62
- quickCheck' 20 prop_toPrims_fromPrims
41
+ quickCheck prop_toPrims_fromPrims
63
42
64
43
log " Testing that JCursor can be encoded / decoded from JSON"
65
- quickCheck' 20 prop_jcursor_serialization
66
-
67
- log " Testing .? combinator"
68
- assert $ let bar = fromString " bar"
69
- in (M .singleton " foo" bar) .? " foo" == Right bar
44
+ quickCheck prop_jcursor_serialization
0 commit comments