fromJSON tests are now working. Yeah!
This commit is contained in:
parent
5e0617a952
commit
af9f69d517
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
module Nix.Pretty where
|
module Nix.Pretty where
|
||||||
|
|
||||||
|
import Control.Applicative ((<|>))
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.Free
|
import Control.Monad.Free
|
||||||
import Data.Fix
|
import Data.Fix
|
||||||
|
@ -39,6 +40,7 @@ import Nix.Utils hiding ((<$>))
|
||||||
#endif
|
#endif
|
||||||
import Nix.Value
|
import Nix.Value
|
||||||
import Prelude hiding ((<$>))
|
import Prelude hiding ((<$>))
|
||||||
|
import Text.Read (readMaybe)
|
||||||
|
|
||||||
-- | This type represents a pretty printed nix expression
|
-- | This type represents a pretty printed nix expression
|
||||||
-- together with some information about the expression.
|
-- together with some information about the expression.
|
||||||
|
@ -296,8 +298,15 @@ printNix = iter phi . check
|
||||||
phi (NVStrF ns) = show $ hackyStringIgnoreContext ns
|
phi (NVStrF ns) = show $ hackyStringIgnoreContext ns
|
||||||
phi (NVListF l) = "[ " ++ unwords l ++ " ]"
|
phi (NVListF l) = "[ " ++ unwords l ++ " ]"
|
||||||
phi (NVSetF s _) =
|
phi (NVSetF s _) =
|
||||||
"{ " ++ concat [ unpack k ++ " = " ++ v ++ "; "
|
"{ " ++ concat [ check (unpack k) ++ " = " ++ v ++ "; "
|
||||||
| (k, v) <- sort $ toList s ] ++ "}"
|
| (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 NVClosureF {} = "<<lambda>>"
|
||||||
phi (NVPathF fp) = fp
|
phi (NVPathF fp) = fp
|
||||||
phi (NVBuiltinF name _) = "<<builtin " ++ name ++ ">>"
|
phi (NVBuiltinF name _) = "<<builtin " ++ name ++ ">>"
|
||||||
|
|
|
@ -2,7 +2,6 @@ with builtins;
|
||||||
|
|
||||||
let simpleJSON = "{\"foo\": \"39\", \"bar\": 472}";
|
let simpleJSON = "{\"foo\": \"39\", \"bar\": 472}";
|
||||||
screwyJSON = "{\"4275\": \"Please do not fail.\"}";
|
screwyJSON = "{\"4275\": \"Please do not fail.\"}";
|
||||||
# crazyJSON should be tested once screwyJSON works!
|
|
||||||
crazyJSON = " {
|
crazyJSON = " {
|
||||||
\"response\": {
|
\"response\": {
|
||||||
\"success\": 1,
|
\"success\": 1,
|
||||||
|
@ -61,4 +60,4 @@ let simpleJSON = "{\"foo\": \"39\", \"bar\": 472}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
in [(fromJSON simpleJSON) (fromJSON screwyJSON)]
|
in [(fromJSON simpleJSON) (fromJSON screwyJSON) (fromJSON crazyJSON)]
|
||||||
|
|
Loading…
Reference in a new issue