@@ -5,7 +5,7 @@ module UnitTests (ioTests, tests) where
55import Control.Monad (forM)
66import Data.Aeson (eitherDecode, encode, genericToJSON, genericToEncoding)
77import Data.Aeson.Encode (encodeToTextBuilder)
8−import Data.Aeson.Types (ToJSON(..), Value, camelTo, defaultOptions)
8+import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions)
99import Data.Char (toUpper)
1010import GHC.Generics (Generic)
1111import Test.Framework (Test, testGroup)
@@ -21,6 +21,13 @@ tests = testGroup "unit" [
2121 testCase "camelTo" $ roundTripCamel "aName"
2222 , testCase "camelTo" $ roundTripCamel "another"
2323 , 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")
2431 ]
2532 , testGroup "encoding" [
2633 testCase "goodProducer" $ goodProducer
@@ -30,10 +37,13 @@ tests = testGroup "unit" [
3037roundTripCamel :: String -> Assertion
3138roundTripCamel name = assertEqual "" name (camelFrom '_' $ camelTo '_' name)
3239
40+roundTripCamel2 :: String -> Assertion
41+roundTripCamel2 name = assertEqual "" name (camelFrom '_' $ camelTo2 '_' name)
3342
43+camelFrom :: Char -> String -> String
44+camelFrom c s = let (p:ps) = split c s
45+ in concat $ p : map capitalize ps
3446 where
35− camelFrom c s = let (p:ps) = split c s
36− in concat $ p : map capitalize ps
3747 split c s = map L.unpack $ L.split c $ L.pack s
3848 capitalize t = toUpper (head t) : tail t
3949