-
Notifications
You must be signed in to change notification settings - Fork 0
/
Qualify_Test.thy
110 lines (90 loc) · 2.51 KB
/
Qualify_Test.thy
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
103
104
105
106
107
108
109
110
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*)
(* Basic tests for the Qualify tool. *)
theory Qualify_Test
imports
Lib.Qualify
begin
locale qualify_test
section \<open>datatype\<close>
datatype leaky = leaky
text \<open>
By default, the datatype package adds constant names to the unqualified global namespace.
Let's check that this is the case.
\<close>
ML \<open>
if can dest_Const @{term leaky}
then ()
else error "Qualify_Test failed: datatype leaky baseline"
\<close>
text \<open>
When we wrap the @{command datatype} command in @{command qualify}\<dots>@{command end_qualify},
the unqualified names should be removed.
\<close>
qualify qualify_test
datatype nonleaky = nonleaky
(* unqualified name still exists here *)
ML \<open>
if can dest_Const @{term nonleaky}
then ()
else error "Qualify_Test failed: datatype nonleaky baseline 1"
\<close>
end_qualify
(* but not here *)
ML \<open>
if can dest_Free @{term nonleaky}
then ()
else error "Qualify_Test failed: datatype nonleaky test"
\<close>
(* qualified name exists *)
ML \<open>
if can dest_Const @{term qualify_test.nonleaky}
then ()
else error "Qualify_Test failed: datatype nonleaky baseline 2"
\<close>
section \<open>instantiation\<close>
text \<open>
We can also qualify fact names from class instantiations.
\<close>
instantiation leaky :: ord begin
definition less_leaky:
"(x :: leaky) < y = True"
instance by intro_classes
end
text \<open>
By default, fact names are added to the unqualified global namespace.
\<close>
ML \<open>
if can (Proof_Context.get_thm @{context}) "less_leaky"
then ()
else error "Qualify_Test failed: instantiation leaky baseline"
\<close>
qualify qualify_test
instantiation qualify_test.nonleaky :: ord begin
definition less_nonleaky:
"(x :: qualify_test.nonleaky) < y = True"
instance by intro_classes
end
(* unqualified name still exists here *)
ML \<open>
if can (Proof_Context.get_thm @{context}) "less_nonleaky"
then ()
else error "Qualify_Test failed: instantiation nonleaky baseline 1"
\<close>
end_qualify
(* but not here *)
ML \<open>
if can (Proof_Context.get_thm @{context}) "less_nonleaky"
then error "Qualify_Test failed: instantiation nonleaky test"
else ()
\<close>
(* qualified name exists *)
ML \<open>
if can (Proof_Context.get_thm @{context}) "qualify_test.less_nonleaky"
then ()
else error "Qualify_Test failed: instantiation nonleaky baseline 2"
\<close>
end