From c299afbdff93762f4ee9aa6bcb7665a1177892d0 Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Fri, 12 Apr 2024 16:04:58 +0300 Subject: [PATCH] test: add basic e2e test --- test/example/dune | 4 ++++ test/example/dune-project | 15 +++++++++++++++ test/example/main.mlx | 25 +++++++++++++++++++++++++ test/example/test.t | 10 ++++++++++ 4 files changed, 54 insertions(+) create mode 100644 test/example/dune create mode 100644 test/example/dune-project create mode 100644 test/example/main.mlx create mode 100644 test/example/test.t diff --git a/test/example/dune b/test/example/dune new file mode 100644 index 0000000..2e305b1 --- /dev/null +++ b/test/example/dune @@ -0,0 +1,4 @@ +(executable + (name main)) + +(cram (deps ./main.exe)) diff --git a/test/example/dune-project b/test/example/dune-project new file mode 100644 index 0000000..025d490 --- /dev/null +++ b/test/example/dune-project @@ -0,0 +1,15 @@ +(lang dune 3.10) + +(generate_opam_files false) + +(package + (name mlx-example) + (depends dune mlx)) + +(dialect + (name mlx) + (implementation + (extension mlx) + (preprocess + (run mlx-pp %{input-file})))) + diff --git a/test/example/main.mlx b/test/example/main.mlx new file mode 100644 index 0000000..fda8058 --- /dev/null +++ b/test/example/main.mlx @@ -0,0 +1,25 @@ +open Printf + +type doc = Element of string * doc list | Text of string + +let render d = + let rec render indent = + let indents = List.init indent (fun _ -> " ") |> String.concat "" in + function + | Element(name, children) -> + let children = List.map (render (indent + 1)) children in + sprintf "%s<%s>\n%s\n%s" indents name (String.concat "\n" children) indents name + | Text s -> sprintf "%s%s" indents s + in + render 0 d + +let div ~children () = Element ("div", children) +let text s = Text s + +let () = + print_endline (render ( +
+
(text "title")
+
(text "content")
+
+ )) diff --git a/test/example/test.t b/test/example/test.t new file mode 100644 index 0000000..fa7ef64 --- /dev/null +++ b/test/example/test.t @@ -0,0 +1,10 @@ + + $ ./main.exe +
+
+ title +
+
+ content +
+