| 1 |
Require Import Ltac2.Ltac2. |
| 2 |
|
| 3 |
(** Basic tests for external APIs from Ltac2.Control *) |
| 4 |
|
| 5 |
Import Ltac2.Control. |
| 6 |
Import Ltac2.Ref. |
| 7 |
|
| 8 |
Ltac2 Type exn ::= [ Error ]. |
| 9 |
|
| 10 |
Fail Ltac2 Eval throw Error. |
| 11 |
Fail Ltac2 Eval plus_bt (fun _ => zero Error) throw_bt. |
| 12 |
Fail Ltac2 Eval plus_bt (fun _ => zero Error) zero_bt. |
| 13 |
Ltac2 Eval plus_bt (fun _ => ()) throw_bt. |
| 14 |
Ltac2 Eval plus_bt (fun _ => ()) zero_bt. |
| 15 |
|
| 16 |
Fail Ltac2 Eval zero Error. |
| 17 |
|
| 18 |
Fail Ltac2 Eval plus (fun () => throw Error) (fun _ => ()). |
| 19 |
|
| 20 |
Ltac2 Eval plus (fun () => zero Error) (fun _ => ()). |
| 21 |
Ltac2 Eval plus_bt (fun () => zero Error) (fun _ _ => ()). |
| 22 |
|
| 23 |
Fail Ltac2 Eval case (fun () => throw Error). |
| 24 |
|
| 25 |
Ltac2 Eval match case (fun () => zero Error) with |
| 26 |
| Val _ => throw Error |
| 27 |
| Err Error => () |
| 28 |
| Err _ => throw Error |
| 29 |
end. |
| 30 |
|
| 31 |
Ltac2 Eval |
| 32 |
let n := plus (fun () => 1) (fun _ => 2) in |
| 33 |
if Int.equal n 1 then zero Error else (). |
| 34 |
|
| 35 |
Fail Ltac2 Eval |
| 36 |
match case (fun () => plus (fun () => 1) (fun _ => 2)) with |
| 37 |
| Val (n,k) => |
| 38 |
if Int.equal n 1 then zero Error else () |
| 39 |
| Err _ => throw Error |
| 40 |
end. |
| 41 |
|
| 42 |
Ltac2 Eval |
| 43 |
match case (fun () => plus (fun () => 1) (fun _ => 2)) with |
| 44 |
| Val (n,k) => |
| 45 |
if Int.equal n 1 then k Error else throw Error |
| 46 |
| Err _ => throw Error |
| 47 |
end. |
| 48 |
|
| 49 |
Ltac2 Eval once (fun () => 1). |
| 50 |
|
| 51 |
Fail Ltac2 Eval |
| 52 |
let n := once (fun () => plus (fun () => 1) (fun _ => 2)) in |
| 53 |
if Int.equal n 1 then zero Error else (). |
| 54 |
|
| 55 |
Ltac2 Eval |
| 56 |
if Int.equal (numgoals()) 0 then () else throw Error. |
| 57 |
|
| 58 |
Goal True /\ True. |
| 59 |
if Int.equal (numgoals()) 1 then () else throw Error. |
| 60 |
split. |
| 61 |
if Int.equal (numgoals()) 1 then () else throw Error. |
| 62 |
all:if Int.equal (numgoals()) 2 then () else throw Error. |
| 63 |
all:shelve (). |
| 64 |
all:if Int.equal (numgoals()) 0 then () else throw Error. |
| 65 |
Abort. |
| 66 |
|
| 67 |
Goal tt = tt /\ 2 = 2 /\ True /\ True /\ true = true. |
| 68 |
repeat (match! goal with [ |- _ /\ _ ] => split end). |
| 69 |
|
| 70 |
Fail all: dispatch []. |
| 71 |
Fail all: dispatch [fun _ => ()]. |
| 72 |
1,2: dispatch [(fun _ => ()); (fun _ => exact (eq_refl 2))]. |
| 73 |
all: extend [fun _ => exact (eq_refl tt)] (fun _ => exact I) [fun _ => ()]. |
| 74 |
|
| 75 |
exact (eq_refl true). |
| 76 |
|
| 77 |
all: if Int.equal (numgoals()) 0 then () else throw Error. |
| 78 |
|
| 79 |
all: extend [] (fun _ => ()) []. |
| 80 |
Fail all: extend [fun _ => ()] (fun _ => ()) []. |
| 81 |
Qed. |
| 82 |
|
| 83 |
Goal True /\ False. |
| 84 |
split. |
| 85 |
let r := ref 0 in |
| 86 |
enter (fun () => |
| 87 |
if Int.equal (get r) 0 then (incr r; exact I) |
| 88 |
else ()). |
| 89 |
all: if Int.equal (numgoals()) 1 then () else throw Error. |
| 90 |
Abort. |
| 91 |
|
| 92 |
Goal 1 = 1 /\ 2 = 2 /\ 3 = 3. |
| 93 |
repeat (match! goal with [ |- _ /\ _ ] => split end). |
| 94 |
all:focus 2 3 (fun () => enter (fun () => plus (fun () => exact (eq_refl 2)) (fun _ => exact (eq_refl 3)))). |
| 95 |
Fail focus 2 3 (fun _ => ()). |
| 96 |
|
| 97 |
shelve (). |
| 98 |
all: if Int.equal (numgoals()) 0 then () else throw Error. |
| 99 |
Abort. |
| 100 |
|
| 101 |
Goal exists n, n = 0. |
| 102 |
shelve_unifiable (). |
| 103 |
Notations.unshelve eexists. |
| 104 |
all:shelve_unifiable (). |
| 105 |
all: if Int.equal (numgoals()) 1 then () else throw Error. |
| 106 |
exact (eq_refl 0). |
| 107 |
Qed. |
| 108 |
|
| 109 |
Goal True. |
| 110 |
let c := '(_ :> nat) in |
| 111 |
match Constr.Unsafe.kind c with |
| 112 |
| Constr.Unsafe.Evar ev _ => new_goal ev |
| 113 |
| _ => throw Error |
| 114 |
end. |
| 115 |
exact I. |
| 116 |
exact 0. |
| 117 |
Qed. |
| 118 |
|
| 119 |
Goal True. |
| 120 |
Fail progress (fun () => ()). |
| 121 |
progress (fun () => exact I). |
| 122 |
Abort. |
| 123 |
|
| 124 |
Goal 3 = 3 -> 1 = 1 /\ 2 = 2. |
| 125 |
intros H. |
| 126 |
split. |
| 127 |
Fail all: let _ := goal () in (). |
| 128 |
Fail all: let _ := hyps () in (). |
| 129 |
Fail all: let _ := hyp @H in (). |
| 130 |
|
| 131 |
reflexivity. |
| 132 |
|
| 133 |
if Constr.equal (goal()) '(2 = 2) then () else throw Error. |
| 134 |
if Constr.equal (hyp @H) '&H then () else throw Error. |
| 135 |
Fail let _ := hyp @X in (). |
| 136 |
pose (X := 2). |
| 137 |
if Constr.equal (hyp @X) '&X then () else throw Error. |
| 138 |
|
| 139 |
if Option.equal Constr.equal (hyp_value @H) None then () else throw Error. |
| 140 |
if Option.equal Constr.equal (hyp_value @X) (Some '2) then () else throw Error. |
| 141 |
|
| 142 |
Ltac2 Eval hyps(). |
| 143 |
match hyps () with |
| 144 |
| [ (h, None, hty); (x, Some xbdy, xty) ] => |
| 145 |
if Ident.equal h @H then () else throw Error; |
| 146 |
if Constr.equal hty '(3 = 3) then () else throw Error; |
| 147 |
if Ident.equal x @X then () else throw Error; |
| 148 |
if Constr.equal xbdy '2 then () else throw Error; |
| 149 |
if Constr.equal xty 'nat then () else throw Error |
| 150 |
| _ => throw Error |
| 151 |
end. |
| 152 |
|
| 153 |
refine (fun () => '(eq_refl &X)). |
| 154 |
Qed. |
| 155 |
|
| 156 |
Goal True. |
| 157 |
with_holes (fun _ => ()) (fun () => ()). |
| 158 |
Fail with_holes (fun _ => '_) (fun _ => ()). |
| 159 |
with_holes (fun _ => '_) (fun c => unify $c I). |
| 160 |
Abort. |
| 161 |
|
| 162 |
Ltac2 Eval time (Some "time") (fun () => ()). |
| 163 |
|
| 164 |
Goal True. |
| 165 |
abstract (Some @subproof) (fun () => exact I). |
| 166 |
Qed. |
| 167 |
|
| 168 |
Ltac2 Eval check_interrupt (). |
| 169 |
|
| 170 |
Ltac2 Eval |
| 171 |
match case (fun () => '(1 + tt)) with |
| 172 |
| Err (Internal e) => |
| 173 |
let _ := clear_err_info e in () |
| 174 |
| _ => throw Error |
| 175 |
end. |
| 176 |
|
| 177 |
Ltac2 Eval timeout 1 (fun () => ()). |
| 178 |
|
| 179 |
(* I don't think we can currently get values of type float |
| 180 |
without going through constr primitive floats (no ltac2 parsing for float literals) |
| 181 |
so skipping testing for timeoutf *) |