| 1 |
Require Import Ltac2.Ltac2. |
| 2 |
|
| 3 |
Ltac2 Type exn ::= [ Regression_Test_Failure ]. |
| 4 |
|
| 5 |
Ltac2 ensure b := if b then () else Control.throw Regression_Test_Failure. |
| 6 |
|
| 7 |
Ltac2 sort_int_list l := |
| 8 |
FSet.elements |
| 9 |
(List.fold_left (fun acc x => FSet.add x acc) (FSet.empty FSet.Tags.int_tag) l). |
| 10 |
|
| 11 |
Ltac2 Eval |
| 12 |
ensure (List.equal Int.equal [1;2;5;8] (sort_int_list [2;5;1;8])). |
| 13 |
|
| 14 |
Ltac2 Eval |
| 15 |
ensure (FSet.is_empty (FSet.empty FSet.Tags.int_tag)). |
| 16 |
|
| 17 |
Ltac2 Eval |
| 18 |
ensure (Bool.neg (FSet.is_empty (FSet.add "hello" (FSet.empty FSet.Tags.string_tag)))). |
| 19 |
|
| 20 |
Ltac2 Eval |
| 21 |
ensure (FSet.is_empty (FSet.remove "hello" (FSet.add "hello" (FSet.empty FSet.Tags.string_tag)))). |
| 22 |
|
| 23 |
Ltac2 Eval |
| 24 |
ensure (Bool.neg (FSet.is_empty (FSet.remove "hello" (FSet.add "other" (FSet.add "hello" (FSet.empty FSet.Tags.string_tag)))))). |
| 25 |
|
| 26 |
Ltac2 Eval |
| 27 |
ensure (FSet.mem "other" (FSet.remove "hello" (FSet.add "other" (FSet.add "hello" (FSet.empty FSet.Tags.string_tag))))). |
| 28 |
|
| 29 |
Ltac2 Eval |
| 30 |
ensure (Bool.neg (FSet.mem "hello" (FSet.remove "hello" (FSet.add "other" (FSet.add "hello" (FSet.empty FSet.Tags.string_tag)))))). |
| 31 |
|
| 32 |
Ltac2 Notation "sprintf" fmt(format) := Message.Format.kfprintf (fun m => Message.to_string m) fmt. |
| 33 |
|
| 34 |
Ltac2 Eval |
| 35 |
let m := FMap.empty FSet.Tags.string_tag in |
| 36 |
let m := FMap.add "one" 1 m in |
| 37 |
let m := FMap.add "two" 2 m in |
| 38 |
let m := FMap.add "three" 3 m in |
| 39 |
let m := FMap.add "four" 4 m in |
| 40 |
let m := FMap.mapi (fun s i => sprintf "%s=%i" s i) m in |
| 41 |
match FMap.find_opt "two" m with |
| 42 |
| None => ensure false |
| 43 |
| Some v => ensure (String.equal "two=2" v) |
| 44 |
end. |
| 45 |
|
| 46 |
(* types didn't collapse *) |
| 47 |
Fail Ltac2 Eval FSet.add 1 (FSet.empty FSet.Tags.string_tag). |