Skip to content

Commit

Permalink
crowbar: add opamUrl support
Browse files Browse the repository at this point in the history
  • Loading branch information
gasche committed Mar 9, 2019
1 parent 87f9201 commit ef41fc0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/crowbar/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(modules opamCrowbar
opamFilename_crowbar
opamHash_crowbar
opamUrl_crowbar
opamCudf_crowbar
test)
(libraries crowbar opam-core opam-format opam-solver)
Expand Down
5 changes: 3 additions & 2 deletions src/crowbar/opamCrowbar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ let nice_int = int8
let nice_uint = uint8
let nice_string =
let letter = map [range ~min:0 25] (fun n -> char_of_int (int_of_char 'a' + n)) in
map [letter; letter; letter; letter; letter]
(fun a b c d e -> String.of_seq (List.to_seq [a;b;c;d;e]))
with_printer Format.pp_print_string @@
map [letter; letter; letter; letter; letter] @@
fun a b c d e -> String.of_seq (List.to_seq [a;b;c;d;e])

let check_json_roundtrip ~name gen equal to_json of_json =
let pp ppf = function
Expand Down
52 changes: 52 additions & 0 deletions src/crowbar/opamUrl_crowbar.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(**************************************************************************)
(* *)
(* Copyright 2019 INRIA *)
(* *)
(* All rights reserved. This file is distributed under the terms of the *)
(* GNU Lesser General Public License version 2.1, with the special *)
(* exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

open OpamUrl
open! Crowbar
open OpamCrowbar

let version_control = choose [
const `git;
const `darcs;
const `hg;
]
let backend =
let print ppf b = Format.pp_print_string ppf (string_of_backend b) in
with_printer print @@ choose [
const `http;
const `rsync;
version_control;
]

let transport = choose [
const "http";
const "ssh";
const "file";
const "git";
const "hg";
const "darcs";
]

let url : OpamUrl.t gen = map [
transport;
nice_string;
option nice_string;
] @@ fun
transport
path
hash
->
String.concat ""
[transport; "://"; path; (match hash with None -> "" | Some h -> h)]
|> OpamUrl.parse

let check () =
check_json_roundtrip ~name:"OpamUrl.t"
url (=) OpamUrl.to_json OpamUrl.of_json;
1 change: 1 addition & 0 deletions src/crowbar/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ let () =
OpamCudf_crowbar.check ();
OpamFilename_crowbar.check ();
OpamHash_crowbar.check ();
OpamUrl_crowbar.check ();

0 comments on commit ef41fc0

Please sign in to comment.