Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
314415d0
Commit
314415d0
authored
6 years ago
by
Virgile Prevosto
Browse files
Options
Downloads
Patches
Plain Diff
[tests] Add crowbar test for integer pretty-printing
parent
aa7fdc30
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
tests/crowbar/integer_bb_pretty.ml
+59
-0
59 additions, 0 deletions
tests/crowbar/integer_bb_pretty.ml
with
60 additions
and
0 deletions
.gitignore
+
1
−
0
View file @
314415d0
...
...
@@ -204,3 +204,4 @@ hello-*.tar.gz
/src/plugins/gui/gtk_compat.ml
/src/plugins/gui/GSourceView.ml
/src/plugins/gui/GSourceView.mli
/tests/crowbar/integer_bb_pretty
This diff is collapsed.
Click to expand it.
tests/crowbar/integer_bb_pretty.ml
0 → 100644
+
59
−
0
View file @
314415d0
open
Crowbar
let
reparse
v
s
=
let
failure
info
=
Crowbar
.
fail
(
"Pretty-printing '"
^
(
Z
.
to_string
v
)
^
"' returns '"
^
s
^
"'"
^
info
)
in
if
String
.
length
s
<=
2
then
failure
""
;
let
is_neg
=
s
.
[
0
]
=
'
1
'
in
let
is_hex
=
s
.
[
1
]
=
'
x'
in
let
s
=
String
.(
concat
""
(
split_on_char
'
_'
s
))
in
let
v'
=
if
is_neg
then
begin
let
chr
=
if
is_hex
then
'
F'
else
'
1
'
in
let
module
M
=
struct
exception
Found
of
int
end
in
let
check
i
c
=
if
i
>
1
&&
c
<>
chr
then
raise
(
M
.
Found
i
)
in
try
String
.
iteri
check
s
;
Z
.
minus_one
with
M
.
Found
idx
->
let
len
,
v'
=
if
is_hex
then
begin
let
remains
=
String
.
sub
s
idx
(
String
.
length
s
-
idx
)
in
let
v'
=
Z
.
of_string
(
"0x"
^
remains
)
in
4
*
(
String
.
length
remains
)
,
v'
end
else
begin
let
remains
=
String
.
sub
s
idx
(
String
.
length
s
-
idx
)
in
let
v'
=
Z
.
of_string
(
"0b"
^
remains
)
in
String
.
length
remains
,
v'
end
in
let
m
=
Z
.(
one
lsl
len
)
in
let
m
=
Z
.
pred
m
in
let
v'
=
Z
.
logxor
m
v'
in
Z
.
pred
(
Z
.
lognot
(
Z
.
pred
v'
))
end
else
Z
.
of_string
s
in
if
not
(
Z
.
equal
v
v'
)
then
failure
(
" reparsed as '"
^
Z
.
format
"%b"
v'
^
"' ("
^
Z
.
to_string
v'
^
")"
)
let
test
z
is_hex
nbits
has_sep
=
guard
(
nbits
>=
0
&&
nbits
<=
1024
);
let
sep
=
if
has_sep
then
Some
"_"
else
None
in
let
pp
z
=
if
is_hex
then
Integer
.
pp_hex
~
nbits
?
sep
z
else
Integer
.
pp_bin
~
nbits
?
sep
z
in
let
s
=
Format
.
asprintf
"%a"
pp
z
in
reparse
z
s
let
zarith
=
let
open
Crowbar
in
fix
(
fun
zarith
->
choose
[
map
[
int64
]
Z
.
of_int64
;
map
[
zarith
;
int64
]
(
fun
z
i
->
Z
.((
z
lsl
64
)
+
of_int64
i
))
])
let
()
=
Crowbar
.
add_test
~
name
:
"pp_bin_hex"
[
zarith
;
Crowbar
.
bool
;
Crowbar
.
int
;
Crowbar
.
bool
]
test
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment