Skip to content

Commit

Permalink
[ test ] Add some simpler tests with implicit args of derived types
Browse files Browse the repository at this point in the history
  • Loading branch information
buzden committed Aug 28, 2024
1 parent b893ecd commit 8e1cc4f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/derivation/core/norec t-pi->.. noext 005/DerivedGen.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module DerivedGen

import Data.Fin

import Deriving.Show

import RunDerivedGen

%default total

%language ElabReflection

data FinEq : Fin n -> Fin n -> Type where
Here : FinEq FZ FZ
These : FinEq n m -> FinEq (FS n) (FS m)

data X : (n : Nat) -> Fin n -> Fin n -> Type where
MkX : (i1, i2 : Fin n) -> (i1 `FinEq` i2) -> X n i1 i2

%hint ShowFinEq : {0 a, b : Fin n} -> Show (FinEq a b); ShowFinEq = %runElab derive

Show (X n i1 i2) where
show $ MkX i1 i2 prf = "MkX \{show i1} \{show i2} \{show prf}"

checkedGen : Fuel -> (n : Nat) -> (i1 : Fin n) -> (i2 : Fin n) -> Gen MaybeEmpty (X n i1 i2)
checkedGen = deriveGen

main : IO ()
main = runGs
[ G $ \fl => checkedGen fl 3 0 1
, G $ \fl => checkedGen fl 3 1 1
, G $ \fl => checkedGen fl 3 2 1
, G $ \fl => checkedGen fl 3 2 2
]
1 change: 1 addition & 0 deletions tests/derivation/core/norec t-pi->.. noext 005/derive.ipkg
12 changes: 12 additions & 0 deletions tests/derivation/core/norec t-pi->.. noext 005/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1/2: Building RunDerivedGen (RunDerivedGen.idr)
2/2: Building DerivedGen (DerivedGen.idr)
Error: While processing right hand side of checkedGen. Error during reflection: Named implicit applications (like to `DerivedGen.FinEq`) are not supported yet

DerivedGen:14:11--14:22
10 |
11 | %language ElabReflection
12 |
13 | data FinEq : Fin n -> Fin n -> Type where
14 | Here : FinEq FZ FZ
^^^^^^^^^^^

1 change: 1 addition & 0 deletions tests/derivation/core/norec t-pi->.. noext 005/run
41 changes: 41 additions & 0 deletions tests/derivation/core/norec t-pi->.. w_ext 003/DerivedGen.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module DerivedGen

import Data.Fin

import Deriving.Show

import RunDerivedGen

%default total

%language ElabReflection

data FinEq : Fin n -> Fin n -> Type where
Here : FinEq FZ FZ
These : FinEq n m -> FinEq (FS n) (FS m)

data X : (n : Nat) -> Fin n -> Fin n -> Type where
MkX : (i1, i2 : Fin n) -> (i1 `FinEq` i2) -> X n i1 i2

%hint ShowFinEq : {0 a, b : Fin n} -> Show (FinEq a b); ShowFinEq = %runElab derive

Show (X n i1 i2) where
show $ MkX i1 i2 prf = "MkX \{show i1} \{show i2} \{show prf}"

checkedGen : Fuel -> (Fuel -> {n : Nat} -> (i1, i2 : Fin n) -> Gen MaybeEmpty $ FinEq i1 i2) =>
(n : Nat) -> (i1 : Fin n) -> (i2 : Fin n) -> Gen MaybeEmpty (X n i1 i2)
checkedGen = deriveGen

genFinEq : Fuel -> {n : Nat} -> (i1, i2 : Fin n) -> Gen MaybeEmpty $ FinEq i1 i2
genFinEq _ FZ FZ = pure Here
genFinEq fl (FS y) (FS z) = These <$> genFinEq fl y z
genFinEq _ FZ (FS _) = empty
genFinEq _ (FS _) FZ = empty

main : IO ()
main = runGs
[ G $ \fl => checkedGen @{genFinEq} fl 3 0 1
, G $ \fl => checkedGen @{genFinEq} fl 3 1 1
, G $ \fl => checkedGen @{genFinEq} fl 3 2 1
, G $ \fl => checkedGen @{genFinEq} fl 3 2 2
]
1 change: 1 addition & 0 deletions tests/derivation/core/norec t-pi->.. w_ext 003/derive.ipkg
12 changes: 12 additions & 0 deletions tests/derivation/core/norec t-pi->.. w_ext 003/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1/2: Building RunDerivedGen (RunDerivedGen.idr)
2/2: Building DerivedGen (DerivedGen.idr)
Error: While processing right hand side of checkedGen. Error during reflection: Target types with implicit type parameters are not supported yet

DerivedGen:25:81--25:92
21 |
22 | Show (X n i1 i2) where
23 | show $ MkX i1 i2 prf = "MkX \{show i1} \{show i2} \{show prf}"
24 |
25 | checkedGen : Fuel -> (Fuel -> {n : Nat} -> (i1, i2 : Fin n) -> Gen MaybeEmpty $ FinEq i1 i2) =>
^^^^^^^^^^^

1 change: 1 addition & 0 deletions tests/derivation/core/norec t-pi->.. w_ext 003/run

0 comments on commit 8e1cc4f

Please sign in to comment.