@@ -5,7 +5,7 @@ module UnitTests (ioTests, tests) where
5import Control.Monad (forM)
5import Control.Monad (forM)
6import Data.Aeson (eitherDecode, encode, genericToJSON, genericToEncoding)
6import Data.Aeson (eitherDecode, encode, genericToJSON, genericToEncoding)
7import Data.Aeson.Encode (encodeToTextBuilder)
7import Data.Aeson.Encode (encodeToTextBuilder)
8−import Data.Aeson.Types (ToJSON(..), Value, camelTo, defaultOptions)
8+import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions)
9import Data.Char (toUpper)
9import Data.Char (toUpper)
10import GHC.Generics (Generic)
10import GHC.Generics (Generic)
11import Test.Framework (Test, testGroup)
11import Test.Framework (Test, testGroup)
@@ -21,6 +21,13 @@ tests = testGroup "unit" [
21 testCase "camelTo" $ roundTripCamel "aName"
21 testCase "camelTo" $ roundTripCamel "aName"
22 , testCase "camelTo" $ roundTripCamel "another"
22 , testCase "camelTo" $ roundTripCamel "another"
23 , testCase "camelTo" $ roundTripCamel "someOtherName"
23 , testCase "camelTo" $ roundTripCamel "someOtherName"
24+ , testCase "camelTo" $
25+ assertEqual "" "camel_apicase" (camelTo '_' "CamelAPICase")
26+ , testCase "camelTo2" $ roundTripCamel2 "aName"
27+ , testCase "camelTo2" $ roundTripCamel2 "another"
28+ , testCase "camelTo2" $ roundTripCamel2 "someOtherName"
29+ , testCase "camelTo2" $
30+ assertEqual "" "camel_api_case" (camelTo2 '_' "CamelAPICase")
25 , testGroup "encoding" [
32 , testGroup "encoding" [
26 testCase "goodProducer" $ goodProducer
33 testCase "goodProducer" $ goodProducer
@@ -30,10 +37,13 @@ tests = testGroup "unit" [
30roundTripCamel :: String -> Assertion
37roundTripCamel :: String -> Assertion
31roundTripCamel name = assertEqual "" name (camelFrom '_' $ camelTo '_' name)
38roundTripCamel name = assertEqual "" name (camelFrom '_' $ camelTo '_' name)
40+roundTripCamel2 :: String -> Assertion
41+roundTripCamel2 name = assertEqual "" name (camelFrom '_' $ camelTo2 '_' name)
43+camelFrom :: Char -> String -> String
44+camelFrom c s = let (p:ps) = split c s
45+ in concat $ p : map capitalize ps
35− camelFrom c s = let (p:ps) = split c s
36− in concat $ p : map capitalize ps
37 split c s = map L.unpack $ L.split c $ L.pack s
47 split c s = map L.unpack $ L.split c $ L.pack s
38 capitalize t = toUpper (head t) : tail t
48 capitalize t = toUpper (head t) : tail t