Skip to content

Commit 684352a

Browse files
committed
new: test 1 undefined Local TyRef
1 parent 0d66ebf commit 684352a

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
module Test.Utils.CompilerInput (compilerInput'incoherent, compilerInput'maybe, compilerInput'undefinedVariable) where
1+
module Test.Utils.CompilerInput (
2+
compilerInput'incoherent,
3+
compilerInput'maybe,
4+
compilerInput'undefinedVariable,
5+
compilerInput'undefinedLocalTyRef,
6+
) where
27

38
import LambdaBuffers.Compiler.ProtoCompat qualified as P
49
import Test.Utils.Constructors (_CompilerInput)
5-
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedVar)
10+
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedVar, module'undefinedlocalTyRef)
611

712
-- | Compiler Input containing 1 module with 1 definition - Maybe.
813
compilerInput'maybe :: P.CompilerInput
@@ -15,3 +20,7 @@ compilerInput'incoherent = _CompilerInput [module'maybe, module'incoherent]
1520
-- | Contains 1 undefined variable.
1621
compilerInput'undefinedVariable :: P.CompilerInput
1722
compilerInput'undefinedVariable = _CompilerInput [module'undefinedVar]
23+
24+
-- | Contains 1 undefined Local TyRef.
25+
compilerInput'undefinedLocalTyRef :: P.CompilerInput
26+
compilerInput'undefinedLocalTyRef = _CompilerInput [module'undefinedlocalTyRef]

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Test.Utils.Constructors (
1919
_ModuleNamePart,
2020
_TyVarI',
2121
_SourceInfo,
22+
_LocalRef,
23+
_LocalRef',
2224
) where
2325

2426
import Control.Lens ((^.))
@@ -133,10 +135,15 @@ _TyDef :: P.TyName -> P.TyAbs -> P.TyDef
133135
_TyDef name ab = P.TyDef {P.tyName = name, P.tyAbs = ab, sourceInfo = P.defSourceInfo}
134136

135137
_TyRefILocal :: Text -> P.Ty
136-
_TyRefILocal x =
137-
P.TyRefI $
138-
P.LocalI $
139-
P.LocalRef
140-
{ P.tyName = P.TyName {P.name = x, sourceInfo = P.defSourceInfo}
141-
, P.sourceInfo = P.defSourceInfo
142-
}
138+
_TyRefILocal x = P.TyRefI $ P.LocalI $ _LocalRef x
139+
140+
_LocalRef :: Text -> P.LocalRef
141+
_LocalRef = flip _LocalRef' P.defSourceInfo
142+
143+
-- | LocalRef with Source Info - for error precision testing.
144+
_LocalRef' :: Text -> P.SourceInfo -> P.LocalRef
145+
_LocalRef' x s =
146+
P.LocalRef
147+
{ P.tyName = P.TyName {P.name = x, sourceInfo = s}
148+
, P.sourceInfo = s
149+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar) where
1+
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar, module'undefinedlocalTyRef) 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)
5+
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe, tyDef'undefinedVar, tyDef'undefinedlocalTyRef)
66

77
-- _Module mn tds cds ins =
88

@@ -28,3 +28,11 @@ module'incoherent = _Module (_ModuleName ["Module"]) [tyDef'maybe, tyDef'incoher
2828
-}
2929
module'undefinedVar :: P.Module
3030
module'undefinedVar = _Module (_ModuleName ["Module"]) [tyDef'undefinedVar] mempty mempty
31+
32+
{- | 1 Module containing
33+
Foo b = Bar Baz b
34+
^^^
35+
Should fail as Baz is a local undefined Ty Ref.
36+
-}
37+
module'undefinedlocalTyRef :: P.Module
38+
module'undefinedlocalTyRef = _Module (_ModuleName ["Module"]) [tyDef'undefinedlocalTyRef] mempty mempty

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
module Test.Utils.TyDef (tyDef'maybe, tyDef'incoherent, tyDef'undefinedVar, tyDef'undefinedVar'var) where
1+
module Test.Utils.TyDef (
2+
tyDef'maybe,
3+
tyDef'incoherent,
4+
tyDef'undefinedVar,
5+
tyDef'undefinedVar'var,
6+
tyDef'undefinedlocalTyRef,
7+
tyDef'undefinedlocalTyRef'localTyRef,
8+
) where
29

3-
import LambdaBuffers.Compiler.ProtoCompat qualified as P
410
import LambdaBuffers.Compiler.ProtoCompat.Types (Ty (TyVarI))
11+
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P
512
import Test.Utils.Constructors (
13+
_LocalRef',
614
_SourceInfo,
715
_TupleI,
816
_TyAbs,
@@ -45,6 +53,31 @@ tyDef'undefinedVar =
4553
(_TyName "Foo")
4654
(_TyAbs [] [("Bar", _TupleI [TyVarI tyDef'undefinedVar'var])])
4755

48-
-- | The undefined var in tyDef'undefinedVar - exported to see if the test identifies it correctly.
56+
{- | The undefined var (i.e. "b") in tyDef'undefinedVar.
57+
Exported to see if the test identifies it correctly.
58+
-}
4959
tyDef'undefinedVar'var :: P.TyVar
5060
tyDef'undefinedVar'var = _TyVar' "b" (_SourceInfo 1 2)
61+
62+
-- | Foo a = Foo Baz b
63+
tyDef'undefinedlocalTyRef :: P.TyDef
64+
tyDef'undefinedlocalTyRef =
65+
_TyDef
66+
(_TyName "Foo")
67+
( _TyAbs
68+
[("a", _Type)]
69+
[
70+
( "Foo"
71+
, _TupleI
72+
[ P.TyRefI tyDef'undefinedlocalTyRef'localTyRef
73+
, _TyVarI "a"
74+
]
75+
)
76+
]
77+
)
78+
79+
{- | The undefined Local TyRef (i.e. "Baz") in tyDef'undefinedlocalTyRef.
80+
Exported to see if the test identifies it correctly.
81+
-}
82+
tyDef'undefinedlocalTyRef'localTyRef :: P.TyRef
83+
tyDef'undefinedlocalTyRef'localTyRef = P.LocalI $ _LocalRef' "Baz" (_SourceInfo 1 2)

0 commit comments

Comments
 (0)