Skip to content

Commit 27f8eec

Browse files
committed
Add size-1 and size-2 tuples to TestBoilerplate.hs
1 parent 96653e1 commit 27f8eec

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

test/NoOmitNothingFields.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ $(testDeclarations "NoOmitNothingFields" (A.defaultOptions {omitNothingFields =
1313
allTests :: SpecWith ()
1414
allTests = describe "NoOmitNothingFields" $ do
1515
it "encodes as expected" $ do
16-
let decls = getTypeScriptDeclarations (Proxy :: Proxy Optional)
16+
let decls = getTypeScriptDeclarations (Proxy :: Proxy OptionalRecord)
1717

18-
decls `shouldBe` [TSTypeAlternatives "Optional" [] ["IOptional"] Nothing
19-
, TSInterfaceDeclaration "IOptional" [] [TSField False "optionalInt" "number | null" Nothing] Nothing]
18+
decls `shouldBe` [TSTypeAlternatives "OptionalRecord" [] ["IOptionalRecord"] Nothing
19+
, TSInterfaceDeclaration "IOptionalRecord" [] [TSField False "optionalInt" "number | null" Nothing] Nothing]
2020

2121
tests

test/OmitNothingFields.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ $(testDeclarations "OmitNothingFields" (A.defaultOptions {omitNothingFields=True
1313
main :: IO ()
1414
main = hspec $ describe "OmitNothingFields" $ do
1515
it "encodes as expected" $ do
16-
let decls = getTypeScriptDeclarations (Proxy :: Proxy Optional)
16+
let decls = getTypeScriptDeclarations (Proxy :: Proxy OptionalRecord)
1717

1818
decls `shouldBe` [TSInterfaceDeclaration {
19-
interfaceName = "Optional"
19+
interfaceName = "OptionalRecord"
2020
, interfaceGenericVariables = []
2121
, interfaceMembers = [
2222
TSField True "optionalInt" "number" Nothing

test/TestBoilerplate.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ data TwoField = TwoField { doubleInt :: Int, doubleString :: String }
2929
data Hybrid = HybridSimple Int | HybridRecord { hybridString :: String }
3030
data TwoConstructor = Con1 { con1String :: String } | Con2 { con2String :: String, con2Int :: Int }
3131
data Complex a = Nullary | Unary Int | Product String Char a | Record { testOne :: Int, testTwo :: Bool, testThree :: Complex a} deriving Eq
32-
data Optional = Optional {optionalInt :: Maybe Int}
32+
data OptionalRecord = OptionalRecord {optionalInt :: Maybe Int}
33+
data OptionalTuple1 = OptionalTuple1 (Maybe Int)
34+
data OptionalTuple2 = OptionalTuple2 String (Maybe Int)
3335
data AesonTypes = AesonTypes { aesonValue :: A.Value, aesonObject :: A.Object }
3436
data Numbers = Numbers {
3537
natural :: Natural
@@ -87,7 +89,9 @@ testDeclarations testName aesonOptions = do
8789
deriveInstances ''Hybrid
8890
deriveInstances ''TwoConstructor
8991
deriveInstances ''Complex
90-
deriveInstances ''Optional
92+
deriveInstances ''OptionalRecord
93+
deriveInstances ''OptionalTuple1
94+
deriveInstances ''OptionalTuple2
9195
deriveInstances ''AesonTypes
9296
deriveInstances ''Numbers
9397
deriveInstances ''FancyFunctors
@@ -113,8 +117,14 @@ testDeclarations testName aesonOptions = do
113117
, (getTypeScriptType (Proxy :: Proxy (Complex Int)), A.encode (Product "asdf" 'g' 42 :: Complex Int))
114118
, (getTypeScriptType (Proxy :: Proxy (Complex Int)), A.encode ((Record { testOne = 3, testTwo = True, testThree = Product "test" 'A' 123}) :: Complex Int))
115119

116-
, (getTypeScriptType (Proxy :: Proxy Optional), A.encode (Optional { optionalInt = Nothing }))
117-
, (getTypeScriptType (Proxy :: Proxy Optional), A.encode (Optional { optionalInt = Just 1 }))
120+
, (getTypeScriptType (Proxy :: Proxy OptionalRecord), A.encode (OptionalRecord { optionalInt = Nothing }))
121+
, (getTypeScriptType (Proxy :: Proxy OptionalRecord), A.encode (OptionalRecord { optionalInt = Just 1 }))
122+
123+
, (getTypeScriptType (Proxy :: Proxy OptionalTuple1), A.encode (OptionalTuple1 Nothing))
124+
, (getTypeScriptType (Proxy :: Proxy OptionalTuple1), A.encode (OptionalTuple1 (Just 1)))
125+
126+
, (getTypeScriptType (Proxy :: Proxy OptionalTuple2), A.encode (OptionalTuple2 "asdf" Nothing))
127+
, (getTypeScriptType (Proxy :: Proxy OptionalTuple2), A.encode (OptionalTuple2 "asdf" (Just 1)))
118128

119129
, (getTypeScriptType (Proxy :: Proxy AesonTypes), A.encode (AesonTypes {
120130
aesonValue = A.object [("foo" :: AesonKey, A.Number 42)]
@@ -133,7 +143,9 @@ testDeclarations testName aesonOptions = do
133143
<> getTypeScriptDeclarations (Proxy :: Proxy Hybrid)
134144
<> getTypeScriptDeclarations (Proxy :: Proxy TwoConstructor)
135145
<> getTypeScriptDeclarations (Proxy :: Proxy (Complex T))
136-
<> getTypeScriptDeclarations (Proxy :: Proxy Optional)
146+
<> getTypeScriptDeclarations (Proxy :: Proxy OptionalRecord)
147+
<> getTypeScriptDeclarations (Proxy :: Proxy OptionalTuple1)
148+
<> getTypeScriptDeclarations (Proxy :: Proxy OptionalTuple2)
137149
<> getTypeScriptDeclarations (Proxy :: Proxy AesonTypes)
138150
<> getTypeScriptDeclarations (Proxy :: Proxy Numbers)
139151
<> getTypeScriptDeclarations (Proxy :: Proxy FancyFunctors)

0 commit comments

Comments
 (0)