Skip to content

Commit

Permalink
Tests for L3
Browse files Browse the repository at this point in the history
Signed-off-by: Kakadu <[email protected]>
  • Loading branch information
Kakadu committed Jan 24, 2024
1 parent cc82310 commit cb2c2ae
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
path = ostap
url = https://github.com/PLTools/ostap.git
branch = old+dune

[submodule "ppx_blob"]
path = ppx_blob
url = https://github.com/actionshrimp/ppx_blob.git
branch = fix-for-dune-3

1 change: 1 addition & 0 deletions .ocamlformat-enable
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
client.ml
L3/testL3.ml
16 changes: 0 additions & 16 deletions L3/L3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,3 @@ let json_to_bytecode ~fk ~fk2 : Yojson.Safe.t -> SM.t =
| _ -> fk2 "ожидался список"
*)


let () =
let input = {|
let fix = { f x -> f ({ eta -> fix(f, eta) },x) } in
( let fac = { self n -> if n<=1 then 1 else n*self(n-1) fi } in
write(fix(fac, 4))
)
|} in
match Parser.parse input with
| `Fail msg -> print_endline msg
| `Ok ast ->
match Program.eval [3] ast with
| rez -> Format.printf "%a\n%!" (Format.pp_print_list Format.pp_print_int) rez
| exception exc -> print_endline (Printexc.to_string exc)

17 changes: 17 additions & 0 deletions L3/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@
(preprocess
(action
(run %{project_root}/pp5+gt+plugins+ostap+dump.byte %{input-file}))))

(library
(name testL3)
(modules testL3)
(libraries L3)
(inline_tests)
(flags
(:standard -rectypes))
(preprocessor_deps
(file t01.l3)
(file t02.l3)
(file t03.l3)
(file t04.l3)
(file t05.l3)
(file t06.l3))
(preprocess
(pps ppx_expect ppx_blob)))
50 changes: 50 additions & 0 deletions L3/testL3.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
open L3

let test input =
match Parser.parse input with
| `Fail msg -> print_endline msg
| `Ok ast -> (
match Program.eval [ 3 ] ast with
| rez ->
Format.printf "%a\n%!" (Format.pp_print_list Format.pp_print_int) rez
| exception exc -> print_endline (Printexc.to_string exc))

let%expect_test " " =
test
{|
let fix = { f x -> f ({ eta -> fix(f, eta) },x) } in
( let fac = { self n -> if n<=1 then 1 else n*self(n-1) fi } in
write(fix(fac, 4))
)
|};
[%expect "L3.Program.Undefined(\"fix\")"]

let%expect_test " " =
test [%blob "t01.l3"];
[%expect "
1
5"]

let%expect_test " " =
test [%blob "t02.l3"];
[%expect "
543210
0"]

let%expect_test " " =
test [%blob "t03.l3"];
[%expect "120"]

let%expect_test " " =
test [%blob "t04.l3"];
[%expect "120"]

let%expect_test " " =
test [%blob "t05.l3"];
[%expect "
1111
12"]

let%expect_test " " =
test [%blob "t06.l3"];
[%expect "120"]
1 change: 1 addition & 0 deletions ppx_blob
Submodule ppx_blob added at 513d84

0 comments on commit cb2c2ae

Please sign in to comment.