Skip to content

Commit

Permalink
test: add basic e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Apr 12, 2024
1 parent 5a70bd4 commit c299afb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/example/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name main))

(cram (deps ./main.exe))
15 changes: 15 additions & 0 deletions test/example/dune-project
Original file line number Diff line number Diff line change
@@ -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}))))

25 changes: 25 additions & 0 deletions test/example/main.mlx
Original file line number Diff line number Diff line change
@@ -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</%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 (
<div>
<div>(text "title")</div>
<div>(text "content")</div>
</div>
))
10 changes: 10 additions & 0 deletions test/example/test.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

$ ./main.exe
<div>
<div>
title
</div>
<div>
content
</div>
</div>

0 comments on commit c299afb

Please sign in to comment.