fromJSON tests are now working. Yeah!

This commit is contained in:
Emmanuel Denloye-Ito 2019-03-10 16:33:29 -04:00 committed by John Wiegley
parent 5e0617a952
commit af9f69d517
2 changed files with 11 additions and 3 deletions

View File

@ -13,6 +13,7 @@
module Nix.Pretty where
import Control.Applicative ((<|>))
import Control.Monad
import Control.Monad.Free
import Data.Fix
@ -39,6 +40,7 @@ import Nix.Utils hiding ((<$>))
#endif
import Nix.Value
import Prelude hiding ((<$>))
import Text.Read (readMaybe)
-- | This type represents a pretty printed nix expression
-- together with some information about the expression.
@ -296,8 +298,15 @@ printNix = iter phi . check
phi (NVStrF ns) = show $ hackyStringIgnoreContext ns
phi (NVListF l) = "[ " ++ unwords l ++ " ]"
phi (NVSetF s _) =
"{ " ++ concat [ unpack k ++ " = " ++ v ++ "; "
"{ " ++ concat [ check (unpack k) ++ " = " ++ v ++ "; "
| (k, v) <- sort $ toList s ] ++ "}"
where
check v =
fromMaybe v
((fmap (surround . show) (readMaybe v :: Maybe Int))
<|> (fmap (surround . show) (readMaybe v :: Maybe Float)))
where
surround s = "\"" ++ s ++ "\""
phi NVClosureF {} = "<<lambda>>"
phi (NVPathF fp) = fp
phi (NVBuiltinF name _) = "<<builtin " ++ name ++ ">>"

View File

@ -2,7 +2,6 @@ with builtins;
let simpleJSON = "{\"foo\": \"39\", \"bar\": 472}";
screwyJSON = "{\"4275\": \"Please do not fail.\"}";
# crazyJSON should be tested once screwyJSON works!
crazyJSON = " {
\"response\": {
\"success\": 1,
@ -61,4 +60,4 @@ let simpleJSON = "{\"foo\": \"39\", \"bar\": 472}";
}
}
}";
in [(fromJSON simpleJSON) (fromJSON screwyJSON)]
in [(fromJSON simpleJSON) (fromJSON screwyJSON) (fromJSON crazyJSON)]