test: Evaluate tactic context

This commit is contained in:
Leni Aniva 2024-06-25 16:18:31 -04:00
parent c0124b347f
commit 58f9d72288
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
2 changed files with 45 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import Pantograph.Goal import Pantograph.Goal
import Pantograph.Library import Pantograph.Library
import Pantograph.Protocol import Pantograph.Protocol
import Pantograph.Condensed
import Lean import Lean
import LSpec import LSpec
@ -10,12 +11,7 @@ namespace Pantograph
deriving instance Repr for Expr deriving instance Repr for Expr
-- Use strict equality check for expressions -- Use strict equality check for expressions
--instance : BEq Expr := ⟨Expr.equal⟩ instance : BEq Expr := ⟨Expr.equal⟩
instance (priority := 80) (x y : Expr) : LSpec.Testable (x.equal y) :=
if h : Expr.equal x y then
.isTrue h
else
.isFalse h $ s!"Expected to be equalaaa: '{x.dbgToString}' and '{y.dbgToString}'"
def uniq (n: Nat): Name := .num (.str .anonymous "_uniq") n def uniq (n: Nat): Name := .num (.str .anonymous "_uniq") n
@ -25,6 +21,7 @@ def Goal.devolatilizeVars (goal: Goal): Goal :=
{ {
goal with goal with
vars := goal.vars.map removeInternalAux, vars := goal.vars.map removeInternalAux,
} }
where removeInternalAux (v: Variable): Variable := where removeInternalAux (v: Variable): Variable :=
{ {
@ -47,6 +44,24 @@ deriving instance DecidableEq, Repr for InteractionError
deriving instance DecidableEq, Repr for Option deriving instance DecidableEq, Repr for Option
end Protocol end Protocol
namespace Condensed
deriving instance BEq, Repr for LocalDecl
deriving instance BEq, Repr for Goal
protected def LocalDecl.devolatilize (decl: LocalDecl): LocalDecl :=
{
decl with fvarId := { name := .anonymous }
}
protected def Goal.devolatilize (goal: Goal): Goal :=
{
goal with
mvarId := { name := .anonymous },
context := goal.context.map LocalDecl.devolatilize
}
end Condensed
def TacticResult.toString : TacticResult → String def TacticResult.toString : TacticResult → String
| .success state => s!".success ({state.goals.length} goals)" | .success state => s!".success ({state.goals.length} goals)"
| .failure messages => | .failure messages =>

View File

@ -25,12 +25,33 @@ def test_eval (env: Environment): IO LSpec.TestSeq :=
let target: Expr := mkAnd let target: Expr := mkAnd
(mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩)) (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩))
(mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩)) (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩))
let test := LSpec.test "goals before" ((← goal.mvarId!.getType) == target) let h := .fvar ⟨uniq 8⟩
let test := LSpec.test "goals before" ((← toCondensedGoal goal.mvarId!).devolatilize == {
context := #[
{ userName := `p, type := .sort 0 },
{ userName := `q, type := .sort 0 },
{ userName := `h, type := h}
],
target,
})
tests := tests ++ test tests := tests ++ test
let tactic := Tactic.evaluate `h2 e let tactic := Tactic.evaluate `h2 e
let m := .mvar ⟨uniq 13⟩
let test ← runTermElabMInMeta do let test ← runTermElabMInMeta do
let newGoals ← runTacticOnMVar tactic goal.mvarId! let [goal] ← runTacticOnMVar tactic goal.mvarId! | panic! "Incorrect goal number"
pure $ LSpec.test "goals after" ((← newGoals.head!.getType) == target) pure $ LSpec.test "goals after" ((← toCondensedGoal goal).devolatilize == {
context := #[
{ userName := `p, type := .sort 0 },
{ userName := `q, type := .sort 0 },
{ userName := `h, type := h},
{
userName := `h2,
type := mkOr h m,
value? := .some $ mkApp3 (mkConst `Or.inl) h m (.fvar ⟨uniq 10⟩)
}
],
target,
})
tests := tests ++ test tests := tests ++ test
return tests return tests