on master help sign in
aeson 0.7 support #36
92ad448Michael Snoyman
Data/Yaml.hs+3−4
@@ -80,12 +80,12 @@ import Data.Char (toUpper)
80import qualified Data.Vector as V
80import qualified Data.Vector as V
81import Data.Text (Text, pack)
81import Data.Text (Text, pack)
82import qualified Data.Text as T
82import qualified Data.Text as T
83−import Data.Text.Read (signed, decimal, double)
84import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
83import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
85import Data.Text.Encoding.Error (lenientDecode)
84import Data.Text.Encoding.Error (lenientDecode)
86import qualified Data.HashMap.Strict as M
85import qualified Data.HashMap.Strict as M
87import Data.Typeable
86import Data.Typeable
88−import Data.Attoparsec.Number
87+import Data.Attoparsec.ByteString (parseOnly)
88+import Data.Aeson.Parser (value)
89import qualified Data.HashSet as HashSet
89import qualified Data.HashSet as HashSet
90
90
91encode :: ToJSON a => a -> ByteString
91encode :: ToJSON a => a -> ByteString
@@ -210,8 +210,7 @@ textToValue _ _ t
210 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
210 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
211 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
211 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
212 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
212 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
213− | Right (x, "") <- signed decimal t = Number $ I x
213+ | Right (Number n) <- parseOnly value (encodeUtf8 t) = Number n
214− | Right (x, "") <- double t = Number $ D x
215 | otherwise = String t
214 | otherwise = String t
216 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
215 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
217 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
216 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
test/main.hs+6−1
@@ -89,7 +89,12 @@ main = hspec $ do
89
89
90 describe "pretty output" $ do
90 describe "pretty output" $ do
91 it "simple nulls" $ D.encode (object ["foo" .= D.Null]) `shouldBe` "foo: null\n"
91 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
93 it "True" $ D.encode (object ["foo" .= True]) `shouldBe` "foo: true\n"
98 it "True" $ D.encode (object ["foo" .= True]) `shouldBe` "foo: true\n"
94 it "False" $ D.encode (object ["foo" .= False]) `shouldBe` "foo: false\n"
99 it "False" $ D.encode (object ["foo" .= False]) `shouldBe` "foo: false\n"
95 it "simple string" $ D.encode (object ["foo" .= ("bar" :: T.Text)]) `shouldBe` "foo: bar\n"
100 it "simple string" $ D.encode (object ["foo" .= ("bar" :: T.Text)]) `shouldBe` "foo: bar\n"
yaml.cabal+1−1
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.8.5.1
2+version: 0.8.5.2
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov