Skip to content

Commit

Permalink
Use ppx_inline_test for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ineol committed Nov 24, 2023
1 parent 008c6c2 commit 3dca3bc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion coq-lsp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ depends: [
"menhir" { >= "20220210" }

# for unit testing
"alcotest" { >= "1.6.0" & with-test }
"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))
(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.

0 comments on commit 3dca3bc

Please sign in to comment.