on master help sign in
aeson 0.7 support #36
commit92ad448d7c67dfc1f2437a140cb70137f3d3fde9 authorMichael Snoyman <michael@snoyman.com> dateSat 11 Jan 2014, 19:26 (13 years ago) parent8d39d4b
3 files changed+10−6
Data/Yaml.hs+3−4 test/main.hs+6−1 yaml.cabal+1−1
Data/Yaml.hs+3−4
@@ -80,12 +80,12 @@ import Data.Char (toUpper)
8080import qualified Data.Vector as V
8181import Data.Text (Text, pack)
8282import qualified Data.Text as T
83−import Data.Text.Read (signed, decimal, double)
8483import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
8584import Data.Text.Encoding.Error (lenientDecode)
8685import qualified Data.HashMap.Strict as M
8786import Data.Typeable
88−import Data.Attoparsec.Number
87+import Data.Attoparsec.ByteString (parseOnly)
88+import Data.Aeson.Parser (value)
8989import qualified Data.HashSet as HashSet
9090
9191encode :: ToJSON a => a -> ByteString
@@ -210,8 +210,7 @@ textToValue _ _ t
210210 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
211211 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
212212 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
213− | Right (x, "") <- signed decimal t = Number $ I x
214− | Right (x, "") <- double t = Number $ D x
213+ | Right (Number n) <- parseOnly value (encodeUtf8 t) = Number n
215214 | otherwise = String t
216215 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
217216 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
test/main.hs+6−1
@@ -89,7 +89,12 @@ main = hspec $ do
8989
9090 describe "pretty output" $ do
9191 it "simple nulls" $ D.encode (object ["foo" .= D.Null]) `shouldBe` "foo: null\n"
92− it "simple numbers" $ D.encode (object ["foo" .= (4 :: Int)]) `shouldBe` "foo: 4\n"
92+ it "simple numbers" $ D.encode (object ["foo" .= (4 :: Int)]) `shouldBe`
93+#if MIN_VERSION_aeson(0, 7, 0)
94+ "foo: 4.0\n" -- FIXME should this be reported as a bug upstream to aeson?
95+#else
96+ "foo: 4\n"
97+#endif
9398 it "True" $ D.encode (object ["foo" .= True]) `shouldBe` "foo: true\n"
9499 it "False" $ D.encode (object ["foo" .= False]) `shouldBe` "foo: false\n"
95100 it "simple string" $ D.encode (object ["foo" .= ("bar" :: T.Text)]) `shouldBe` "foo: bar\n"
yaml.cabal+1−1
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.5.1
2+version: 0.8.5.2
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov