Skip to content

Commit

Permalink
feat(parser-tests): add fibonacci parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
ksenmel committed Nov 21, 2024
1 parent aec0c86 commit a6e5e0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tests/parser/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name tests)
(modules parse_simple_expr parse_factorial)
(modules parse_simple_expr parse_factorial parse_fibonacci)
(libraries parser ast)
(preprocess
(pps ppx_expect ppx_deriving.show))
Expand Down
35 changes: 35 additions & 0 deletions lib/tests/parser/parse_fibonacci.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(* * Copyright 2024, raf-nr and ksenmel *)

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

open Base
open Parser

let%expect_test _ =
test_parse "let rec fib n = if n > 1 then fib (n - 1) + fib (n - 2) else 1";
[%expect {|
[(SDeclaration
(DRecursive
((PVar (Id "fib")),
(EFun (((PVar (Id "n")), []),
(EIfThenElse (
(EApplication ((EIdentifier (Id "( > )")),
[(EIdentifier (Id "n")); (EConstant (CInt 1))])),
(EApplication ((EIdentifier (Id "fib")),
[(EApplication ((EIdentifier (Id "n")),
[(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 1))]))
]
));
(EApplication ((EIdentifier (Id "( + )")),
[(EConstant (CInt 0)); (EIdentifier (Id "fib"))]));
(EApplication ((EIdentifier (Id "n")),
[(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 2))]))
]
))
]
)),
(Some (EConstant (CInt 1)))))
)))))
] |}]

0 comments on commit a6e5e0b

Please sign in to comment.