-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifast-mode-tests.el
154 lines (144 loc) · 3.5 KB
/
verifast-mode-tests.el
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(require 'pp)
(require 'ert)
(require 'verifast-mode)
(require 'assess)
(ert-deftest verifast-pass ()
"Just a passing test, to make sure they exist"
t)
(ert-deftest verifast-mode-indent-lemma ()
"Ensure we correctly indent simple lemmas."
(should (assess-indentation=
'verifast-mode
;; before:
"
lemma void reverse_cons<t>(t head, list<t> tail)
requires true;
ensures reverse(cons(head, tail)) == append(reverse(tail), cons(head, nil));
{
reverse_append(reverse(tail), cons(head, nil));
}"
;; after:
"
lemma void reverse_cons<t>(t head, list<t> tail)
requires true;
ensures reverse(cons(head, tail)) == append(reverse(tail), cons(head, nil));
{
reverse_append(reverse(tail), cons(head, nil));
}")))
(ert-deftest verifast-mode-indent-less-sign ()
"Ensure we indent correctly the code after '<',
as it seems like an opening angle bracket."
(should (access-indentatio
'verifast-mode
"
lemma void nth_cons()
requires 0 < n;
ensures true;
"
;; after:
"
lemma void nth_cons()
requires 0 < n;
ensures true;
")))
(ert-deftest verifast-mode-indent-simple-switch ()
"Ensure we correctly indent simple lemmas."
(should (assess-indentation=
'verifast-mode
;; before:
"
fixpoint t get_some<t>(option<t> x) {
switch(x) {
case none: return default_value<t>();
case some(v): return v;
}
}"
;; after:
"
fixpoint t get_some<t>(option<t> x) {
switch(x) {
case none: return default_value<t>();
case some(v): return v;
}
}")))
(ert-deftest verifast-mode-indent-long-switch ()
"Ensure we correctly indent simple lemmas."
(should (assess-indentation=
'verifast-mode
;; before:
"
lemma void length_0_nil<T>(list<T> lst)
requires length(lst) == 0;
ensures lst == nil;
{
switch (lst) {
case nil: return;
case cons(h, t):
assert(length(lst) > length(t));
assert(length(t) == 0);
return;
}
}"
;; after:
"
lemma void length_0_nil<T>(list<T> lst)
requires length(lst) == 0;
ensures lst == nil;
{
switch (lst) {
case nil: return;
case cons(h, t):
assert(length(lst) > length(t));
assert(length(t) == 0);
return;
}
}")))
(ert-deftest verifast-mode-indent-argument-on-a-new-line ()
"Ensure we correctly indent simple lemmas."
(should (assess-indentation=
'verifast-mode
;; before:
"
lemma void nth_cons<T>(int n, list<T> lst,
T head)
requires 0 < n;
ensures nth(n-1, lst) == nth(n, cons(head, lst));
{
}
"
;; after:
"
lemma void nth_cons<T>(int n, list<T> lst,
T head)
requires 0 < n;
ensures nth(n-1, lst) == nth(n, cons(head, lst));
{
}
")))
(ert-deftest verifast-mode-indent-requires-multi-line-argument ()
"Ensure we correctly indent simple lemmas."
(should (assess-indentation=
'verifast-mode
;; before:
"
lemma void nth_len_append_cons<T>(list<T> lst, T x)
requires true;
ensures nth(length(lst),
append(lst, cons(x, nil))) == x;
{
}"
;; after:
"
lemma void nth_len_append_cons<T>(list<T> lst, T x)
requires true;
ensures nth(length(lst),
append(lst, cons(x, nil))) == x;
{
}")))
(ert-deftest verifast-mode-highlight-sources ()
"Ensure we highlight known values for source."
(should (assess-face-at=
"int x;"
'verifast-mode
"int"
'font-lock-type-face)))