on master help sign in
Fix sporadic eitherDecodeLenient test failures
bef0e88Julian K. Arni
servant/test/Servant/API/ContentTypesSpec.hs+4−3
@@ -12,8 +12,6 @@ import Data.Monoid
12#endif
12#endif
13import Control.Arrow
13import Control.Arrow
14import Data.Aeson
14import Data.Aeson
15−import Data.Aeson.Parser (jstring)
16−import Data.Attoparsec.ByteString (parseOnly)
17import Data.Either
15import Data.Either
18import Data.Function (on)
16import Data.Function (on)
19import Data.Proxy
17import Data.Proxy
@@ -164,11 +162,14 @@ spec = describe "Servant.API.ContentTypes" $ do
164
162
165 describe "eitherDecodeLenient" $ do
163 describe "eitherDecodeLenient" $ do
166
164
165+ -- aeson >= 0.9 decodes top-level strings
166+#if MIN_VERSION_aeson(0,9,0)
167 it "parses top-level strings" $ do
167 it "parses top-level strings" $ do
168 let toMaybe = either (const Nothing) Just
168 let toMaybe = either (const Nothing) Just
169 -- The Left messages differ, so convert to Maybe
169 -- The Left messages differ, so convert to Maybe
170 property $ \x -> toMaybe (eitherDecodeLenient x)
170 property $ \x -> toMaybe (eitherDecodeLenient x)
171− `shouldBe` toMaybe (parseOnly jstring $ cs x)
171+ `shouldBe` (decode x :: Maybe String)
172+#endif
172
173
173
174
174data SomeData = SomeData { record1 :: String, record2 :: Int }
175data SomeData = SomeData { record1 :: String, record2 :: Int }