Down to 3 failures

This commit is contained in:
John Wiegley 2019-03-18 18:31:36 -07:00
parent 77d67b106c
commit 769a40e643
No known key found for this signature in database
GPG key ID: C144D8F4F19FE630
2 changed files with 17 additions and 17 deletions

View file

@ -1300,21 +1300,21 @@ readDir_ p = demand p $ \path' -> do
fromJSON
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
fromJSON = fromValue >=> fromStringNoContext >=> \encoded ->
fromJSON arg = demand arg $ fromValue >=> fromStringNoContext >=> \encoded ->
case A.eitherDecodeStrict' @A.Value $ encodeUtf8 encoded of
Left jsonError ->
throwError $ ErrorCall $ "builtins.fromJSON: " ++ jsonError
Right v -> jsonToNValue v
where
jsonToNValue = \case
A.Object m -> flip nvSet M.empty <$> traverse (defer . jsonToNValue) m
A.Object m -> flip nvSet M.empty <$> traverse jsonToNValue m
A.Array l -> nvList <$> traverse jsonToNValue (V.toList l)
A.String s -> pure $ nvStr $ hackyMakeNixStringWithoutContext s
A.Number n -> pure $ nvConstant $ case floatingOrInteger n of
Left r -> NFloat r
Right i -> NInt i
A.Bool b -> pure $ nvConstant $ NBool b
A.Null -> pure $ nvConstant NNull
A.Bool b -> pure $ nvConstant $ NBool b
A.Null -> pure $ nvConstant NNull
prim_toJSON :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
prim_toJSON x = demand x $ fmap nvStr . nvalueToJSONNixString

View file

@ -64,17 +64,6 @@ checkComparable x y = case (x, y) of
(NVPath _, NVPath _) -> pure ()
_ -> throwError $ Comparison x y
thunkEqM :: (MonadThunk t m (NValue t f m), Comonad f) => t -> t -> m Bool
thunkEqM lt rt = force lt $ \lv -> force rt $ \rv ->
let unsafePtrEq = case (lt, rt) of
(thunkId -> lid, thunkId -> rid) | lid == rid -> return True
_ -> valueEqM lv rv
in case (lv, rv) of
(NVClosure _ _, NVClosure _ _) -> unsafePtrEq
(NVList _ , NVList _ ) -> unsafePtrEq
(NVSet _ _ , NVSet _ _ ) -> unsafePtrEq
_ -> valueEqM lv rv
-- | Checks whether two containers are equal, using the given item equality
-- predicate. If there are any item slots that don't match between the two
-- containers, the result will be False.
@ -170,8 +159,8 @@ valueEqM
-> NValue t f m
-> m Bool
valueEqM (Pure x) (Pure y) = thunkEqM x y
valueEqM (Pure _) _ = pure False
valueEqM _ (Pure _) = pure False
valueEqM (Pure x) y@(Free _) = thunkEqM x =<< thunk (pure y)
valueEqM x@(Free _) (Pure y) = thunkEqM ?? y =<< thunk (pure x)
valueEqM (Free (NValue (extract -> x))) (Free (NValue (extract -> y))) =
valueFEqM (compareAttrSetsM f valueEqM) valueEqM x y
where
@ -182,6 +171,17 @@ valueEqM (Free (NValue (extract -> x))) (Free (NValue (extract -> y))) =
NVStr' s -> pure $ Just s
_ -> pure Nothing
thunkEqM :: (MonadThunk t m (NValue t f m), Comonad f) => t -> t -> m Bool
thunkEqM lt rt = force lt $ \lv -> force rt $ \rv ->
let unsafePtrEq = case (lt, rt) of
(thunkId -> lid, thunkId -> rid) | lid == rid -> return True
_ -> valueEqM lv rv
in case (lv, rv) of
(NVClosure _ _, NVClosure _ _) -> unsafePtrEq
(NVList _ , NVList _ ) -> unsafePtrEq
(NVSet _ _ , NVSet _ _ ) -> unsafePtrEq
_ -> valueEqM lv rv
valueNFEq :: Comonad f => NValueNF t f m -> NValueNF t f m -> Bool
valueNFEq (Fix (NValue (extract -> x))) (Fix (NValue (extract -> y))) =
valueFEq (compareAttrSets f valueNFEq) valueNFEq x y