Debian Codegraph @

test-suite/primitive/string/test.v

raw
1 Require Import PrimInt63 PrimString.
2
3 Open Scope uint63_scope.
4 Open Scope pstring_scope.
5
6 Check (eq_refl : length (make 0 "a") = 0 ).
7 Check (eq_refl : length (make 42 "a") = 42 ).
8 Check (eq_refl : length (make max_length "a") = max_length).
9 Check (eq_refl : length (make (PrimInt63.add max_length 1) "a") = max_length).
10
11 Check (eq_refl : make 0 "a" = "").
12 Check (eq_refl : make 5 "a" = "aaaaa").
13
14 Check (eq_refl : get "abcdefg" 0 = "a"%char63).
15 Check (eq_refl : get "abcdefg" 5 = "f"%char63).
16 Check (eq_refl : get "abcdefg" 6 = "g"%char63).
17
18 (* Invalid index. *)
19 Check (eq_refl : get "abcdefg" 7 = 0%uint63).
20
21 Check (eq_refl : sub "abcdefg" 0 0 = "").
22 Check (eq_refl : sub "abcdefg" 0 7 = "abcdefg").
23 Check (eq_refl : sub "abcdefg" 0 6 = "abcdef").
24 Check (eq_refl : sub "abcdefg" 1 6 = "bcdefg").
25 Check (eq_refl : sub "abcdefg" 6 1 = "g").
26 Check (eq_refl : sub "abcdefg" 6 0 = "").
27 Check (eq_refl : sub "abcdefg" 7 0 = "").
28
29 (* When there are not enough characters, take as many as are available. *)
30 Check (eq_refl : sub "abcdefg" 4 10 = "efg").
31
32 (* Invalid ranges. *)
33 Check (eq_refl : sub "abcdefg" 7 2 = "").
34 Check (eq_refl : sub "abcdefg" 73 42 = "").
35
36 Check (eq_refl : cat "" "" = "" ).
37 Check (eq_refl : cat "a" "b" = "ab").
38 Check (eq_refl : cat "aa" "" = "aa").
39 Check (eq_refl : cat "" "bb" = "bb").
40
41 Check (eq_refl : compare "" "" = Eq).
42 Check (eq_refl : compare "a" "" = Gt).
43 Check (eq_refl : compare "" "a" = Lt).
44 Check (eq_refl : compare "a" "b" = Lt).
45 Check (eq_refl : compare "b" "a" = Gt).
46 Check (eq_refl : compare "a" "ab" = Lt).
47 Check (eq_refl : compare "ab" "a" = Gt).
48
49 (* Dropping a suffix on length overflow. *)
50 Check (eq_refl : cat (make max_length "a") "b" = make max_length "a").
51
52 Ltac syntactic_refl :=
53 lazymatch goal with
54 | |- ?x = ?x => apply (@eq_refl _ x)
55 end.
56
57 (* [lazy] *)
58
59 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
60 Proof. lazy. syntactic_refl. Qed.
61
62 Goal get "aaa" 0 = "a"%char63.
63 Proof. lazy. syntactic_refl. Qed.
64
65 Goal sub "abcd" 2 1 = "c".
66 Proof. lazy. syntactic_refl. Qed.
67
68 Goal cat "ab" "ba" = "abba".
69 Proof. lazy. syntactic_refl. Qed.
70
71 Goal compare "ab" "ab" = Eq.
72 Proof. lazy. syntactic_refl. Qed.
73
74 Goal compare "ab" "a" = Gt.
75 Proof. lazy. syntactic_refl. Qed.
76
77 Goal compare "a" "ab" = Lt.
78 Proof. lazy. syntactic_refl. Qed.
79
80 (* [cbn] *)
81
82 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
83 Proof. cbn. syntactic_refl. Qed.
84
85 Goal get "aaa" 0 = "a"%char63.
86 Proof. cbn. syntactic_refl. Qed.
87
88 Goal sub "abcd" 2 1 = "c".
89 Proof. cbn. syntactic_refl. Qed.
90
91 Goal cat "ab" "ba" = "abba".
92 Proof. cbn. syntactic_refl. Qed.
93
94 Goal compare "ab" "ab" = Eq.
95 Proof. cbn. syntactic_refl. Qed.
96
97 Goal compare "ab" "a" = Gt.
98 Proof. cbn. syntactic_refl. Qed.
99
100 Goal compare "a" "ab" = Lt.
101 Proof. cbn. syntactic_refl. Qed.
102
103 (* [cbv] *)
104
105 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
106 Proof. cbv. syntactic_refl. Qed.
107
108 Goal get "aaa" 0 = "a"%char63.
109 Proof. cbv. syntactic_refl. Qed.
110
111 Goal sub "abcd" 2 1 = "c".
112 Proof. cbv. syntactic_refl. Qed.
113
114 Goal cat "ab" "ba" = "abba".
115 Proof. cbv. syntactic_refl. Qed.
116
117 Goal compare "ab" "ab" = Eq.
118 Proof. cbv. syntactic_refl. Qed.
119
120 Goal compare "ab" "a" = Gt.
121 Proof. cbv. syntactic_refl. Qed.
122
123 Goal compare "a" "ab" = Lt.
124 Proof. cbv. syntactic_refl. Qed.
125
126 (* [simpl] *)
127
128 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
129 Proof. simpl. syntactic_refl. Qed.
130
131 Goal get "aaa" 0 = "a"%char63.
132 Proof. simpl. syntactic_refl. Qed.
133
134 Goal sub "abcd" 2 1 = "c".
135 Proof. simpl. syntactic_refl. Qed.
136
137 Goal cat "ab" "ba" = "abba".
138 Proof. simpl. syntactic_refl. Qed.
139
140 Goal compare "ab" "ab" = Eq.
141 Proof. simpl. syntactic_refl. Qed.
142
143 Goal compare "ab" "a" = Gt.
144 Proof. simpl. syntactic_refl. Qed.
145
146 Goal compare "a" "ab" = Lt.
147 Proof. simpl. syntactic_refl. Qed.
148
149 (* [hnf] *)
150
151 (* Reduce with [hnf] on either side of an equality. *)
152 Ltac hnf_eq :=
153 lazymatch goal with
154 | |- ?lhs = ?rhs =>
155 let lhs := eval hnf in lhs in
156 let rhs := eval hnf in rhs in
157 assert (lhs = rhs) as H; [|exact H]
158 end.
159
160 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
161 Proof. hnf_eq. syntactic_refl. Qed.
162
163 Goal get "aaa" 0 = "a"%char63.
164 Proof. hnf_eq. syntactic_refl. Qed.
165
166 Goal sub "abcd" 2 1 = "c".
167 Proof. hnf_eq. syntactic_refl. Qed.
168
169 Goal cat "ab" "ba" = "abba".
170 Proof. hnf_eq. syntactic_refl. Qed.
171
172 Goal compare "ab" "ab" = Eq.
173 Proof. hnf_eq. syntactic_refl. Qed.
174
175 Goal compare "ab" "a" = Gt.
176 Proof. hnf_eq. syntactic_refl. Qed.
177
178 Goal compare "a" "ab" = Lt.
179 Proof. hnf_eq. syntactic_refl. Qed.
180
181 (* [vm_compute] *)
182
183 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
184 Proof. vm_compute. syntactic_refl. Qed.
185
186 Goal get "aaa" 0 = "a"%char63.
187 Proof. vm_compute. syntactic_refl. Qed.
188
189 Goal sub "abcd" 2 1 = "c".
190 Proof. vm_compute. syntactic_refl. Qed.
191
192 Goal cat "ab" "ba" = "abba".
193 Proof. vm_compute. syntactic_refl. Qed.
194
195 Goal compare "ab" "ab" = Eq.
196 Proof. vm_compute. syntactic_refl. Qed.
197
198 Goal compare "ab" "a" = Gt.
199 Proof. vm_compute. syntactic_refl. Qed.
200
201 Goal compare "a" "ab" = Lt.
202 Proof. vm_compute. syntactic_refl. Qed.
203
204 Check (eq_refl "aaaaa" <: make 5 "a" = cat (make 2 "a") (make 3 "a")).
205 Check (eq_refl (char63_wrap "a"%char63) <: get "aaa" 0 = "a"%char63).
206 Check (eq_refl "c" <: sub "abcd" 2 1 = "c").
207 Check (eq_refl "abba" <: cat "ab" "ba" = "abba").
208 Check (eq_refl Eq <: compare "ab" "ab" = Eq).
209 Check (eq_refl Gt <: compare "ab" "a" = Gt).
210 Check (eq_refl Lt <: compare "a" "ab" = Lt).
211
212 (* [native_compute] *)
213
214 Goal make 5 "a" = cat (make 2 "a") (make 3 "a").
215 Proof. native_compute. syntactic_refl. Qed.
216
217 Goal get "aaa" 0 = "a"%char63.
218 Proof. native_compute. syntactic_refl. Qed.
219
220 Goal sub "abcd" 2 1 = "c".
221 Proof. native_compute. syntactic_refl. Qed.
222
223 Goal cat "ab" "ba" = "abba".
224 Proof. native_compute. syntactic_refl. Qed.
225
226 Goal compare "ab" "ab" = Eq.
227 Proof. native_compute. syntactic_refl. Qed.
228
229 Goal compare "ab" "a" = Gt.
230 Proof. native_compute. syntactic_refl. Qed.
231
232 Goal compare "a" "ab" = Lt.
233 Proof. native_compute. syntactic_refl. Qed.
234
235 Check (eq_refl "aaaaa" <<: make 5 "a" = cat (make 2 "a") (make 3 "a")).
236 Check (eq_refl (char63_wrap "a"%char63) <<: get "aaa" 0 = "a"%char63).
237 Check (eq_refl "c" <<: sub "abcd" 2 1 = "c").
238 Check (eq_refl "abba" <<: cat "ab" "ba" = "abba").
239 Check (eq_refl Eq <<: compare "ab" "ab" = Eq).
240 Check (eq_refl Gt <<: compare "ab" "a" = Gt).
241 Check (eq_refl Lt <<: compare "a" "ab" = Lt).