1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE ScopedTypeVariables #-}
12import Data.Aeson (FromJSON(..), eitherDecode)
13import Data.Proxy (Proxy(..))
15import Numeric.Natural (Natural)
16import Test.Tasty (TestTree)
17import Test.Tasty.HUnit (Assertion, assertFailure, assertEqual, testCase)
18import qualified Data.ByteString.Lazy.Char8 as L
19import qualified Data.HashMap.Strict as HM
25 , testCase "Integer" integer
26 , testCase "Natural" natural
27 , testCase "String" string
28 , testCase "HashMap" hashMap
33 let t = test (Proxy :: Proxy Int)
34 t "\"\"" $ expected "Int" "String"
35 t "[]" $ expected "Int" "Array"
36 t "{}" $ expected "Int" "Object"
37 t "null" $ expected "Int" "Null"
41 let t = test (Proxy :: Proxy Integer)
42 t "44.44" $ expected "Integer" "floating number 44.44"
46 let t = test (Proxy :: Proxy Natural)
47 t "44.44" $ expected "Natural" "floating number 44.44"
48 t "-50" $ expected "Natural" "negative number -50"
52 let t = test (Proxy :: Proxy String)
53 t "1" $ expected "String" "Number"
54 t "[]" $ expected "String" "Array"
55 t "{}" $ expected "String" "Object"
56 t "null" $ expected "String" "Null"
60 let t = test (Proxy :: Proxy (HM.HashMap String Int))
61 t "\"\"" $ expected "HashMap k v" "String"
62 t "[]" $ expected "HashMap k v" "Array"
64expected :: String -> String -> String
65expected ex enc = "Error in $: expected " ++ ex ++ ", encountered " ++ enc
67test :: forall a proxy . (FromJSON a, Show a) => proxy a -> L.ByteString -> String -> Assertion
68test _ v msg = case eitherDecode v of
69 Left e -> assertEqual "Invalid error message" msg e
70 Right (x :: a) -> assertFailure $ "Expected parsing to fail but it suceeded with: " ++ show x
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