git.iko.soy/rowtype-yoga/purescript-yoga-json
on v2.0.0 help sign in
27 lines 1.1 kB history raw
1module Test.Util where
3import Prelude
5import Data.Either (Either(..))
6import Data.Semigroup.Foldable (intercalateMap)
7import Effect.Aff (Aff)
8import Foreign (Foreign, renderForeignError)
9import Test.Spec.Assertions (fail)
10import Type.Proxy (Proxy(..))
11import Yoga.JSON (class ReadForeign, class WriteForeign, read, readJSON, write, writeJSON)
12import Yoga.JSON.Error (toJSONPath)
14roundtrips ∷ ∀ a. Show a ⇒ Eq a ⇒ ReadForeign a ⇒ WriteForeign a ⇒ a → Aff Unit
15roundtrips x = do
16 x # write # shouldRead (Proxy ∷ _ a)
17 x # writeJSON # shouldReadJSON (Proxy ∷ _ a)
19shouldRead ∷ ∀ a. ReadForeign a ⇒ Proxy a → Foreign → Aff Unit
20shouldRead _ = read >>> case _ of
21 Left e → fail (intercalateMap "\n" renderForeignError e <> "\n" <> intercalateMap "\n" toJSONPath e)
22 Right (_ ∷ a) → pure unit
24shouldReadJSON ∷ ∀ a. ReadForeign a ⇒ Proxy a → String → Aff Unit
25shouldReadJSON _ = readJSON >>> case _ of
26 Left e → fail (intercalateMap "\n" renderForeignError e <> "\n" <> intercalateMap "\n" toJSONPath e)
27 Right (_ ∷ a) → pure unit