@@ -7,6 +7,7 @@ module UnitTests (ioTests, tests) where
77import Control.Monad (forM)
88import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding, FromJSON(..), withObject, (.:), (.:?), (.:!))
99import Data.Aeson.Encode (encodeToTextBuilder)
10+import Data.Aeson.Internal (JSONPathElement(..), formatError)
1011import Data.Aeson.TH (deriveJSON)
1112import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
1213import Data.Char (toUpper)
@@ -49,6 +50,9 @@ tests = testGroup "unit" [
4950 testCase "good" $ utcTimeGood
5051 , testCase "bad" $ utcTimeBad
5152 ]
53+ , testGroup "formatError" [
54+ testCase "example 1" $ formatErrorExample
55+ ]
5256 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
5357 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
5458 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
@@ -167,6 +171,13 @@ utcTimeBad = do
167171 let (dec :: Maybe UTCTime) = decode . LT.encodeUtf8 $ (LT.concat ["\"", s, "\""]) in
168172 assertEqual "verify failure" Nothing dec
169173
174+-- Non identifier keys should be escaped & enclosed in brackets
175+formatErrorExample :: Assertion
176+formatErrorExample =
177+ let rhs = formatError [Index 0, Key "foo", Key "bar", Key "a.b.c", Key "", Key "'\\", Key "end"] "error msg"
178+ lhs = "Error in $[0].foo.bar['a.b.c']['']['\\'\\\\'].end: error msg"
179+ in assertEqual "formatError example" lhs rhs
180+
170181------------------------------------------------------------------------------
171182-- Comparison (.:?) and (.:!)
172183------------------------------------------------------------------------------