Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pcre): regression test #411 #412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

rgrinberg
Copy link
Member

@RiderALT I tried reproducing the issue. I'm not sure which semver string isn't parsing correctly. Could you adjust this test to demonstrate the problem perhaps?

@RiderALT
Copy link

RiderALT commented Sep 7, 2024

this is simple - don't print content of the parse result. Just check length of Arrays and Lists.
Working test:

open Import
module Pcre = Re_private.Pcre

let rex =
  Pcre.regexp
    ("^\\s*[v=]*\\s*"
     (* optional version identifier *)
     ^ "([0-9]+|[xX*])(\\.([0-9]+|[xX*])?(\\.([0-9]+|[xX*])?)?)?"
     (* 3-dotted notation *)
     ^ "(?:-((?:[a-zA-Z0-9]+|[a-zA-Z0-9-])(?:\\.[a-zA-Z0-9]+|[a-zA-Z0-9-])*))?"
     ^ (* pre release *)
     "(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?\\s*$" (* build indentifier *))
;;

let sep_re = Pcre.regexp "\\."

let test version =
  try
    let parsed = Pcre.extract ~rex version in
    let pre = Pcre.split ~rex:sep_re parsed.(6) in
    let build = Pcre.split ~rex:sep_re parsed.(7) in
    printf
      "%i %i %i"
      (Array.length parsed)
      (List.length pre)
      (List.length build)
  with
  | Not_found -> Printf.printf "%s: Parsing Error. Invalid Version\n" version
;;

let%expect_test "regression test" =
  test "v1.2.3";
  [%expect {| 8 0 0 |}];
  test "=1.2.3";
  [%expect {| 8 0 0 |}];
  test "v 1.2.3";
  [%expect {| 8 0 0 |}];
  test "= 1.2.3";
  [%expect {| 8 0 0 |}];
  test " v1.2.3";
  [%expect {| 8 0 0 |}];
  test " =1.2.3";
  [%expect {| 8 0 0 |}];
  test " v 1.2.3";
  [%expect {| 8 0 0 |}];
  test " = 1.2.3";
  [%expect {| 8 0 0 |}];
  test "1.2.3-0";
  [%expect {| 8 1 0 |}];
  test "v1.2.3-1";
  [%expect {| 8 1 0 |}];
  test "v1.2.3-beta";
  [%expect {| 8 1 0 |}];
  test "=1.2.3-beta";
  [%expect {| 8 1 0 |}];
  test "1.2.3-beta";
  [%expect {| 8 1 0 |}];
  test "1.2.3-beta+build";
  [%expect {| 8 1 1 |}];
  test "1.2.3+build";
  [%expect {| 8 1 0 |}];
  test "  v1.2.3+build";
  [%expect {| 8 0 1 |}];
;;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants