on master help sign in
Merge pull request #204 from tekul/master
552c25fBryan O'Sullivan
Data/Aeson/Types.hs+1
@@ -60,6 +60,7 @@ module Data.Aeson.Types
60 -- * Generic and TH encoding configuration
60 -- * Generic and TH encoding configuration
61 , Options(..)
61 , Options(..)
62 , SumEncoding(..)
62 , SumEncoding(..)
63+ , camelTo
63 , defaultOptions
64 , defaultOptions
64 , defaultTaggedObject
65 , defaultTaggedObject
65 ) where
66 ) where
tests/Properties.hs+14−11
@@ -5,10 +5,11 @@ import Data.Aeson (eitherDecode)
5import Data.Aeson.Encode
5import Data.Aeson.Encode
6import Data.Aeson.Parser (value)
6import Data.Aeson.Parser (value)
7import Data.Aeson.Types
7import Data.Aeson.Types
8+import Data.Char (toUpper)
8import Test.Framework (Test, defaultMain, testGroup)
9import Test.Framework (Test, defaultMain, testGroup)
9import Test.Framework.Providers.QuickCheck2 (testProperty)
10import Test.Framework.Providers.QuickCheck2 (testProperty)
10import Test.Framework.Providers.HUnit (testCase)
11import Test.Framework.Providers.HUnit (testCase)
11−import Test.HUnit (assertFailure, assertEqual)
12+import Test.HUnit (Assertion, assertFailure, assertEqual)
12import Test.QuickCheck (Arbitrary(..))
13import Test.QuickCheck (Arbitrary(..))
13import qualified Data.Vector as V
14import qualified Data.Vector as V
14import qualified Data.Attoparsec.Lazy as L
15import qualified Data.Attoparsec.Lazy as L
@@ -28,13 +29,14 @@ import Data.Int
28import qualified Data.Map as Map
29import qualified Data.Map as Map
29#endif
30#endif
30
31
31−{-
32+
32−roundTripCaml :: String -> Bool
33+roundTripCamel :: String -> Assertion
33−roundTripCaml s = s == (camlFrom '_' $ camlTo '_' s)
34+roundTripCamel name = assertEqual "" name (camelFrom '_' $ camelTo '_' name)
34 where
35 where
35− camlFrom :: Char -> String -> String
36+ camelFrom c s = let (p:ps) = split c s
36− camlFrom c = concatMap capitalize $ split c
37+ in concat $ p : map capitalize ps
37−-}
38+ split c s = map L.unpack $ L.split c $ L.pack s
39+ capitalize t = toUpper (head t) : tail t
38
40
39encodeDouble :: Double -> Double -> Bool
41encodeDouble :: Double -> Double -> Bool
40encodeDouble num denom
42encodeDouble num denom
@@ -116,10 +118,11 @@ tests = [
116 testProperty "encodeDouble" encodeDouble
118 testProperty "encodeDouble" encodeDouble
117 , testProperty "encodeInteger" encodeInteger
119 , testProperty "encodeInteger" encodeInteger
118 ],
120 ],
119− -- testGroup "camlCase" [
121+ testGroup "camelCase" [
120− -- testProperty "camlTo" $ roundTripCaml "AnApiMethod"
122+ testCase "camelTo" $ roundTripCamel "aName"
121− -- , testProperty "camlTo" $ roundTripCaml "anotherMethodType"
123+ , testCase "camelTo" $ roundTripCamel "another"
124+ , testCase "camelTo" $ roundTripCamel "someOtherName"
122− -- ],
125+ ],
123 testGroup "roundTrip" [
126 testGroup "roundTrip" [
124 testProperty "Bool" $ roundTripEq True
127 testProperty "Bool" $ roundTripEq True
125 , testProperty "Double" $ roundTripEq (1 :: Approx Double)
128 , testProperty "Double" $ roundTripEq (1 :: Approx Double)