packages feed

json-spec-elm 0.3.0.1 → 0.3.0.2

raw patch · 3 files changed

+50/−3 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

json-spec-elm.cabal view
@@ -1,6 +1,6 @@ cabal-version:       3.0 name:                json-spec-elm-version:             0.3.0.1+version:             0.3.0.2 synopsis:            Elm code generate for `json-spec`. description:                               Produce elm types, encoders, and decoders from a
src/Data/JsonSpec/Elm.hs view
@@ -276,7 +276,7 @@       Expr.Lam . toScope $         Expr.apps           "Maybe.withDefault"-          [ "Json.Decode.null"+          [ "Json.Encode.null"           , Expr.apps               "Maybe.map"               [ Expr.bind Expr.Global absurd encoder
test/test.hs view
@@ -7,7 +7,7 @@ import Data.Foldable (traverse_) import Data.HashMap.Strict (HashMap) import Data.JsonSpec (Specification(JsonArray, JsonDateTime, JsonEither,-  JsonInt, JsonLet, JsonNum, JsonObject, JsonRef, JsonString, JsonTag))+  JsonInt, JsonLet, JsonNullable, JsonNum, JsonObject, JsonRef, JsonString, JsonTag)) import Data.JsonSpec.Elm (Named, elmDefs) import Data.Maybe (fromMaybe) import Data.Proxy (Proxy(Proxy))@@ -200,7 +200,51 @@             \)"           callCommand "rm -rf elm-test" +      it "works with nullable values" $+        let+          actual :: HashMap Module Text+          actual =+            fmap ((<> "\n") . renderStrict . layoutPretty defaultLayoutOptions)+            . modules+            . Set.toList+            $ elmDefs (Proxy @NullableSpec) +          expected :: HashMap Module Text+          expected = +            HM.singleton+              ["Api", "Data"]+              ( Text.unlines+                  [ "module Api.Data exposing"+                  , "    ( nullableIntDecoder"+                  , "    , nullableIntEncoder"+                  , "    , NullableInt"+                  , "    )"+                  , ""+                  , "import Json.Decode"+                  , "import Json.Encode"+                  , ""+                  , ""+                  , "nullableIntDecoder : Json.Decode.Decoder NullableInt"+                  , "nullableIntDecoder ="+                  , "    Json.Decode.nullable Json.Decode.int"+                  , ""+                  , ""+                  , "nullableIntEncoder : NullableInt -> Json.Encode.Value"+                  , "nullableIntEncoder a ="+                  , "    Maybe.withDefault Json.Encode.null (Maybe.map Json.Encode.int a)"+                  , ""+                  , ""+                  , "type alias NullableInt  ="+                  , "    Maybe Int"+                  ]+              )+        in do+          TIO.hPutStrLn stderr "==========================================\n\n"+          TIO.hPutStrLn stderr (fromMaybe "" (HM.lookup ["Api", "Data"] actual))+          TIO.hPutStrLn stderr "\n\n==========================================\n\n"+          actual `shouldBe` expected++ {-   This spec is copied from an as-yet uncompleted personal project. I   just used it because it is fairly complex. Probably something known@@ -311,6 +355,9 @@          ]     ) +type NullableSpec =+  Named "NullableInt"+    (JsonNullable JsonInt)  writeModule :: (Module, Text) -> IO () writeModule (module_, content) = do