Skip to content

Commit 2129026

Browse files
committed
Import ppx_deriving_qcheck
1 parent b065a81 commit 2129026

File tree

8 files changed

+1365
-0
lines changed

8 files changed

+1365
-0
lines changed

ppx_deriving_qcheck.opam

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
opam-version: "2.0"
2+
name: "ppx_deriving_qcheck"
3+
version: "0.2.0"
4+
license: "BSD-2-Clause"
5+
synopsis: "PPX Deriver for QCheck"
6+
7+
maintainer: "[email protected]"
8+
author: [ "the qcheck contributors" ]
9+
10+
depends: [
11+
"dune" {>= "2.8.0"}
12+
"ocaml" {>= "4.10.2"}
13+
"qcheck" {>= "0.17"}
14+
"ppxlib" {>= "0.22.0"}
15+
"odoc" {with-doc}
16+
"alcotest" {with-test & >= "1.4.0" }
17+
]
18+
19+
build: [
20+
["dune" "build" "-p" name "-j" jobs]
21+
["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc}
22+
["dune" "runtest" "-p" name "-j" jobs] {with-test}
23+
]
24+
25+
homepage: "https://github.com/c-cube/qcheck/"
26+
bug-reports: "https://github.com/c-cube/qcheck/-/issues"
27+
dev-repo: "git+https://github.com/vch9/ppx_deriving_qcheck.git"

src/ppx_deriving_qcheck/attributes.ml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
open Ppxlib
2+
3+
(** [find_first_attribute xs name] returns the first attribute found in [xs]
4+
named [name] *)
5+
let find_attribute_opt xs name =
6+
List.find_opt (fun attribute -> attribute.attr_name.txt = name) xs
7+
8+
let get_expr_payload x =
9+
match x.attr_payload with
10+
| PStr [ { pstr_desc = Pstr_eval (e, _); _ } ] -> Some [%expr [%e e]]
11+
| _ -> None
12+
13+
let gen ct =
14+
Option.fold ~none:None ~some:get_expr_payload
15+
@@ find_attribute_opt ct.ptyp_attributes "gen"
16+
17+
let weight xs =
18+
Option.fold ~none:None ~some:get_expr_payload
19+
@@ find_attribute_opt xs "weight"
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
open Ppxlib
2+
(** This file handles every attributes to be found in a core_type definition *)
3+
4+
val gen : core_type -> expression option
5+
(** [gen loc ct] look for an attribute "gen" in [ct]
6+
7+
example:
8+
{[
9+
type t =
10+
| A of int
11+
| B of (int [@gen QCheck.int32])
12+
]}
13+
14+
It allows the user to specify which generator he wants for a specific type.
15+
Returns the generator as an expression and returns None if no attribute
16+
is present *)
17+
18+
val weight : attributes -> expression option
19+
(** [weight loc ct] look for an attribute "weight" in [ct]
20+
21+
example:
22+
{[
23+
type t =
24+
| A [@weight 5]
25+
| B [@weight 6]
26+
| C
27+
]}
28+
It allows the user to specify the weight of a type case. *)

src/ppx_deriving_qcheck/dune

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(library
2+
(name ppx_deriving_qcheck)
3+
(public_name ppx_deriving_qcheck)
4+
(libraries ppxlib)
5+
(preprocess (pps ppxlib.metaquot))
6+
(ppx_runtime_libraries qcheck-core)
7+
(kind ppx_deriver))

0 commit comments

Comments
 (0)