packages feed

purescript-bridge 0.11.1.0 → 0.11.1.1

raw patch · 4 files changed

+42/−23 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

purescript-bridge.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.11.1.0+version:             0.11.1.1  -- A short (one-line) description of the package. synopsis:            Generate PureScript data types from Haskell data types
src/Language/PureScript/Bridge/Printer.hs view
@@ -186,19 +186,18 @@  constructorToOptic :: Bool -> TypeInfo 'PureScript -> DataConstructor 'PureScript -> Text constructorToOptic otherConstructors typeInfo (DataConstructor n args) =-  case args of-    Left cs  ->-      if otherConstructors-      then+  case (args,otherConstructors) of+    (Left [c], False) ->+        pName <> forAll <>  "Iso' " <> typName <> " " <> mkTypeSig (constructorTypes [c]) <> "\n"+              <> pName <> " = _Newtype"+              <> "\n"+    (Left cs, _) ->         pName <> forAll <>  "Prism' " <> typName <> " " <> mkTypeSig types <> "\n"-             <> pName <> " = prism' " <> getter <> " f\n"-             <> spaces 2 <> "where\n"-             <> spaces 4 <> "f " <> mkF cs-             <> otherConstructorFallThrough-             <> "\n"-      else pName <> forAll <>  "Iso' " <> typName <> " " <> mkTypeSig (constructorTypes cs) <> "\n"-             <> pName <> " = _Newtype"-             <> "\n"+              <> pName <> " = prism' " <> getter <> " f\n"+              <> spaces 2 <> "where\n"+              <> spaces 4 <> "f " <> mkF cs+              <> otherConstructorFallThrough+              <> "\n"       where         mkF [] = n <> " = Just unit\n"         mkF _  = "(" <> n <> " " <> T.unwords (map _recLabel types) <> ") = Just $ " <> mkFnArgs types <> "\n"@@ -208,18 +207,16 @@           where             cArgs = map (T.singleton . fst) $ zip ['a'..] cs         types = constructorTypes cs-    Right rs ->-      if otherConstructors-      then-        pName <> forAll <> "Prism' " <> typName <> " { " <> recordSig rs <> " }\n"-             <> pName <> " = prism' " <> n <> " f\n"-             <> spaces 2 <> "where\n"-             <> spaces 4 <> "f (" <> n <> " r) = Just r\n"-             <> otherConstructorFallThrough-             <> "\n"-      else+    (Right rs, False) ->         pName <> forAll <> "Iso' " <> typName <> " { " <> recordSig rs <> "}\n"               <> pName <> " = _Newtype\n"+              <> "\n"+    (Right rs, True) ->+        pName <> forAll <> "Prism' " <> typName <> " { " <> recordSig rs <> " }\n"+              <> pName <> " = prism' " <> n <> " f\n"+              <> spaces 2 <> "where\n"+              <> spaces 4 <> "f (" <> n <> " r) = Just r\n"+              <> otherConstructorFallThrough               <> "\n"   where     recordSig rs = T.intercalate ", " (map recordEntryToText rs)
test/Spec.hs view
@@ -269,6 +269,25 @@                           , "--------------------------------------------------------------------------------"                           ]       in recTypeText `shouldBe` txt+    it "tests generation for haskell data type with one constructor, two arguments" $+      let recType = bridgeSumType (buildBridge defaultBridge) (mkSumType (Proxy :: Proxy SingleProduct))+          recTypeText = sumTypeToText recType+          txt = T.stripEnd $+                T.unlines [ "data SingleProduct ="+                          , "    SingleProduct String Int"+                          , ""+                          , "derive instance genericSingleProduct :: Generic SingleProduct"+                          , ""+                          , ""+                          , "--------------------------------------------------------------------------------"+                          , "_SingleProduct :: Prism' SingleProduct { a :: String, b :: Int }"+                          , "_SingleProduct = prism' (\\{ a, b } -> SingleProduct a b) f"+                          , "  where"+                          , "    f (SingleProduct a b) = Just $ { a: a, b: b }"+                          , ""+                          , "--------------------------------------------------------------------------------"+                          ]+      in recTypeText `shouldBe` txt     it "tests that sum types with multiple constructors don't generate record optics" $       let recType = bridgeSumType (buildBridge defaultBridge) (mkSumType (Proxy :: Proxy TwoRecords))           recTypeOptics = recordOptics recType
test/TestData.hs view
@@ -66,6 +66,9 @@ data SingleValueConstr = SingleValueConstr Int   deriving (Generic, Typeable, Show) +data SingleProduct = SingleProduct Text Int+  deriving (Generic, Typeable, Show)+ a :: HaskellType a = mkTypeInfo (Proxy :: Proxy (Either String Int))