-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from MercuryTechnologies/tad/generic-sum-types
Fix codegen for sum-of-products with generic parameters
- Loading branch information
Showing
5 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@JsonClassDiscriminator("direction") | ||
@Serializable | ||
sealed class CursorInput<A> { | ||
@Serializable | ||
@SerialName("nextPage") | ||
data class NextPage<A>(val key: A?) : CursorInput<A>() | ||
|
||
@Serializable | ||
@SerialName("previousPage") | ||
data class PreviousPage<A>(val key: A) : CursorInput<A>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum CursorInput<A: Hashable & Codable>: CaseIterable, Hashable, Codable { | ||
case nextPage(A?) | ||
case previousPage(A) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module SumOfProductWithTypeParameterSpec where | ||
|
||
import Common | ||
import Data.List (stripPrefix) | ||
import Data.Maybe | ||
import Moat | ||
import Test.Hspec | ||
import Test.Hspec.Golden | ||
import Prelude hiding (Enum) | ||
|
||
data CursorInput a | ||
= CursorInputNextPage (Maybe a) | ||
| CursorInputPreviousPage a | ||
|
||
mobileGenWith | ||
( defaultOptions | ||
{ constructorModifier = \body -> fromMaybe body (stripPrefix "CursorInput" body) | ||
, dataAnnotations = [Serializable, SerialName] | ||
, dataProtocols = [OtherProtocol "CaseIterable", Hashable, Codable] | ||
, sumOfProductEncodingOptions = | ||
SumOfProductEncodingOptions | ||
{ encodingStyle = TaggedObjectStyle | ||
, sumAnnotations = [RawAnnotation "JsonClassDiscriminator(\"direction\")"] | ||
, contentsFieldName = "key" | ||
, tagFieldName = "direction" | ||
} | ||
} | ||
) | ||
''CursorInput | ||
|
||
spec :: Spec | ||
spec = | ||
describe "stays golden" $ do | ||
let moduleName = "SumOfProductWithTypeParameterSpec" | ||
it "kotlin" $ | ||
defaultGolden ("kotlin" <> moduleName) (showKotlin @(CursorInput _)) | ||
it "swift" $ | ||
defaultGolden ("swift" <> moduleName) (showSwift @(CursorInput _)) |