-
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.
Propagate 'Codable' bounds through MoatData tyvars
- Loading branch information
Showing
10 changed files
with
96 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,3 @@ | ||
@Parcelize | ||
@Serializable | ||
value class LTree<A : Parcelable>(val value: List<A>) : Parcelable |
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,10 @@ | ||
/** | ||
* Non-empty, possibly infinite, multi-way trees; also known as *rose trees*. | ||
* | ||
* @param rootLabel label value | ||
* @param subForest zero or more child trees | ||
*/ | ||
data class Tree<A : Parcelable>( | ||
val rootLabel: A, | ||
val subForest: List<Tree<A>>, | ||
) : Parcelable |
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 @@ | ||
struct LTree<A: Codable>: CaseIterable, Hashable, Codable { | ||
typealias LTreeTag = Tagged<LTree, [A]> | ||
let value: LTreeTag | ||
} |
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,7 @@ | ||
/// Non-empty, possibly infinite, multi-way trees; also known as *rose trees*. | ||
struct Tree<A: Codable>: Codable { | ||
/// label value | ||
var rootLabel: A | ||
/// zero or more child trees | ||
var subForest: [Tree<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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
struct Data<A, B>: CaseIterable, Hashable, Codable { | ||
struct Data<A: Codable, B: Codable>: CaseIterable, Hashable, Codable { | ||
var field0: A | ||
var field1: B | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
struct Data<A>: CaseIterable, Hashable, Codable { | ||
struct Data<A: Codable>: CaseIterable, Hashable, Codable { | ||
var field0: 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,32 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
|
||
module GenericNewtypeSpec where | ||
|
||
import Common | ||
import Data.List.NonEmpty (NonEmpty) | ||
import Moat | ||
import Test.Hspec | ||
import Test.Hspec.Golden | ||
import Prelude | ||
|
||
newtype LTree a = LTree (NonEmpty a) | ||
deriving stock (Show, Eq) | ||
|
||
mobileGenWith | ||
( defaultOptions | ||
{ dataAnnotations = [Parcelize, Serializable] | ||
, dataInterfaces = [Parcelable] | ||
, dataProtocols = [OtherProtocol "CaseIterable", Hashable, Codable] | ||
, dataRawValue = Just Str | ||
} | ||
) | ||
''LTree | ||
|
||
spec :: Spec | ||
spec = | ||
describe "stays golden" $ do | ||
let moduleName = "GenericNewtypeSpec" | ||
it "swift" $ | ||
defaultGolden ("swift" <> moduleName) (showSwift @(LTree _)) | ||
it "kotlin" $ | ||
defaultGolden ("kotlin" <> moduleName) (showKotlin @(LTree _)) |
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,27 @@ | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module GenericStructSpec where | ||
|
||
import Common | ||
import Data.Tree (Tree) | ||
import Moat | ||
import Test.Hspec | ||
import Test.Hspec.Golden | ||
import Prelude | ||
|
||
mobileGenWith | ||
( defaultOptions | ||
{ dataInterfaces = [Parcelable] | ||
, dataProtocols = [Codable] | ||
} | ||
) | ||
''Tree | ||
|
||
spec :: Spec | ||
spec = | ||
describe "stays golden" $ do | ||
let moduleName = "GenericStructSpec" | ||
it "swift" $ | ||
defaultGolden ("swift" <> moduleName) (showSwift @(Tree _)) | ||
it "kotlin" $ | ||
defaultGolden ("kotlin" <> moduleName) (showKotlin @(Tree _)) |