Skip to content

Commit 8fcf33e

Browse files
committed
new: add additional file
1 parent d246376 commit 8fcf33e

File tree

6 files changed

+87
-15
lines changed

6 files changed

+87
-15
lines changed

lambda-buffers-compiler/test/Test/KindCheck.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,5 @@ testArrowFoldHHK =
188188
foldWithArrowToType [ty, (ty :->: ty) :->: ty, ty]
189189
@?= (ty :->: (((ty :->: ty) :->: ty) :->: (ty :->: ty)))
190190

191-
-- | TyDef to Kind Canonical representation - sums not folded - therefore we get constructor granularity. Might use in a different implementation for more granular errors.
192191
lVar :: Text -> Type
193192
lVar = Var . LocalRef
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Test.KindCheck.Errors (testGKindCheckErrors) where
2+
3+
import LambdaBuffers.Compiler.KindCheck (check_)
4+
import LambdaBuffers.Compiler.ProtoCompat.Types (CompilerError (CompKindCheckError), KindCheckError (UnboundTyRefError, UnboundTyVarError))
5+
import Test.Tasty (TestTree, testGroup)
6+
import Test.Tasty.HUnit (testCase, (@?=))
7+
import Test.Utils.CompilerInput (compilerInput'undefinedForeignTyRef, compilerInput'undefinedVariable)
8+
import Test.Utils.TyDef (tyDef'undefinedForeignTyRef, tyDef'undefinedForeignTyRef'TyRef, tyDef'undefinedVar, tyDef'undefinedVar'var)
9+
10+
testGKindCheckErrors :: TestTree
11+
testGKindCheckErrors = testGroup "Kind Check Error Tests" [undefinedVariable, undefinedLocalTyRef]
12+
13+
undefinedVariable :: TestTree
14+
undefinedVariable =
15+
testCase "Catch undefined(free) variable in Type Definition." $
16+
check_ compilerInput'undefinedVariable @?= Left (CompKindCheckError $ UnboundTyVarError tyDef'undefinedVar tyDef'undefinedVar'var)
17+
18+
undefinedLocalTyRef :: TestTree
19+
undefinedLocalTyRef =
20+
testCase "Catch undefined Foreign TyRef in Type Definition." $
21+
check_ compilerInput'undefinedForeignTyRef @?= Left (CompKindCheckError $ UnboundTyRefError tyDef'undefinedForeignTyRef tyDef'undefinedForeignTyRef'TyRef)

lambda-buffers-compiler/test/Test/Utils/CompilerInput.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module Test.Utils.CompilerInput (
33
compilerInput'maybe,
44
compilerInput'undefinedVariable,
55
compilerInput'undefinedLocalTyRef,
6+
compilerInput'undefinedForeignTyRef,
67
) where
78

89
import LambdaBuffers.Compiler.ProtoCompat qualified as P
910
import Test.Utils.Constructors (_CompilerInput)
10-
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedVar, module'undefinedlocalTyRef)
11+
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedForeignTyRef, module'undefinedLocalTyRef, module'undefinedVar)
1112

1213
-- | Compiler Input containing 1 module with 1 definition - Maybe.
1314
compilerInput'maybe :: P.CompilerInput
@@ -23,4 +24,8 @@ compilerInput'undefinedVariable = _CompilerInput [module'undefinedVar]
2324

2425
-- | Contains 1 undefined Local TyRef.
2526
compilerInput'undefinedLocalTyRef :: P.CompilerInput
26-
compilerInput'undefinedLocalTyRef = _CompilerInput [module'undefinedlocalTyRef]
27+
compilerInput'undefinedLocalTyRef = _CompilerInput [module'undefinedLocalTyRef]
28+
29+
-- | Contains 1 undefined Foreign TyRef.
30+
compilerInput'undefinedForeignTyRef :: P.CompilerInput
31+
compilerInput'undefinedForeignTyRef = _CompilerInput [module'undefinedForeignTyRef]

lambda-buffers-compiler/test/Test/Utils/Constructors.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Test.Utils.Constructors (
2121
_SourceInfo,
2222
_LocalRef,
2323
_LocalRef',
24+
_ForeignRef',
2425
) where
2526

2627
import Control.Lens ((^.))
@@ -147,3 +148,14 @@ _LocalRef' x s =
147148
{ P.tyName = P.TyName {P.name = x, sourceInfo = s}
148149
, P.sourceInfo = s
149150
}
151+
152+
_ForeignRef :: Text -> [Text] -> P.ForeignRef
153+
_ForeignRef n m = _ForeignRef' n (_ModuleName m) P.defSourceInfo
154+
155+
_ForeignRef' :: Text -> P.ModuleName -> P.SourceInfo -> P.ForeignRef
156+
_ForeignRef' x m s =
157+
P.ForeignRef
158+
{ P.tyName = P.TyName {P.name = x, sourceInfo = s}
159+
, P.moduleName = m
160+
, P.sourceInfo = s
161+
}

lambda-buffers-compiler/test/Test/Utils/Module.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar, module'undefinedlocalTyRef) where
1+
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar, module'undefinedLocalTyRef, module'undefinedForeignTyRef) where
22

33
import LambdaBuffers.Compiler.ProtoCompat qualified as P
44
import Test.Utils.Constructors (_Module, _ModuleName)
5-
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe, tyDef'undefinedVar, tyDef'undefinedlocalTyRef)
5+
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe, tyDef'undefinedForeignTyRef, tyDef'undefinedLocalTyRef, tyDef'undefinedVar)
66

77
-- _Module mn tds cds ins =
88

@@ -34,5 +34,13 @@ module'undefinedVar = _Module (_ModuleName ["Module"]) [tyDef'undefinedVar] memp
3434
^^^
3535
Should fail as Baz is a local undefined Ty Ref.
3636
-}
37-
module'undefinedlocalTyRef :: P.Module
38-
module'undefinedlocalTyRef = _Module (_ModuleName ["Module"]) [tyDef'undefinedlocalTyRef] mempty mempty
37+
module'undefinedLocalTyRef :: P.Module
38+
module'undefinedLocalTyRef = _Module (_ModuleName ["Module"]) [tyDef'undefinedLocalTyRef] mempty mempty
39+
40+
{- | 1 Module containing
41+
Foo b = Bar Module.Foreign.Baz b
42+
^^^^^^^^^^^^^^^^^^
43+
Should fail as Baz is a foreign undefined Ty Ref.
44+
-}
45+
module'undefinedForeignTyRef :: P.Module
46+
module'undefinedForeignTyRef = _Module (_ModuleName ["Module"]) [tyDef'undefinedForeignTyRef] mempty mempty

lambda-buffers-compiler/test/Test/Utils/TyDef.hs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ module Test.Utils.TyDef (
33
tyDef'incoherent,
44
tyDef'undefinedVar,
55
tyDef'undefinedVar'var,
6-
tyDef'undefinedlocalTyRef,
7-
tyDef'undefinedlocalTyRef'localTyRef,
6+
tyDef'undefinedLocalTyRef,
7+
tyDef'undefinedLocalTyRef'TyRef,
8+
tyDef'undefinedForeignTyRef,
9+
tyDef'undefinedForeignTyRef'TyRef,
810
) where
911

1012
import LambdaBuffers.Compiler.ProtoCompat.Types (Ty (TyVarI))
1113
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P
1214
import Test.Utils.Constructors (
15+
_ForeignRef',
1316
_LocalRef',
17+
_ModuleName,
1418
_SourceInfo,
1519
_TupleI,
1620
_TyAbs,
@@ -60,24 +64,47 @@ tyDef'undefinedVar'var :: P.TyVar
6064
tyDef'undefinedVar'var = _TyVar' "b" (_SourceInfo 1 2)
6165

6266
-- | Foo a = Foo Baz b
63-
tyDef'undefinedlocalTyRef :: P.TyDef
64-
tyDef'undefinedlocalTyRef =
67+
tyDef'undefinedLocalTyRef :: P.TyDef
68+
tyDef'undefinedLocalTyRef =
6569
_TyDef
6670
(_TyName "Foo")
6771
( _TyAbs
6872
[("a", _Type)]
6973
[
7074
( "Foo"
7175
, _TupleI
72-
[ P.TyRefI tyDef'undefinedlocalTyRef'localTyRef
76+
[ P.TyRefI tyDef'undefinedLocalTyRef'TyRef
7377
, _TyVarI "a"
7478
]
7579
)
7680
]
7781
)
7882

79-
{- | The undefined Local TyRef (i.e. "Baz") in tyDef'undefinedlocalTyRef.
83+
{- | The undefined Local TyRef (i.e. "Baz") in tyDef'undefinedLocalTyRef.
8084
Exported to see if the test identifies it correctly.
8185
-}
82-
tyDef'undefinedlocalTyRef'localTyRef :: P.TyRef
83-
tyDef'undefinedlocalTyRef'localTyRef = P.LocalI $ _LocalRef' "Baz" (_SourceInfo 1 2)
86+
tyDef'undefinedLocalTyRef'TyRef :: P.TyRef
87+
tyDef'undefinedLocalTyRef'TyRef = P.LocalI $ _LocalRef' "Baz" (_SourceInfo 1 2)
88+
89+
-- | Foo a = Foo Baz b
90+
tyDef'undefinedForeignTyRef :: P.TyDef
91+
tyDef'undefinedForeignTyRef =
92+
_TyDef
93+
(_TyName "Foo")
94+
( _TyAbs
95+
[("a", _Type)]
96+
[
97+
( "Foo"
98+
, _TupleI
99+
[ P.TyRefI tyDef'undefinedForeignTyRef'TyRef
100+
, _TyVarI "a"
101+
]
102+
)
103+
]
104+
)
105+
106+
{- | The undefined Local TyRef (i.e. "Baz") in tyDef'undefinedLocalTyRef.
107+
Exported to see if the test identifies it correctly.
108+
-}
109+
tyDef'undefinedForeignTyRef'TyRef :: P.TyRef
110+
tyDef'undefinedForeignTyRef'TyRef = P.ForeignI $ _ForeignRef' "Baz" (_ModuleName ["Foreign", "Module"]) (_SourceInfo 1 2)

0 commit comments

Comments
 (0)