Browse Source

Add Semver to library, an simple non-spec implementation of semver (#100)

* Add Semver to library, an simple non-spec implementation of semver

* add a None test case
remotes/origin/add-simple-redirecting-site
Gal Schlezinger 6 years ago committed by GitHub
parent
commit
50cc1e9bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 440
      esy.lock/index.json
  2. 6
      esy.lock/opam/dune.1.9.3/opam
  3. 11
      esy.lock/opam/ocaml-migrate-parsetree.1.3.0/opam
  4. 27
      esy.lock/opam/ppx_tools_versioned.5.2.1/opam
  5. 30
      esy.lock/opam/ppx_tools_versioned.5.2.2/opam
  6. 35
      esy.lock/opam/semver.0.1.0/opam
  7. 2
      esy.lock/overrides/opam__s__conf_pkg_config_opam__c__1.1_opam_override/package.json
  8. 0
      esy.lock/overrides/opam__s__dune_opam__c__1.9.3_opam_override/package.json
  9. 23
      library/Semver.re
  10. 11
      library/Semver.rei
  11. 2
      library/Versions.re
  12. 4
      library/dune
  13. 7
      package.json
  14. 1
      test/TestFnm.re
  15. 27
      test/TestSemver.re

440
esy.lock/index.json

File diff suppressed because it is too large Load Diff

6
esy.lock/opam/dune.1.9.1/opam → esy.lock/opam/dune.1.9.3/opam

@ -42,9 +42,9 @@ packages across several versions of OCaml and gives cross-compilation
for free. for free.
""" """
url { url {
src: "https://github.com/ocaml/dune/releases/download/1.9.1/dune-1.9.1.tbz" src: "https://github.com/ocaml/dune/releases/download/1.9.3/dune-1.9.3.tbz"
checksum: [ checksum: [
"sha256=c9a1e258a14d96fd95fb525e7659c371e8b1d253905e3d39c5b2efa280b4927c" "sha256=317bec6de4429b5dee157e9864294e1534b722a2acfc50480bd16c804ab790ca"
"sha512=842d0aa7fbe97bc5a0fde974fa9ddd95d8e2f60a7018b60779cf782282e2bc362f4ae347cd7795b857a8e05ebb9d82f1236c0e4d1e7ec10d3b210028bc2058c1" "sha512=17450333156622d4612816f9ad5a224c741d62b247d63c1d77b5359d37517c1f9bc598dd11fa024f4e02ccf7eef474cd532eef1d9c34ed13439db6c781f9fa7a"
] ]
} }

11
esy.lock/opam/ocaml-migrate-parsetree.1.2.0/opam → esy.lock/opam/ocaml-migrate-parsetree.1.3.0/opam

@ -4,7 +4,7 @@ authors: [
"Frédéric Bour <frederic.bour@lakaban.net>" "Frédéric Bour <frederic.bour@lakaban.net>"
"Jérémie Dimino <jeremie@dimino.org>" "Jérémie Dimino <jeremie@dimino.org>"
] ]
license: "LGPL-2.1" license: "LGPL-2.1 with OCaml linking exception"
homepage: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree" homepage: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree"
bug-reports: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree/issues" bug-reports: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree/issues"
dev-repo: "git+https://github.com/ocaml-ppx/ocaml-migrate-parsetree.git" dev-repo: "git+https://github.com/ocaml-ppx/ocaml-migrate-parsetree.git"
@ -17,7 +17,7 @@ depends: [
"result" "result"
"ppx_derivers" "ppx_derivers"
"dune" {build & >= "1.6.0"} "dune" {build & >= "1.6.0"}
"ocaml" {>= "4.02.3" & < "4.08.0"} "ocaml" {>= "4.02.3"}
] ]
synopsis: "Convert OCaml parsetrees between different versions" synopsis: "Convert OCaml parsetrees between different versions"
description: """ description: """
@ -29,6 +29,9 @@ rewriters independent of a compiler version.
""" """
url { url {
src: src:
"https://github.com/ocaml-ppx/ocaml-migrate-parsetree/releases/download/v1.2.0/ocaml-migrate-parsetree-v1.2.0.tbz" "https://github.com/ocaml-ppx/ocaml-migrate-parsetree/releases/download/v1.3.0/ocaml-migrate-parsetree-v1.3.0.tbz"
checksum: "md5=cc6fb09ad6f99156c7dba47711c62c6f" checksum: [
"sha256=dfb05a3611783f0a49325b1e185bb1827c263d9ca2228287da55f037ad3c280e"
"sha512=95a12f4e9e257395aeb5024f3acf4f8e419f6df8d94e611c3660a139254252aa5e462394a5ff91c2b238351bed946e0b5aee05f22e0e2e3350fb476ab3b8b510"
]
} }

27
esy.lock/opam/ppx_tools_versioned.5.2.1/opam

@ -1,27 +0,0 @@
opam-version: "2.0"
maintainer: "frederic.bour@lakaban.net"
authors: [
"Frédéric Bour <frederic.bour@lakaban.net>"
"Alain Frisch <alain.frisch@lexifi.com>"
]
license: "MIT"
homepage: "https://github.com/let-def/ppx_tools_versioned"
bug-reports: "https://github.com/let-def/ppx_tools_versioned/issues"
dev-repo: "git://github.com/let-def/ppx_tools_versioned.git"
tags: [ "syntax" ]
build: [
["jbuilder" "subst" "-p" name] {pinned}
["jbuilder" "build" "-p" name "-j" jobs]
["jbuilder" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "4.02.0"}
"jbuilder" {build & >= "1.0+beta17"}
"ocaml-migrate-parsetree" {>= "1.0.10" & < "1.3.0"}
]
synopsis: "A variant of ppx_tools based on ocaml-migrate-parsetree"
url {
src:
"https://github.com/ocaml-ppx/ppx_tools_versioned/archive/5.2.1.tar.gz"
checksum: "md5=1ae6ae43ec161fbbf12c2b4d3a7e26f5"
}

30
esy.lock/opam/ppx_tools_versioned.5.2.2/opam

@ -0,0 +1,30 @@
opam-version: "2.0"
maintainer: "frederic.bour@lakaban.net"
authors: [
"Frédéric Bour <frederic.bour@lakaban.net>"
"Alain Frisch <alain.frisch@lexifi.com>"
]
license: "MIT"
homepage: "https://github.com/ocaml-ppx/ppx_tools_versioned"
bug-reports: "https://github.com/ocaml-ppx/ppx_tools_versioned/issues"
dev-repo: "git://github.com/ocaml-ppx/ppx_tools_versioned.git"
tags: [ "syntax" ]
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "4.02.0"}
"dune" {build & >= "1.0"}
"ocaml-migrate-parsetree" {>= "1.0.10"}
]
synopsis: "A variant of ppx_tools based on ocaml-migrate-parsetree"
url {
src:
"https://github.com/ocaml-ppx/ppx_tools_versioned/archive/5.2.2.tar.gz"
checksum: [
"md5=f78a3c2b4cc3b92702e1f7096a6125fa"
"sha512=68c168ebc01af46fe8766ad7e36cc778caabb97d8eb303db284d106450cb79974c2a640ce459e197630b9e84b02caa24b59c97c9a8d39ddadc7efc7284e42a70"
]
}

35
esy.lock/opam/semver.0.1.0/opam

@ -1,35 +0,0 @@
opam-version: "2.0"
maintainer: "rudi.grinberg@gmail.com"
authors: [
"Tikhon Jelvis"
"Rudi Grinberg"
]
homepage: "https://github.com/rgrinberg/ocaml-semver"
bug-reports: "https://github.com/rgrinberg/ocaml-semver/issues"
license: "BSD3"
dev-repo: "git+https://github.com/rgrinberg/ocaml-semver.git"
build: [
["ocaml" "setup.ml" "-configure"]
["ocaml" "setup.ml" "-build"]
["ocaml" "setup.ml" "-configure" "--enable-tests"] {with-test}
["ocaml" "setup.ml" "-build"] {with-test}
["ocaml" "setup.ml" "-test"] {with-test}
["ocaml" "setup.ml" "-doc"] {with-doc}
]
install: ["ocaml" "setup.ml" "-install"]
remove: ["ocamlfind" "remove" "semver"]
depends: [
"ocaml" {>= "4.02.0"}
"ocamlfind" {build}
"ounit" {with-test}
"ocamlbuild" {build}
]
synopsis: "Semantic versioning module"
description: """
Provides a single module `Semver` that can parse, compare, and manipulate
software versions of the form x.x.x. See http://semver.org/"""
flags: light-uninstall
url {
src: "https://github.com/rgrinberg/ocaml-semver/archive/v0.1.0.tar.gz"
checksum: "md5=ce6614ba2f91754028b29a12989f9da6"
}

2
esy.lock/overrides/opam__s__conf_pkg_config_opam__c__1.1_opam_override/package.json

@ -1,5 +1,5 @@
{ {
"dependencies": { "dependencies": {
"yarn-pkg-config": "esy-ocaml/yarn-pkg-config#d488cd9321cd5036bd36ec96744ce78c5d45fc49" "yarn-pkg-config": "esy-ocaml/yarn-pkg-config#cca65f99674ed2d954d28788edeb8c57fada5ed0"
} }
} }

0
esy.lock/overrides/opam__s__dune_opam__c__1.9.1_opam_override/package.json → esy.lock/overrides/opam__s__dune_opam__c__1.9.3_opam_override/package.json

23
library/Semver.re

@ -0,0 +1,23 @@
[@deriving (eq, ord, make)]
type t = {
major: int,
minor: int,
patch: int,
};
let fromString = str =>
switch (
String.split_on_char('.', str)
|> List.map(int_of_string_opt)
|> Core.Option.all
) {
| Some([major, minor, patch]) => Some({major, minor, patch})
| _ => None
};
let toString = ({major, minor, patch}) =>
Printf.sprintf("%d.%d.%d", major, minor, patch);
let major = ({major, _}) => major;
let minor = ({minor, _}) => minor;
let patch = ({patch, _}) => patch;

11
library/Semver.rei

@ -0,0 +1,11 @@
[@deriving (eq, ord)]
type t;
let make: (~major: int, ~minor: int, ~patch: int) => t;
let fromString: string => option(t);
let toString: t => string;
let major: t => int;
let minor: t => int;
let patch: t => int;

2
library/Versions.re

@ -7,7 +7,7 @@ let flip = (fn, a, b) => fn(b, a);
let skip = (~amount, str) => let skip = (~amount, str) =>
Str.last_chars(str, String.length(str) - amount); Str.last_chars(str, String.length(str) - amount);
let parseSemver = version => version |> skip(~amount=1) |> Semver.of_string; let parseSemver = version => version |> skip(~amount=1) |> Semver.fromString;
let compare = (v1, v2) => let compare = (v1, v2) =>
switch (parseSemver(v1), parseSemver(v2)) { switch (parseSemver(v1), parseSemver(v2)) {

4
library/dune

@ -7,6 +7,6 @@
(name Fnm) (name Fnm)
; Other libraries list this name in their package.json 'require' field to use this library. ; Other libraries list this name in their package.json 'require' field to use this library.
(public_name fnm.lib) (public_name fnm.lib)
(libraries pastel.lib str core lwt ssl lwt_ssl lambdasoup semver cohttp cohttp-lwt cohttp-lwt-unix console.lib ) (libraries pastel.lib str core lwt ssl lwt_ssl lambdasoup cohttp cohttp-lwt cohttp-lwt-unix console.lib )
(preprocess ( pps lwt_ppx ppx_let ppx_deriving.show )) ; From package.json preprocess field (preprocess ( pps lwt_ppx ppx_let ppx_deriving.show ppx_deriving.eq ppx_deriving.make ppx_deriving.ord )) ; From package.json preprocess field
) )

7
package.json

@ -29,7 +29,10 @@
"pps", "pps",
"lwt_ppx", "lwt_ppx",
"ppx_let", "ppx_let",
"ppx_deriving.show" "ppx_deriving.show",
"ppx_deriving.eq",
"ppx_deriving.make",
"ppx_deriving.ord"
], ],
"require": [ "require": [
"pastel.lib", "pastel.lib",
@ -39,7 +42,6 @@
"ssl", "ssl",
"lwt_ssl", "lwt_ssl",
"lambdasoup", "lambdasoup",
"semver",
"cohttp", "cohttp",
"cohttp-lwt", "cohttp-lwt",
"cohttp-lwt-unix", "cohttp-lwt-unix",
@ -80,7 +82,6 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@opam/dune": "*", "@opam/dune": "*",
"@opam/semver": "*",
"@opam/core": "*", "@opam/core": "*",
"@opam/cmdliner": "*", "@opam/cmdliner": "*",
"@opam/lwt": "*", "@opam/lwt": "*",

1
test/TestFnm.re

@ -1,3 +1,4 @@
include SmokeTest; include SmokeTest;
include TestSemver;
TestFramework.cli(); TestFramework.cli();

27
test/TestSemver.re

@ -0,0 +1,27 @@
open TestFramework;
describe("Semver", ({test, _}) => {
open Fnm;
test("parses a string", ({expect, _}) => {
let x = Semver.fromString("1.2.3");
expect.equal(x, Some(Semver.make(~major=1, ~minor=2, ~patch=3)));
});
test("returns none on invalid semver", ({expect, _}) => {
let x = Semver.fromString("x1.2.3");
expect.equal(x, None);
});
test("compare versions", ({expect}) => {
let semver1 = Semver.make(~major=1, ~minor=2, ~patch=0);
let semver2 = Semver.make(~major=1, ~minor=2, ~patch=3);
let semver3 = Semver.make(~major=1, ~minor=3, ~patch=3);
let semver4 = Semver.make(~major=4, ~minor=3, ~patch=3);
let sorted =
List.sort(Semver.compare, [semver1, semver2, semver4, semver3]);
expect.list(sorted).toEqual([semver1, semver2, semver3, semver4]);
});
});
Loading…
Cancel
Save