| 1 |
(* test copied from ocaml's fragile_matching.ml test as of ocaml b02c7ca08 *) |
| 2 |
|
| 3 |
Require Import Ltac2.Ltac2. |
| 4 |
|
| 5 |
(* Tests for stack-overflow crashes caused by a combinatorial |
| 6 |
explosition in fragile pattern checking. *) |
| 7 |
|
| 8 |
Module SyntheticTest. |
| 9 |
|
| 10 |
Ltac2 Type t := [ A | B ]. |
| 11 |
|
| 12 |
Ltac2 f x := |
| 13 |
match x with |
| 14 |
| A,A,A,A,A, A,A,A,A,A, A,A,A,A,A, A,A,A => 1 |
| 15 |
| (A|B),(A|B),(A|B),(A|B),(A|B), |
| 16 |
(A|B),(A|B),(A|B),(A|B),(A|B), |
| 17 |
(A|B),(A|B),(A|B),(A|B),(A|B), |
| 18 |
(A|B),(A|B),(A|B) => 2 |
| 19 |
end. |
| 20 |
|
| 21 |
End SyntheticTest. |
| 22 |
|
| 23 |
Module RealCodeTest. |
| 24 |
(* from Alex Fedoseev *) |
| 25 |
|
| 26 |
Ltac2 Type ('a,'b) result := [ Ok ('a) | Err ('b) ]. |
| 27 |
|
| 28 |
Ltac2 Type visibility := [Shown | Hidden]. |
| 29 |
|
| 30 |
Ltac2 Type ('outputValue, 'message) fieldStatus := |
| 31 |
[ Pristine |
| 32 |
| Dirty (('outputValue, 'message) result, visibility) ]. |
| 33 |
|
| 34 |
Ltac2 Type message := string. |
| 35 |
|
| 36 |
Ltac2 Type rec fieldsStatuses := { |
| 37 |
iaasStorageConfigurations : |
| 38 |
iaasStorageConfigurationFieldsStatuses array; |
| 39 |
} |
| 40 |
|
| 41 |
with iaasStorageConfigurationFieldsStatuses := { |
| 42 |
startDate : (int, message) fieldStatus; |
| 43 |
term : (int, message) fieldStatus; |
| 44 |
rawStorageCapacity : (int, message) fieldStatus; |
| 45 |
diskType : (string option, message) fieldStatus; |
| 46 |
connectivityMethod : (string option, message) fieldStatus; |
| 47 |
getRequest : (int option, message) fieldStatus; |
| 48 |
getRequestUnit : (string option, message) fieldStatus; |
| 49 |
putRequest : (int option, message) fieldStatus; |
| 50 |
putRequestUnit : (string option, message) fieldStatus; |
| 51 |
transferOut : (int option, message) fieldStatus; |
| 52 |
transferOutUnit : (string option, message) fieldStatus; |
| 53 |
region : (string option, message) fieldStatus; |
| 54 |
cloudType : (string option, message) fieldStatus; |
| 55 |
description : (string option, message) fieldStatus; |
| 56 |
features : (string array, message) fieldStatus; |
| 57 |
accessTypes : (string array, message) fieldStatus; |
| 58 |
certifications : (string array, message) fieldStatus; |
| 59 |
additionalRequirements : (string option, message) fieldStatus; |
| 60 |
}. |
| 61 |
|
| 62 |
Ltac2 Type interface := { dirty : unit -> bool }. |
| 63 |
|
| 64 |
Ltac2 useForm () := { |
| 65 |
dirty := (fun () => |
| 66 |
Array.for_all |
| 67 |
(fun item => |
| 68 |
match item with |
| 69 |
| { |
| 70 |
additionalRequirements := Pristine; |
| 71 |
certifications := Pristine; |
| 72 |
accessTypes := Pristine; |
| 73 |
features := Pristine; |
| 74 |
description := Pristine; |
| 75 |
cloudType := Pristine; |
| 76 |
region := Pristine; |
| 77 |
transferOutUnit := Pristine; |
| 78 |
transferOut := Pristine; |
| 79 |
putRequestUnit := Pristine; |
| 80 |
putRequest := Pristine; |
| 81 |
getRequestUnit := Pristine; |
| 82 |
getRequest := Pristine; |
| 83 |
connectivityMethod := Pristine; |
| 84 |
diskType := Pristine; |
| 85 |
rawStorageCapacity := Pristine; |
| 86 |
term := Pristine; |
| 87 |
startDate := Pristine; |
| 88 |
} => |
| 89 |
false |
| 90 |
| { |
| 91 |
additionalRequirements := Pristine | Dirty _ _; |
| 92 |
certifications := Pristine | Dirty _ _; |
| 93 |
accessTypes := Pristine | Dirty _ _; |
| 94 |
features := Pristine | Dirty _ _; |
| 95 |
description := Pristine | Dirty _ _; |
| 96 |
cloudType := Pristine | Dirty _ _; |
| 97 |
region := Pristine | Dirty _ _; |
| 98 |
transferOutUnit := Pristine | Dirty _ _; |
| 99 |
transferOut := Pristine | Dirty _ _; |
| 100 |
putRequestUnit := Pristine | Dirty _ _; |
| 101 |
putRequest := Pristine | Dirty _ _; |
| 102 |
getRequestUnit := Pristine | Dirty _ _; |
| 103 |
getRequest := Pristine | Dirty _ _; |
| 104 |
connectivityMethod := Pristine | Dirty _ _; |
| 105 |
diskType := Pristine | Dirty _ _; |
| 106 |
rawStorageCapacity := Pristine | Dirty _ _; |
| 107 |
term := Pristine | Dirty _ _; |
| 108 |
startDate := Pristine | Dirty _ _; |
| 109 |
} => |
| 110 |
true |
| 111 |
end) |
| 112 |
Array.empty) |
| 113 |
}. |
| 114 |
|
| 115 |
End RealCodeTest. |
| 116 |
|
| 117 |
Module Parsing. |
| 118 |
(* additional parsing tests not from ocaml *) |
| 119 |
|
| 120 |
(* the first command should not parse as the second *) |
| 121 |
Ltac2 Eval fun x => match x with _ :: _ | _ as x => x end. |
| 122 |
Fail Ltac2 Eval fun x => match x with _ :: _ | (_ as x) => x end. |
| 123 |
|
| 124 |
(* #21045 *) |
| 125 |
Ltac2 Eval match [10; 20; 30; 40] with x :: y :: z => x :: y :: z | _ => [] end. |
| 126 |
|
| 127 |
End Parsing. |