@@ -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
32−roundTripCaml :: String -> Bool
33+roundTripCamel :: String -> Assertion
33−roundTripCaml s = s == (camlFrom '_' $ camlTo '_' s)
34+roundTripCamel name = assertEqual "" name (camelFrom '_' $ camelTo '_' name)
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
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
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"
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)