-
Notifications
You must be signed in to change notification settings - Fork 2
/
InternalTests.lean
102 lines (82 loc) · 2.94 KB
/
InternalTests.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import SubVerso.Examples
import SubVerso.Highlighting.Highlighted
/-! These are SubVerso tests that don't involve a subprocess, to make development easier. -/
open SubVerso Examples
partial def SubVerso.Highlighting.Highlighted.asString (hl : Highlighted) : String := Id.run do
let mut out := ""
match hl with
| .seq hls =>
for x in hls.map asString do
out := out ++ x
| .span _ hl' =>
out := out ++ hl'.asString
| .tactics _ _ _ hl' =>
out := out ++ hl'.asString
| .point .. => pure ()
| .text s => out := out ++ s
| .token t => out := out ++ t.content
out
partial def SubVerso.Highlighting.Highlighted.proofStates (hl : Highlighting.Highlighted) : Array (String × Array (Goal String)) := Id.run do
let mut out := #[]
match hl with
| .seq hls =>
for x in hls.map proofStates do
out := out ++ x
| .span _ hl' =>
out := out ++ hl'.proofStates
| .tactics info _ _ hl' =>
out := out.push (hl'.asString, info.map (·.map (·.asString)))
| _ => pure ()
out
%example proof
theorem test (n : Nat) : n * 1 = n := by
induction n with
| zero => rfl
| succ n ih =>
rw [← ih]
cases n
next => simp
case' succ =>
skip
case succ =>
. skip; simp
%end
%dump proof into proofJson
%dumpE proof into proofEx
-- We don't have #guard_msgs in all supported Lean versions, so here's a low-tech replacement:
open Lean Elab Command in
elab "#evalString" s:str e:term : command => do
let msgs := (← get).messages
try
modify ({· with messages := {}})
elabCommand <| ← `(#eval $e)
let msgs' := (← get).messages
let [msg] := msgs'.toList
| throwError "Too many messages"
if (← msg.toString) != s.getString then
throwErrorAt e "Expected {String.quote s.getString}, got {String.quote (← msg.toString)}"
finally
modify ({· with messages := msgs})
open Lean Elab Command in
elab "#evalStrings " "[" ss:str,* "] " e:term : command => do
let msgs := (← get).messages
try
modify ({· with messages := {}})
elabCommand <| ← `(#eval $e)
let msgs' := (← get).messages
let [msg] := msgs'.toList
| throwError "Too many messages"
let ok := ss.getElems.toList.map (·.getString)
if (← msg.toString) ∉ ok then
throwErrorAt e "Expected one of {ok.map String.quote}, got {String.quote (← msg.toString)}"
finally
modify ({· with messages := msgs})
#evalString "[[\"n * 1 = n\"]]\n"
(proofEx.highlighted[0].proofStates.toList.filter (·.fst == "by") |>.map (·.snd.toList.map (·.conclusion)))
#evalStrings [ -- NB #5677 changed goal displays, so the second
-- version here became the expected output after
-- nightly-2024-10-18.
"[[some `zero], [some `succ], [none], [some `succ.succ], [none]]\n",
"[[none], [some `succ.succ], [none]]\n"]
(proofEx.highlighted[0].proofStates.toList.filter (·.fst == "=>") |>.map (·.snd.toList.map (·.name)))
def main : IO Unit := pure ()