first commit
This commit is contained in:
commit
e1c6aeeeed
42 changed files with 1305 additions and 0 deletions
6
test/fuzz/dune
Normal file
6
test/fuzz/dune
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(executable
|
||||
(name fuzz)
|
||||
(modules fuzz gen)
|
||||
(flags
|
||||
(:standard -open Prelude))
|
||||
(libraries crowbar fmt prelude scfg))
|
||||
18
test/fuzz/fuzz.ml
Normal file
18
test/fuzz/fuzz.ml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
open Scfg
|
||||
|
||||
let () = Random.self_init ()
|
||||
|
||||
let () =
|
||||
Crowbar.add_test ~name:"Print and parse fuzzing" [ Gen.config ] (fun config ->
|
||||
let printed = Fmt.str "%a" Pp.config config in
|
||||
match Parse.from_string printed with
|
||||
| Error (`Msg msg) ->
|
||||
Crowbar.failf "%s on the given input@\n***`%S`@\n***`%s`@\n" msg printed
|
||||
printed
|
||||
| Ok config -> (
|
||||
let printed = Fmt.str "%a" Pp.config config in
|
||||
match Parse.from_string printed with
|
||||
| Error (`Msg msg) ->
|
||||
Crowbar.failf "%s on the given input@\n***`%S`@\n***`%s`@\n" msg printed
|
||||
printed
|
||||
| Ok parsed -> Crowbar.check_eq ~pp:Pp.config config parsed ) )
|
||||
21
test/fuzz/gen.ml
Normal file
21
test/fuzz/gen.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
open Crowbar
|
||||
|
||||
let ( let* ) = dynamic_bind
|
||||
|
||||
let ( let+ ) = map
|
||||
|
||||
let unicode_bytes =
|
||||
let+ values = [ list1 uchar ] in
|
||||
let buf = Buffer.create (List.length values) in
|
||||
List.iter (fun u -> Buffer.add_utf_8_uchar buf u) values;
|
||||
Buffer.contents buf
|
||||
|
||||
let directive =
|
||||
fix (fun directive ->
|
||||
let* name = unicode_bytes in
|
||||
let* params = list unicode_bytes in
|
||||
let+ children = [ list directive ] in
|
||||
let open Scfg.Types in
|
||||
{ name; params; children } )
|
||||
|
||||
let config = list directive
|
||||
Loading…
Add table
Add a link
Reference in a new issue