From a9f8c77abc8463adafc30981306a5c5347cc9970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ch=C3=A1varri?= Date: Thu, 15 Aug 2024 12:47:47 +0200 Subject: [PATCH] Add locations-check test (#844) * add locations-check test * update tests --- ppx/test/locations-check.t | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ppx/test/locations-check.t diff --git a/ppx/test/locations-check.t b/ppx/test/locations-check.t new file mode 100644 index 000000000..0520bb96e --- /dev/null +++ b/ppx/test/locations-check.t @@ -0,0 +1,66 @@ +Test the preprocessed reason-react components have well-formed locations. +Uses https://github.com/ocaml-ppx/ppxlib/blob/44583fc14c3cc39ee6269ffd69f52146283f72c0/src/location_check.mli + +With no annotations (ppx does nothing) + + $ cat >input.ml < let make ~foo ~bar = + > (div + > ~children:[ React.string foo; bar |> string_of_int |> React.string ] + > ()) + > EOF + + $ reason-react-ppx -check -locations-check input.ml + let make ~foo ~bar = + div ~children:[React.string foo; (bar |> string_of_int) |> React.string] () + +With JSX annotation + + $ cat >input.ml < let make ~foo ~bar = + > (div + > ~children:[ React.string foo; bar |> string_of_int |> React.string ] + > () [@JSX]) + > EOF + + $ reason-react-ppx -check -locations-check input.ml + File "input.ml", line 2, characters 3-6: + 2 | (div + ^^^ + Error: invalid output from ppx, expression overlaps with expression at location: + File "input.ml", line 2, characters 2-96: + [1] + +With @react.component annotation + + $ cat >input.ml < let[@react.component] make ~foo ~bar = + > (div + > ~children:[ React.string foo; bar |> string_of_int |> React.string ] + > () [@JSX]) + > EOF + + $ reason-react-ppx -check -locations-check input.ml + File "input.ml", line 1, characters 33-36: + 1 | let[@react.component] make ~foo ~bar = + ^^^ + Error: invalid output from ppx, core type overlaps with core type at location: + File "input.ml", line 1, characters 33-36: + [1] + +Everything + + $ cat >input.ml < let[@react.component] make ~foo ~bar = + > (div + > ~children:[ React.string foo; bar |> string_of_int |> React.string ] + > () [@JSX]) + > EOF + + $ reason-react-ppx -check -locations-check input.ml + File "input.ml", line 1, characters 33-36: + 1 | let[@react.component] make ~foo ~bar = + ^^^ + Error: invalid output from ppx, core type overlaps with core type at location: + File "input.ml", line 1, characters 33-36: + [1]