Fix boolean parsing
This commit is contained in:
parent
7874b384a5
commit
8e5112ed93
17
lib/Bril.hs
17
lib/Bril.hs
|
|
@ -5,7 +5,7 @@ module Bril (
|
|||
parseBrilFromPath, parseBrilJSON,
|
||||
)where
|
||||
|
||||
import Data.Aeson (FromJSON, parseJSON, withObject, withText, withScientific, (.:), (.:?), eitherDecode)
|
||||
import Data.Aeson (FromJSON, parseJSON, withObject, withText, withBool, withScientific, (.:), (.:?), eitherDecode)
|
||||
import Data.Aeson.Types (Parser, modifyFailure)
|
||||
import qualified Data.Aeson (Value, Object, Key)
|
||||
import Data.Aeson.KeyMap
|
||||
|
|
@ -203,19 +203,8 @@ instance FromJSON Type where
|
|||
|
||||
parseValue :: Type -> Data.Aeson.Value -> Parser Value
|
||||
parseValue Bool =
|
||||
withText "BoolValue" $ \v ->
|
||||
case v of
|
||||
"true" -> return $ BoolValue True
|
||||
"false" -> return $ BoolValue False
|
||||
_ -> fail $ "invalid bool literal: " ++ (T.unpack v)
|
||||
--parseValue Int =
|
||||
-- withText "IntValue" $ \v ->
|
||||
-- case ((signed decimal :: Reader Int64) v) of
|
||||
-- Left x -> fail $ "invalid int literal: " ++ x
|
||||
-- Right (val, t) ->
|
||||
-- if (T.null t)
|
||||
-- then return $ IntValue val
|
||||
-- else fail $ "invalid int literal: " ++ (T.unpack v)
|
||||
withBool "BoolValue" (return . BoolValue)
|
||||
|
||||
parseValue Int =
|
||||
withScientific "IntValue" $ \v ->
|
||||
if (not (isInteger v))
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@ testTypes = TestCase $ do
|
|||
testLiterals :: Test
|
||||
testLiterals = TestCase $ do
|
||||
assertEqual "true literal"
|
||||
(parseLiteral B.Bool ("true"::Text)) (Success $ B.BoolValue True)
|
||||
(parseLiteral B.Bool True) (Success $ B.BoolValue True)
|
||||
assertEqual "false literal"
|
||||
(parseLiteral B.Bool ("false"::Text)) (Success $ B.BoolValue False)
|
||||
assertEqual "wrong bool literal"
|
||||
(parseLiteral B.Bool ("xxx"::Text)) (Error "invalid bool literal: xxx")
|
||||
(parseLiteral B.Bool False) (Success $ B.BoolValue False)
|
||||
|
||||
assertEqual "int literal"
|
||||
(parseLiteral B.Int (1434 :: Int)) (Success $ B.IntValue 1434)
|
||||
|
|
|
|||
Loading…
Reference in New Issue