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

Use ppx_inline_test for unit tests #623

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coq-lsp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ depends: [
# waterproof parser
"menhir" { >= "20220210" }

# for unit testing
"alcotest" { >= "1.6.0" & with-test }
# unit testing
"ppx_inline_test" { >= "0.14.1" }

# Uncomment this for releases
# "coq" { >= "8.17" < "8.18" }
Expand Down
2 changes: 2 additions & 0 deletions coq/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
(public_name coq-lsp.coq)
; Unfortunate we have to link the STM due to the LTAC plugin
; depending on it, we should fix this upstream
(inline_tests)
(preprocess (pps ppx_inline_test))
Comment on lines +6 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the test library as a dependency to the executable, which is probably not what you want. I think it would be better to have a separate test library like before.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it? I think dune handles this properly.

(libraries lang coq-core.vernac coq-serapi.serlib))
28 changes: 28 additions & 0 deletions coq/utf8.ml
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,31 @@ let get_byte_offset_from_utf16_pos line (char : int) =
()
done;
if !byte_idx < String.length line then Some !byte_idx else None

let%test_unit "utf16 offsets" =
let testcases_x =
[ ("aax", 2, true)
; (" xoo", 2, true)
; ("0123", 4, false)
; (" 𝒞x", 4, true)
; (" 𝒞x𝒞", 4, true)
; (" 𝒞∫x", 5, true)
; (" 𝒞", 4, false)
; ("∫x.dy", 1, true)
]
in
List.iter
(fun (s, i, b) ->
let res = get_byte_offset_from_utf16_pos s i in
if b then
let res = Option.map (fun i -> s.[i]) res in
match res with
| Some x when x = 'x' -> ()
| Some x ->
failwith
(Printf.sprintf "Didn't find x in test %s : %d, instead: %c" s i x)
| None ->
failwith (Printf.sprintf "Didn't not find x in test %s : %d" s i)
else if res != None then
failwith (Printf.sprintf "Shouldn't find x in test %s : %d" s i))
testcases_x
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
in
l.attrValues {
inherit serapi;
inherit (ocamlPackages) yojson cmdliner uri dune-build-info;
inherit (ocamlPackages) yojson cmdliner uri dune-build-info ppx_inline_test;
};
};

Expand All @@ -90,7 +90,7 @@
packages = l.attrValues {
inherit (config.treefmt.build) wrapper;
inherit (pkgs) dune_3 nodejs dune-release;
inherit (ocamlPackages) ocaml ocaml-lsp alcotest;
inherit (ocamlPackages) ocaml ocamlformat ocaml-lsp;
};
};
};
Expand Down
4 changes: 0 additions & 4 deletions test/unit_test/dune

This file was deleted.

30 changes: 0 additions & 30 deletions test/unit_test/utf16_pos.ml

This file was deleted.

Loading