5import Data.Bifunctor (first)
9import qualified Data.Text as T
10import Data.Text.Encoding (decodeUtf8, encodeUtf8)
11import qualified Data.Vector as V
12import qualified JSONPointer as JP
13import Network.HTTP.Types.URI (urlDecode)
16import Test.QuickCheck (property)
18import qualified Example
22 describe "example" $ do
23 it "compiles and runs without errors" Example.main
24 describe "pointers" $ do
25 it "can be stored as JSON without changing its value" (property roundtrip)
26 it "can be represented in a JSON string value" jsonString
27 it "can be represented in a URI fragment identifier" uriFragment
29roundtrip :: JP.Pointer -> Bool
30roundtrip a = Just a == decode (encode a)
32jsonString :: Expectation
33jsonString = traverse_ resolvesTo
35 , ("/foo" , Array $ V.fromList ["bar", "baz"])
36 , ("/foo/0", String "bar")
38 , ("/a~1b" , Number 1)
42 , ("/i\\j" , Number 5)
43 , ("/k\"l" , Number 6)
45 , ("/m~0n" , Number 8)
48uriFragment :: Expectation
49uriFragment = traverse_ resolvesTo . fmap (first decodeFragment) $
51 , ("#/foo" , Array $ V.fromList ["bar", "baz"])
52 , ("#/foo/0", String "bar")
54 , ("#/a~1b" , Number 1)
55 , ("#/c%25d", Number 2)
56 , ("#/e%5Ef", Number 3)
57 , ("#/g%7Ch", Number 4)
58 , ("#/i%5Cj", Number 5)
59 , ("#/k%22l", Number 6)
60 , ("#/%20" , Number 7)
61 , ("#/m~0n" , Number 8)
64 decodeFragment :: Text -> Text
65 decodeFragment = T.drop 1 . decodeUtf8 . urlDecode True . encodeUtf8
67resolvesTo :: (Text, Value) -> Expectation
68resolvesTo (t, expected) =
70 Left e -> expectationFailure (show e <> " error for pointer: " <> show t)
71 Right p -> JP.resolve p specExample `shouldBe` Right expected
75 [ "foo" .= (["bar", "baz"] :: [Text])
81 , "i\\j" .= (5 :: Int)
82 , "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