1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
12import Data.Aeson (FromJSON(..), eitherDecode)
13import Data.Proxy (Proxy(..))
15import Numeric.Natural (Natural)
16import Test.Framework (Test)
17import Test.Framework.Providers.HUnit (testCase)
18import Test.HUnit (Assertion, assertFailure, assertEqual)
19import qualified Data.ByteString.Lazy.Char8 as L
20import qualified Data.HashMap.Strict as HM
26 , testCase "Integer" integer
27 , testCase "Natural" natural
28 , testCase "String" string
29 , testCase "HashMap" hashMap
34 let t = test (Proxy :: Proxy Int)
35 t "\"\"" $ expected "Int" "String"
36 t "[]" $ expected "Int" "Array"
37 t "{}" $ expected "Int" "Object"
38 t "null" $ expected "Int" "Null"
42 let t = test (Proxy :: Proxy Integer)
43 t "44.44" $ expected "Integer" "floating number 44.44"
47 let t = test (Proxy :: Proxy Natural)
48 t "44.44" $ expected "Natural" "floating number 44.44"
49 t "-50" $ expected "Natural" "negative number -50"
53 let t = test (Proxy :: Proxy String)
54 t "1" $ expected "String" "Number"
55 t "[]" $ expected "String" "Array"
56 t "{}" $ expected "String" "Object"
57 t "null" $ expected "String" "Null"
61 let t = test (Proxy :: Proxy (HM.HashMap String Int))
62 t "\"\"" $ expected "HashMap k v" "String"
63 t "[]" $ expected "HashMap k v" "Array"
65expected :: String -> String -> String
66expected ex enc = "Error in $: expected " ++ ex ++ ", encountered " ++ enc
68test :: forall a proxy . (FromJSON a, Show a) => proxy a -> L.ByteString -> String -> Assertion
69test _ v msg = case eitherDecode v of
70 Left e -> assertEqual "Invalid error message" msg e
71 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