|
| 1 | +(******************************************************************************) |
| 2 | +(* This file is part of Waterproof-lib. *) |
| 3 | +(* *) |
| 4 | +(* Waterproof-lib is free software: you can redistribute it and/or modify *) |
| 5 | +(* it under the terms of the GNU General Public License as published by *) |
| 6 | +(* the Free Software Foundation, either version 3 of the License, or *) |
| 7 | +(* (at your option) any later version. *) |
| 8 | +(* *) |
| 9 | +(* Waterproof-lib is distributed in the hope that it will be useful, *) |
| 10 | +(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) |
| 11 | +(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) |
| 12 | +(* GNU General Public License for more details. *) |
| 13 | +(* *) |
| 14 | +(* You should have received a copy of the GNU General Public License *) |
| 15 | +(* along with Waterproof-lib. If not, see <https://www.gnu.org/licenses/>. *) |
| 16 | +(* *) |
| 17 | +(******************************************************************************) |
| 18 | + |
| 19 | +From Ltac2 Require Import Ltac2. |
| 20 | +From Waterproof Require Import Waterproof. |
| 21 | +From Waterproof Require Import Util.MessagesToUser. |
| 22 | +From Waterproof Require Import Util.TypeCorrector. |
| 23 | + |
| 24 | +Section assert_tests. |
| 25 | + |
| 26 | +Parameter setS : Set. |
| 27 | +Parameter s : setS. |
| 28 | + |
| 29 | +Parameter typeT : Type. |
| 30 | +Parameter t : typeT. |
| 31 | + |
| 32 | +Lemma test : 0 = 0. |
| 33 | +Proof. |
| 34 | + (* The statement (0 = 0) has type Prop so nothing should happen and resulting type should be Prop. *) |
| 35 | + let res := correct_type_by_wrapping constr:(0 = 0) in ( |
| 36 | + match! Constr.type res with |
| 37 | + | Prop => () |
| 38 | + | _ => throw ( Message.of_string "Expected resulting type to be Prop." ) |
| 39 | + end; |
| 40 | + let expected_constr := constr:(0 = 0) in |
| 41 | + if Constr.equal res expected_constr |
| 42 | + then () |
| 43 | + else throw ( Message.of_string "Expected resulting term to be '0 = 0'." ) |
| 44 | + ). |
| 45 | + |
| 46 | + (* The statement 'true' has type bool so this should get wrapped in 'is_true (true)' which has type Prop. *) |
| 47 | + let res := correct_type_by_wrapping constr:(true) in ( |
| 48 | + match! Constr.type res with |
| 49 | + | Prop => () |
| 50 | + | _ => throw ( Message.of_string "Expected resulting type to be Prop." ) |
| 51 | + end; |
| 52 | + let expected_constr := constr:(is_true true) in |
| 53 | + if Constr.equal res expected_constr |
| 54 | + then () |
| 55 | + else throw ( Message.of_string "Expected resulting term to be 'is_true true'." ) |
| 56 | + ). |
| 57 | + |
| 58 | + (* The statement 'true = true' has type Prop so nothing should happen and resulting type should be Prop. *) |
| 59 | + let res := correct_type_by_wrapping constr:(true = true) in ( |
| 60 | + match! Constr.type res with |
| 61 | + | Prop => () |
| 62 | + | _ => throw ( Message.of_string "Expected resulting type to be Prop." ) |
| 63 | + end; |
| 64 | + let expected_constr := constr:(true = true) in |
| 65 | + if Constr.equal res expected_constr |
| 66 | + then () |
| 67 | + else throw ( Message.of_string "Expected resulting term to be 'true = true'." ) |
| 68 | + ). |
| 69 | + |
| 70 | + (* setS has type Set which should not change *) |
| 71 | + let res := correct_type_by_wrapping constr:(setS) in ( |
| 72 | + match! Constr.type res with |
| 73 | + | Set => () |
| 74 | + | _ => throw ( Message.of_string "Expected resulting type to be Set." ) |
| 75 | + end; |
| 76 | + let expected_constr := constr:(setS) in |
| 77 | + if Constr.equal res expected_constr |
| 78 | + then () |
| 79 | + else throw ( Message.of_string "Expected resulting term to be 'setS'." ) |
| 80 | + ). |
| 81 | + |
| 82 | + (* typeT has type Type which should not change *) |
| 83 | + let res := correct_type_by_wrapping constr:(typeT) in ( |
| 84 | + match! Constr.type res with |
| 85 | + | Type => () |
| 86 | + | _ => throw ( Message.of_string "Expected resulting type to be Type." ) |
| 87 | + end; |
| 88 | + let expected_constr := constr:(typeT) in |
| 89 | + if Constr.equal res expected_constr |
| 90 | + then () |
| 91 | + else throw ( Message.of_string "Expected resulting term to be 'typeT'." ) |
| 92 | + ). |
| 93 | + |
| 94 | + (* 0 has type nat and this should fail *) |
| 95 | + Fail Ltac2 Eval correct_type_by_wrapping constr:(0). |
| 96 | + |
| 97 | + (* s has type setS and this should fail *) |
| 98 | + Fail Ltac2 Eval correct_type_by_wrapping constr:(s). |
| 99 | + |
| 100 | + (* t has type typeT and this should fail *) |
| 101 | + Fail Ltac2 Eval correct_type_by_wrapping constr:(t). |
| 102 | +Abort. |
| 103 | + |
| 104 | +End assert_tests. |
0 commit comments