@@ -3,17 +3,15 @@ module Main where
4import Control.Arrow
4import Control.Arrow
5import Data.Aeson
5import Data.Aeson
6−import qualified Data.Aeson.Pointer as P
6+import qualified Data.Aeson.Pointer as P
7−import Data.Text (Text)
7+import Data.Text (Text)
8−import qualified Data.Text as T
8+import qualified Data.Text as T
9import Data.Text.Encoding
9import Data.Text.Encoding
10−import qualified Data.Vector as V
10+import qualified Data.Vector as V
11−import Network.HTTP.Types.URI (urlDecode)
11+import Network.HTTP.Types.URI (urlDecode)
13import Test.Hspec
13import Test.Hspec
14−import Test.QuickCheck (property)
14+import Test.QuickCheck (property)
16−import Test.HUnit hiding (Test)
18-- For GHCs before 7.10:
16-- For GHCs before 7.10:
19import Control.Applicative
17import Control.Applicative
@@ -34,7 +32,7 @@ main = hspec $ do
34roundtrip :: P.Pointer -> Bool
32roundtrip :: P.Pointer -> Bool
35roundtrip a = Just a == decode (encode a)
33roundtrip a = Just a == decode (encode a)
37−jsonString :: Assertion
35+jsonString :: Expectation
38jsonString = traverse_ resolvesTo
36jsonString = traverse_ resolvesTo
39 [ ("" , specExample)
37 [ ("" , specExample)
40 , ("/foo" , Array $ V.fromList ["bar", "baz"])
38 , ("/foo" , Array $ V.fromList ["bar", "baz"])
@@ -50,7 +48,7 @@ jsonString = traverse_ resolvesTo
50 , ("/m~0n" , Number 8)
48 , ("/m~0n" , Number 8)
53−uriFragment :: Assertion
51+uriFragment :: Expectation
54uriFragment = traverse_ resolvesTo . fmap (first decodeFragment) $
52uriFragment = traverse_ resolvesTo . fmap (first decodeFragment) $
55 [ ("#" , specExample)
53 [ ("#" , specExample)
56 , ("#/foo" , Array $ V.fromList ["bar", "baz"])
54 , ("#/foo" , Array $ V.fromList ["bar", "baz"])
@@ -69,14 +67,11 @@ uriFragment = traverse_ resolvesTo . fmap (first decodeFragment) $
69 decodeFragment :: Text -> Text
67 decodeFragment :: Text -> Text
70 decodeFragment = T.drop 1 . decodeUtf8 . urlDecode True . encodeUtf8
68 decodeFragment = T.drop 1 . decodeUtf8 . urlDecode True . encodeUtf8
72−resolvesTo :: (Text, Value) -> Assertion
70+resolvesTo :: (Text, Value) -> Expectation
73resolvesTo (t, expected) =
71resolvesTo (t, expected) =
74 case P.unescape t of
72 case P.unescape t of
75− Left e -> assertFailure (show e <> " error for pointer: " <> show t)
73+ Left e -> expectationFailure (show e <> " error for pointer: " <> show t)
76− Right p -> assertEqual
77− ("Resolved value for pointer: " <> show t)
79− (P.resolve p specExample)
74+ Right p -> P.resolve p specExample `shouldBe` Right expected
81specExample :: Value
76specExample :: Value
82specExample = object
77specExample = object