7import qualified Data.Text as T
8import Data.Text.Encoding
9import qualified Data.Vector as V
10import qualified JSONPointer as JP
11import Network.HTTP.Types.URI (urlDecode)
14import Test.QuickCheck (property)
16-- For GHCs before 7.10:
17import Control.Applicative
21import qualified Example
25 describe "example" $ do
26 it "compiles and runs without errors" Example.main
27 describe "pointers" $ do
28 it "can be stored as JSON without changing its value" (property roundtrip)
29 it "can be represented in a JSON string value" jsonString
30 it "can be represented in a URI fragment identifier" uriFragment
32roundtrip :: JP.Pointer -> Bool
33roundtrip a = Just a == decode (encode a)
35jsonString :: Expectation
36jsonString = traverse_ resolvesTo
38 , ("/foo" , Array $ V.fromList ["bar", "baz"])
39 , ("/foo/0", String "bar")
41 , ("/a~1b" , Number 1)
45 , ("/i\\j" , Number 5)
46 , ("/k\"l" , Number 6)
48 , ("/m~0n" , Number 8)
51uriFragment :: Expectation
52uriFragment = traverse_ resolvesTo . fmap (first decodeFragment) $
54 , ("#/foo" , Array $ V.fromList ["bar", "baz"])
55 , ("#/foo/0", String "bar")
57 , ("#/a~1b" , Number 1)
58 , ("#/c%25d", Number 2)
59 , ("#/e%5Ef", Number 3)
60 , ("#/g%7Ch", Number 4)
61 , ("#/i%5Cj", Number 5)
62 , ("#/k%22l", Number 6)
63 , ("#/%20" , Number 7)
64 , ("#/m~0n" , Number 8)
67 decodeFragment :: Text -> Text
68 decodeFragment = T.drop 1 . decodeUtf8 . urlDecode True . encodeUtf8
70resolvesTo :: (Text, Value) -> Expectation
71resolvesTo (t, expected) =
73 Left e -> expectationFailure (show e <> " error for pointer: " <> show t)
74 Right p -> JP.resolve p specExample `shouldBe` Right expected
78 [ "foo" .= (["bar", "baz"] :: [Text])
84 , "i\\j" .= (5 :: Int)
85 , "k\"l" .= (6 :: Int)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list