From 944814e76031e23ce853d08207416ecf9dd5be0c Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 01:05:02 +0300 Subject: [PATCH 1/7] testing(hs): add `basicStruct` --- test/ParsingSpec.hs | 24 +++++++++++++++++++++--- test/reference-output/basicStruct.hs | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/reference-output/basicStruct.hs diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index 2e8958b..b715924 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -28,7 +28,8 @@ data TypeScriptReferenceOutput = TypeScriptReferenceOutput } data HaskellReferenceOutput = HaskellReferenceOutput - { basic :: !Text, + { basicStruct :: !Text, + basic :: !Text, import' :: !Text, hasGeneric :: !Text, generics :: !Text, @@ -110,12 +111,21 @@ typeScriptReferenceOutput = do haskellReferenceOutput :: IO HaskellReferenceOutput haskellReferenceOutput = do + basicStruct <- basicStructReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" generics <- genericsReferenceOutput "hs" gitHub <- gitHubReferenceOutput "hs" - pure HaskellReferenceOutput {basic, import', hasGeneric, generics, gitHub} + pure + HaskellReferenceOutput + { basicStruct, + basic, + import', + hasGeneric, + generics, + gitHub + } fSharpReferenceOutput :: IO FSharpReferenceOutput fSharpReferenceOutput = do @@ -261,7 +271,14 @@ spec tsGenerics tsGitHub ) - (HaskellReferenceOutput hsBasic hsImport hsHasGeneric hsGenerics hsGitHub) + ( HaskellReferenceOutput + hsBasicStruct + hsBasic + hsImport + hsHasGeneric + hsGenerics + hsGitHub + ) (FSharpReferenceOutput fsBasic fsImport fsHasGeneric fsGenerics fsGitHub) (PythonReferenceOutput pyPython pyBasic pyGenerics) ( KotlinReferenceOutput @@ -596,6 +613,7 @@ spec basicStructModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/basicStruct.gotyno"] TypeScript.outputModule basicStructModule `shouldBe` tsBasicStruct + Haskell.outputModule basicStructModule `shouldBe` hsBasicStruct Kotlin.outputModule basicStructModule `shouldBe` ktBasicStruct DLang.outputModule basicStructModule `shouldBe` dBasicStruct diff --git a/test/reference-output/basicStruct.hs b/test/reference-output/basicStruct.hs new file mode 100644 index 0000000..ba54765 --- /dev/null +++ b/test/reference-output/basicStruct.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.BasicStruct where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data BasicStruct = BasicStruct + { _basicStructField1 :: Int, + _basicStructField2 :: Text + } + deriving (Eq, Show, Generic) + +deriveLensAndJSON ''BasicStruct From 522b433cbf5c38496ff0318ca5c4c5ce36228582 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 20:53:34 +0300 Subject: [PATCH 2/7] testing(hs): add `basicUnion` --- test/ParsingSpec.hs | 5 +++++ test/reference-output/basicUnion.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/reference-output/basicUnion.hs diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index b715924..ff65ebb 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -29,6 +29,7 @@ data TypeScriptReferenceOutput = TypeScriptReferenceOutput data HaskellReferenceOutput = HaskellReferenceOutput { basicStruct :: !Text, + basicUnion :: !Text, basic :: !Text, import' :: !Text, hasGeneric :: !Text, @@ -112,6 +113,7 @@ typeScriptReferenceOutput = do haskellReferenceOutput :: IO HaskellReferenceOutput haskellReferenceOutput = do basicStruct <- basicStructReferenceOutput "hs" + basicUnion <- basicUnionReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" @@ -120,6 +122,7 @@ haskellReferenceOutput = do pure HaskellReferenceOutput { basicStruct, + basicUnion, basic, import', hasGeneric, @@ -273,6 +276,7 @@ spec ) ( HaskellReferenceOutput hsBasicStruct + hsBasicUnion hsBasic hsImport hsHasGeneric @@ -621,6 +625,7 @@ spec basicUnionModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/basicUnion.gotyno"] TypeScript.outputModule basicUnionModule `shouldBe` tsBasicUnion + Haskell.outputModule basicUnionModule `shouldBe` hsBasicUnion Kotlin.outputModule basicUnionModule `shouldBe` ktBasicUnion DLang.outputModule basicUnionModule `shouldBe` dBasicUnion diff --git a/test/reference-output/basicUnion.hs b/test/reference-output/basicUnion.hs new file mode 100644 index 0000000..375d9e3 --- /dev/null +++ b/test/reference-output/basicUnion.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.BasicUnion where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data PayloadStruct = PayloadStruct + { _payloadStructField1 :: Int + } + deriving (Eq, Show, Generic) + +deriveLensAndJSON ''PayloadStruct + +data BasicUnion + = HasStringPayload Text + | HasPayload PayloadStruct + | HasNoPayload + deriving (Eq, Show, Generic) + +instance ToJSON BasicUnion where + toJSON = JSON.genericToJSON $ Helpers.gotynoOptions "type" + +instance FromJSON BasicUnion where + parseJSON = JSON.genericParseJSON $ Helpers.gotynoOptions "type" From 986944b3b7b405b9cbe2bddb4d87ada73476600e Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 21:50:49 +0300 Subject: [PATCH 3/7] testing(hs): add `generic{Struct,Union}` --- src/CodeGeneration/Haskell.hs | 12 ++++++--- test/HaskellOutputSpec.hs | 36 +++++++++++++++++--------- test/ParsingSpec.hs | 10 +++++++ test/reference-output/genericStruct.hs | 29 +++++++++++++++++++++ test/reference-output/genericUnion.hs | 21 +++++++++++++++ test/reference-output/generics.hs | 12 ++++++--- test/reference-output/hasGeneric.hs | 24 +++++++++++------ test/reference-output/importExample.hs | 12 ++++++--- 8 files changed, 124 insertions(+), 32 deletions(-) create mode 100644 test/reference-output/genericStruct.hs create mode 100644 test/reference-output/genericUnion.hs diff --git a/src/CodeGeneration/Haskell.hs b/src/CodeGeneration/Haskell.hs index 1a672df..6558b91 100644 --- a/src/CodeGeneration/Haskell.hs +++ b/src/CodeGeneration/Haskell.hs @@ -299,8 +299,10 @@ outputGenericStruct name typeVariables fields = mconcat [ classHeaderOutput "ToJSON", "\n", - " toJSON = JSON.genericToJSON\n", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_", + " toJSON =\n", + " JSON.genericToJSON\n", + " JSON.defaultOptions\n", + " {JSON.fieldLabelModifier = drop @[] (length \"_", nameOf name, "\") >>> lowerCaseFirst}" ] @@ -308,8 +310,10 @@ outputGenericStruct name typeVariables fields = mconcat [ classHeaderOutput "FromJSON", "\n", - " parseJSON = JSON.genericParseJSON\n", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_", + " parseJSON =\n", + " JSON.genericParseJSON\n", + " JSON.defaultOptions\n", + " {JSON.fieldLabelModifier = drop @[] (length \"_", nameOf name, "\") >>> lowerCaseFirst}" ] diff --git a/test/HaskellOutputSpec.hs b/test/HaskellOutputSpec.hs index 2c0298b..fe34c37 100644 --- a/test/HaskellOutputSpec.hs +++ b/test/HaskellOutputSpec.hs @@ -60,12 +60,16 @@ spec = do " deriving (Eq, Show, Generic)", "", "instance (FromJSON t, FromJSON u) => FromJSON (Holder t u) where", - " parseJSON = JSON.genericParseJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", + " parseJSON =", + " JSON.genericParseJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", "", "instance (ToJSON t, ToJSON u) => ToJSON (Holder t u) where", - " toJSON = JSON.genericToJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", + " toJSON =", + " JSON.genericToJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", "", "makeLenses ''Holder", "" @@ -360,12 +364,16 @@ spec = do " deriving (Eq, Show, Generic)", "", "instance (FromJSON t) => FromJSON (Holder t) where", - " parseJSON = JSON.genericParseJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", + " parseJSON =", + " JSON.genericParseJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", "", "instance (ToJSON t) => ToJSON (Holder t) where", - " toJSON = JSON.genericToJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", + " toJSON =", + " JSON.genericToJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_Holder\") >>> lowerCaseFirst}", "", "makeLenses ''Holder", "", @@ -376,12 +384,16 @@ spec = do " deriving (Eq, Show, Generic)", "", "instance (FromJSON t) => FromJSON (MaybeHolder t) where", - " parseJSON = JSON.genericParseJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_MaybeHolder\") >>> lowerCaseFirst}", + " parseJSON =", + " JSON.genericParseJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_MaybeHolder\") >>> lowerCaseFirst}", "", "instance (ToJSON t) => ToJSON (MaybeHolder t) where", - " toJSON = JSON.genericToJSON", - " JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length \"_MaybeHolder\") >>> lowerCaseFirst}", + " toJSON =", + " JSON.genericToJSON", + " JSON.defaultOptions", + " {JSON.fieldLabelModifier = drop @[] (length \"_MaybeHolder\") >>> lowerCaseFirst}", "", "makeLenses ''MaybeHolder", "", diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index ff65ebb..6d080dd 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -30,6 +30,8 @@ data TypeScriptReferenceOutput = TypeScriptReferenceOutput data HaskellReferenceOutput = HaskellReferenceOutput { basicStruct :: !Text, basicUnion :: !Text, + genericStruct :: !Text, + genericUnion :: !Text, basic :: !Text, import' :: !Text, hasGeneric :: !Text, @@ -114,6 +116,8 @@ haskellReferenceOutput :: IO HaskellReferenceOutput haskellReferenceOutput = do basicStruct <- basicStructReferenceOutput "hs" basicUnion <- basicUnionReferenceOutput "hs" + genericStruct <- genericStructReferenceOutput "hs" + genericUnion <- genericUnionReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" @@ -123,6 +127,8 @@ haskellReferenceOutput = do HaskellReferenceOutput { basicStruct, basicUnion, + genericStruct, + genericUnion, basic, import', hasGeneric, @@ -277,6 +283,8 @@ spec ( HaskellReferenceOutput hsBasicStruct hsBasicUnion + hsGenericStruct + hsGenericUnion hsBasic hsImport hsHasGeneric @@ -633,6 +641,7 @@ spec genericStructModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/genericStruct.gotyno"] TypeScript.outputModule genericStructModule `shouldBe` tsGenericStruct + Haskell.outputModule genericStructModule `shouldBe` hsGenericStruct Kotlin.outputModule genericStructModule `shouldBe` ktGenericStruct DLang.outputModule genericStructModule `shouldBe` dGenericStruct @@ -640,6 +649,7 @@ spec genericUnionModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/genericUnion.gotyno"] TypeScript.outputModule genericUnionModule `shouldBe` tsGenericUnion + Haskell.outputModule genericUnionModule `shouldBe` hsGenericUnion Kotlin.outputModule genericUnionModule `shouldBe` ktGenericUnion DLang.outputModule genericUnionModule `shouldBe` dGenericUnion diff --git a/test/reference-output/genericStruct.hs b/test/reference-output/genericStruct.hs new file mode 100644 index 0000000..739eeeb --- /dev/null +++ b/test/reference-output/genericStruct.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.GenericStruct where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data GenericStruct t = GenericStruct + { _genericStructField :: t + } + deriving (Eq, Show, Generic) + +instance (FromJSON t) => FromJSON (GenericStruct t) where + parseJSON = + JSON.genericParseJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_GenericStruct") >>> lowerCaseFirst} + +instance (ToJSON t) => ToJSON (GenericStruct t) where + toJSON = + JSON.genericToJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_GenericStruct") >>> lowerCaseFirst} + +makeLenses ''GenericStruct diff --git a/test/reference-output/genericUnion.hs b/test/reference-output/genericUnion.hs new file mode 100644 index 0000000..27e7f08 --- /dev/null +++ b/test/reference-output/genericUnion.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.GenericUnion where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data GenericUnion t + = HasTPayload t + | HasNoPayload + deriving (Eq, Show, Generic) + +instance (ToJSON t) => ToJSON (GenericUnion t) where + toJSON = JSON.genericToJSON $ Helpers.gotynoOptions "type" + +instance (FromJSON t) => FromJSON (GenericUnion t) where + parseJSON = JSON.genericParseJSON $ Helpers.gotynoOptions "type" diff --git a/test/reference-output/generics.hs b/test/reference-output/generics.hs index 1d83be4..15b9dca 100644 --- a/test/reference-output/generics.hs +++ b/test/reference-output/generics.hs @@ -26,12 +26,16 @@ data UsingOwnGenerics t = UsingOwnGenerics deriving (Eq, Show, Generic) instance (FromJSON t) => FromJSON (UsingOwnGenerics t) where - parseJSON = JSON.genericParseJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_UsingOwnGenerics") >>> lowerCaseFirst} + parseJSON = + JSON.genericParseJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_UsingOwnGenerics") >>> lowerCaseFirst} instance (ToJSON t) => ToJSON (UsingOwnGenerics t) where - toJSON = JSON.genericToJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_UsingOwnGenerics") >>> lowerCaseFirst} + toJSON = + JSON.genericToJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_UsingOwnGenerics") >>> lowerCaseFirst} makeLenses ''UsingOwnGenerics diff --git a/test/reference-output/hasGeneric.hs b/test/reference-output/hasGeneric.hs index fe88459..b06937d 100644 --- a/test/reference-output/hasGeneric.hs +++ b/test/reference-output/hasGeneric.hs @@ -29,12 +29,16 @@ data Holder t = Holder deriving (Eq, Show, Generic) instance (FromJSON t) => FromJSON (Holder t) where - parseJSON = JSON.genericParseJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_Holder") >>> lowerCaseFirst} + parseJSON = + JSON.genericParseJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_Holder") >>> lowerCaseFirst} instance (ToJSON t) => ToJSON (Holder t) where - toJSON = JSON.genericToJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_Holder") >>> lowerCaseFirst} + toJSON = + JSON.genericToJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_Holder") >>> lowerCaseFirst} makeLenses ''Holder @@ -45,12 +49,16 @@ data MaybeHolder t = MaybeHolder deriving (Eq, Show, Generic) instance (FromJSON t) => FromJSON (MaybeHolder t) where - parseJSON = JSON.genericParseJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_MaybeHolder") >>> lowerCaseFirst} + parseJSON = + JSON.genericParseJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_MaybeHolder") >>> lowerCaseFirst} instance (ToJSON t) => ToJSON (MaybeHolder t) where - toJSON = JSON.genericToJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_MaybeHolder") >>> lowerCaseFirst} + toJSON = + JSON.genericToJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_MaybeHolder") >>> lowerCaseFirst} makeLenses ''MaybeHolder diff --git a/test/reference-output/importExample.hs b/test/reference-output/importExample.hs index 4f2b3dd..4706dc3 100644 --- a/test/reference-output/importExample.hs +++ b/test/reference-output/importExample.hs @@ -25,12 +25,16 @@ data HoldsSomething t = HoldsSomething deriving (Eq, Show, Generic) instance (FromJSON t) => FromJSON (HoldsSomething t) where - parseJSON = JSON.genericParseJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_HoldsSomething") >>> lowerCaseFirst} + parseJSON = + JSON.genericParseJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_HoldsSomething") >>> lowerCaseFirst} instance (ToJSON t) => ToJSON (HoldsSomething t) where - toJSON = JSON.genericToJSON - JSON.defaultOptions {JSON.fieldLabelModifier = drop @[] (length "_HoldsSomething") >>> lowerCaseFirst} + toJSON = + JSON.genericToJSON + JSON.defaultOptions + {JSON.fieldLabelModifier = drop @[] (length "_HoldsSomething") >>> lowerCaseFirst} makeLenses ''HoldsSomething From 287a1d4516d9e0d96cf433b4ef97bfc0ad31d9f6 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 22:01:06 +0300 Subject: [PATCH 4/7] testing(hs): add `basicEnumeration` --- src/CodeGeneration/Haskell.hs | 2 +- test/ParsingSpec.hs | 5 +++ test/reference-output/basicEnumeration.hs | 42 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/reference-output/basicEnumeration.hs diff --git a/src/CodeGeneration/Haskell.hs b/src/CodeGeneration/Haskell.hs index 6558b91..8ec640b 100644 --- a/src/CodeGeneration/Haskell.hs +++ b/src/CodeGeneration/Haskell.hs @@ -220,7 +220,7 @@ outputEnumeration name values' = ) & Text.intercalate "\n" outputLiteral (LiteralString s) = mconcat ["String \"", s, "\""] - outputLiteral (LiteralInteger i) = mconcat ["Number $ fromInteger", tshow i] + outputLiteral (LiteralInteger i) = mconcat ["Number $ fromInteger ", tshow i] outputLiteral (LiteralFloat f) = mconcat ["Number ", tshow f] outputLiteral (LiteralBoolean b) = mconcat ["Boolean ", tshow b] fromJsonOutput = diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index 6d080dd..b9ac91f 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -32,6 +32,7 @@ data HaskellReferenceOutput = HaskellReferenceOutput basicUnion :: !Text, genericStruct :: !Text, genericUnion :: !Text, + basicEnumeration :: !Text, basic :: !Text, import' :: !Text, hasGeneric :: !Text, @@ -118,6 +119,7 @@ haskellReferenceOutput = do basicUnion <- basicUnionReferenceOutput "hs" genericStruct <- genericStructReferenceOutput "hs" genericUnion <- genericUnionReferenceOutput "hs" + basicEnumeration <- basicEnumerationReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" @@ -129,6 +131,7 @@ haskellReferenceOutput = do basicUnion, genericStruct, genericUnion, + basicEnumeration, basic, import', hasGeneric, @@ -285,6 +288,7 @@ spec hsBasicUnion hsGenericStruct hsGenericUnion + hsBasicEnumeration hsBasic hsImport hsHasGeneric @@ -657,6 +661,7 @@ spec enumerationModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/basicEnumeration.gotyno"] TypeScript.outputModule enumerationModule `shouldBe` tsBasicEnumeration + Haskell.outputModule enumerationModule `shouldBe` hsBasicEnumeration Kotlin.outputModule enumerationModule `shouldBe` ktBasicEnumeration DLang.outputModule enumerationModule `shouldBe` dBasicEnumeration diff --git a/test/reference-output/basicEnumeration.hs b/test/reference-output/basicEnumeration.hs new file mode 100644 index 0000000..e4a9fce --- /dev/null +++ b/test/reference-output/basicEnumeration.hs @@ -0,0 +1,42 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.BasicEnumeration where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data StringValues + = StringValuesFirst + | StringValuesSecond + | StringValuesThird + | StringValuesFourth + deriving (Eq, Show, Generic) + +instance ToJSON StringValues where + toJSON StringValuesFirst = String "first" + toJSON StringValuesSecond = String "second" + toJSON StringValuesThird = String "Third" + toJSON StringValuesFourth = String "Fourth" + +instance FromJSON StringValues where + parseJSON = Helpers.enumFromJSON [(String "first", StringValuesFirst), (String "second", StringValuesSecond), (String "Third", StringValuesThird), (String "Fourth", StringValuesFourth)] + +data IntValues + = IntValuesFirst + | IntValuesSecond + | IntValuesThird + | IntValuesFourth + deriving (Eq, Show, Generic) + +instance ToJSON IntValues where + toJSON IntValuesFirst = Number $ fromInteger 1 + toJSON IntValuesSecond = Number $ fromInteger 2 + toJSON IntValuesThird = Number $ fromInteger 3 + toJSON IntValuesFourth = Number $ fromInteger 4 + +instance FromJSON IntValues where + parseJSON = Helpers.enumFromJSON [(Number $ fromInteger 1, IntValuesFirst), (Number $ fromInteger 2, IntValuesSecond), (Number $ fromInteger 3, IntValuesThird), (Number $ fromInteger 4, IntValuesFourth)] From 123b04b90c4a2db5b8a3ab56b04c846cdeabb924 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 22:06:04 +0300 Subject: [PATCH 5/7] testing(hs): add `basicImport` --- test/ParsingSpec.hs | 5 +++++ test/reference-output/basicImport.hs | 29 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/reference-output/basicImport.hs diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index b9ac91f..a5f3216 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -33,6 +33,7 @@ data HaskellReferenceOutput = HaskellReferenceOutput genericStruct :: !Text, genericUnion :: !Text, basicEnumeration :: !Text, + basicImport :: !Text, basic :: !Text, import' :: !Text, hasGeneric :: !Text, @@ -120,6 +121,7 @@ haskellReferenceOutput = do genericStruct <- genericStructReferenceOutput "hs" genericUnion <- genericUnionReferenceOutput "hs" basicEnumeration <- basicEnumerationReferenceOutput "hs" + basicImport <- basicImportReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" @@ -132,6 +134,7 @@ haskellReferenceOutput = do genericStruct, genericUnion, basicEnumeration, + basicImport, basic, import', hasGeneric, @@ -289,6 +292,7 @@ spec hsGenericStruct hsGenericUnion hsBasicEnumeration + hsBasicImport hsBasic hsImport hsHasGeneric @@ -670,6 +674,7 @@ spec (getRight >>> PartialList.last) <$> parseModules ["examples/basicStruct.gotyno", "examples/basicImport.gotyno"] TypeScript.outputModule basicImportModule `shouldBe` tsBasicImport + Haskell.outputModule basicImportModule `shouldBe` hsBasicImport Kotlin.outputModule basicImportModule `shouldBe` ktBasicImport DLang.outputModule basicImportModule `shouldBe` dBasicImport diff --git a/test/reference-output/basicImport.hs b/test/reference-output/basicImport.hs new file mode 100644 index 0000000..ab33894 --- /dev/null +++ b/test/reference-output/basicImport.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.BasicImport where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +import qualified GotynoOutput.BasicStruct as BasicStruct + +data StructUsingImport = StructUsingImport + { _structUsingImportField :: BasicStruct.BasicStruct + } + deriving (Eq, Show, Generic) + +deriveLensAndJSON ''StructUsingImport + +data UnionUsingImport + = ConstructorWithPayload BasicStruct.BasicStruct + deriving (Eq, Show, Generic) + +instance ToJSON UnionUsingImport where + toJSON = JSON.genericToJSON $ Helpers.gotynoOptions "type" + +instance FromJSON UnionUsingImport where + parseJSON = JSON.genericParseJSON $ Helpers.gotynoOptions "type" From c81a4a800d4a92a5d8fb271527d3f5beba3a8773 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sat, 15 Oct 2022 22:10:49 +0300 Subject: [PATCH 6/7] testing(hs): add `basicOptional` --- test/ParsingSpec.hs | 5 +++++ test/reference-output/basicOptional.hs | 31 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/reference-output/basicOptional.hs diff --git a/test/ParsingSpec.hs b/test/ParsingSpec.hs index a5f3216..7563b82 100644 --- a/test/ParsingSpec.hs +++ b/test/ParsingSpec.hs @@ -34,6 +34,7 @@ data HaskellReferenceOutput = HaskellReferenceOutput genericUnion :: !Text, basicEnumeration :: !Text, basicImport :: !Text, + basicOptional :: !Text, basic :: !Text, import' :: !Text, hasGeneric :: !Text, @@ -122,6 +123,7 @@ haskellReferenceOutput = do genericUnion <- genericUnionReferenceOutput "hs" basicEnumeration <- basicEnumerationReferenceOutput "hs" basicImport <- basicImportReferenceOutput "hs" + basicOptional <- basicOptionalReferenceOutput "hs" basic <- basicReferenceOutput "hs" import' <- importReferenceOutput "hs" hasGeneric <- hasGenericReferenceOutput "hs" @@ -135,6 +137,7 @@ haskellReferenceOutput = do genericUnion, basicEnumeration, basicImport, + basicOptional, basic, import', hasGeneric, @@ -293,6 +296,7 @@ spec hsGenericUnion hsBasicEnumeration hsBasicImport + hsBasicOptional hsBasic hsImport hsHasGeneric @@ -682,6 +686,7 @@ spec basicOptionalModule <- (getRight >>> PartialList.head) <$> parseModules ["examples/basicOptional.gotyno"] TypeScript.outputModule basicOptionalModule `shouldBe` tsBasicOptional + Haskell.outputModule basicOptionalModule `shouldBe` hsBasicOptional Kotlin.outputModule basicOptionalModule `shouldBe` ktBasicOptional DLang.outputModule basicOptionalModule `shouldBe` dBasicOptional diff --git a/test/reference-output/basicOptional.hs b/test/reference-output/basicOptional.hs new file mode 100644 index 0000000..485d914 --- /dev/null +++ b/test/reference-output/basicOptional.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} + +module GotynoOutput.BasicOptional where + +import Data.Aeson (FromJSON (..), ToJSON (..)) +import qualified Data.Aeson as JSON +import GHC.Generics (Generic) +import qualified Gotyno.Helpers as Helpers +import Qtility + +data HasOptionalString = HasOptionalString + { _hasOptionalStringStringField :: (Maybe Text), + _hasOptionalStringOptionalArrayField :: (Maybe [Int]), + _hasOptionalStringArrayOfOptionalField :: [(Maybe Int)] + } + deriving (Eq, Show, Generic) + +deriveLensAndJSON ''HasOptionalString + +data HasOptionalConstructor + = DoesNot Int + | Does (Maybe Int) + | HasOptionalStruct (Maybe HasOptionalString) + deriving (Eq, Show, Generic) + +instance ToJSON HasOptionalConstructor where + toJSON = JSON.genericToJSON $ Helpers.gotynoOptions "type" + +instance FromJSON HasOptionalConstructor where + parseJSON = JSON.genericParseJSON $ Helpers.gotynoOptions "type" From 6fd68dceef79fd8967a0bed2b9308d40ab5be133 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Sun, 16 Oct 2022 00:15:22 +0300 Subject: [PATCH 7/7] changelog: add entry for 2.2.2 --- CHANGELOG.md | 6 ++++++ package.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49cc732..b04518a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2.2.2 + +### Fixes + +- Fixed bug in Haskell number literal output + ## 2.2.1 ### Fixes diff --git a/package.yaml b/package.yaml index 3374070..eef6235 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: gotyno-hs -version: 2.2.1 +version: 2.2.2 synopsis: A type definition compiler supporting multiple output languages. description: Compiles type definitions into F#, TypeScript and Python, with validators, decoders and encoders. license: BSD2