1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
12import Data.Aeson (FromJSON(..), eitherDecode)
13import Data.Proxy (Proxy(..))
15import Test.Framework (Test)
16import Test.Framework.Providers.HUnit (testCase)
17import Test.HUnit (Assertion, assertFailure, assertEqual)
18import qualified Data.ByteString.Lazy.Char8 as L
19import qualified Data.HashMap.Strict as HM
25 , testCase "String" string
26 , testCase "HashMap" hashMap
31 let t = test (Proxy :: Proxy Int)
32 t "\"\"" $ expected "Int" "String"
33 t "[]" $ expected "Int" "Array"
34 t "{}" $ expected "Int" "Object"
35 t "null" $ expected "Int" "Null"
39 let t = test (Proxy :: Proxy String)
40 t "1" $ expected "String" "Number"
41 t "[]" $ expected "String" "Array"
42 t "{}" $ expected "String" "Object"
43 t "null" $ expected "String" "Null"
47 let t = test (Proxy :: Proxy (HM.HashMap String Int))
48 t "\"\"" $ expected "HashMap k v" "String"
49 t "[]" $ expected "HashMap k v" "Array"
51expected :: String -> String -> String
52expected ex enc = "Error in $: expected " ++ ex ++ ", encountered " ++ enc
54test :: forall a proxy . (FromJSON a, Show a) => proxy a -> L.ByteString -> String -> Assertion
55test _ v msg = case eitherDecode v of
56 Left e -> assertEqual "Invalid error message" msg e
57 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