Skip to content

Commit

Permalink
feat(parser-tests): add empty list parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
ksenmel committed Nov 21, 2024
1 parent ae47417 commit 8214d42
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/tests/parser/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(library
(name tests)
(modules parse_simple_expr)
(libraries parser ast)
(preprocess
(pps ppx_expect ppx_deriving.show))
(inline_tests))
95 changes: 95 additions & 0 deletions lib/tests/parser/parse_simple_expr.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(* * Copyright 2024, raf-nr and ksenmel *)

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

open Base
open Parser

(* Constants *)

let%expect_test _ =
test_parse {| 1 |};
[%expect {| [(SExpression (EConstant (CInt 1)))] |}]

let%expect_test _ =
test_parse {| -1 |};
[%expect {|
[(SExpression
(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 1))])))
] |}]

let%expect_test _ =
test_parse {| ((((-1)))) |};
[%expect {|
[(SExpression
(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 1))])))
] |}]


(* Binary and unary operations *)

let%expect_test _ =
test_parse {| 1 + 2 + 3 * 4 |};
[%expect {|
[(SExpression
(EApplication ((EIdentifier (Id "( * )")),
[(EApplication ((EConstant (CInt 1)),
[(EApplication ((EIdentifier (Id "( + )")),
[(EConstant (CInt 0)); (EConstant (CInt 2))]));
(EApplication ((EIdentifier (Id "( + )")),
[(EConstant (CInt 0)); (EConstant (CInt 3))]))
]
));
(EConstant (CInt 4))]
)))
] |}]
;;

let%expect_test _ =
test_parse {| 1 * (+ 2) / ( - 3) - 4 |};
[%expect {|
[(SExpression
(EApplication ((EIdentifier (Id "( - )")),
[(EApplication ((EIdentifier (Id "( / )")),
[(EApplication ((EIdentifier (Id "( * )")),
[(EConstant (CInt 1));
(EApplication ((EIdentifier (Id "( + )")),
[(EConstant (CInt 0)); (EConstant (CInt 2))]))
]
));
(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 3))]))
]
));
(EConstant (CInt 4))]
)))
] |}]


let%expect_test _ =
test_parse {| ((-(+(-1)))) |};
[%expect {|
[(SExpression
(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0));
(EApplication ((EIdentifier (Id "( + )")),
[(EConstant (CInt 0));
(EApplication ((EIdentifier (Id "( - )")),
[(EConstant (CInt 0)); (EConstant (CInt 1))]))
]
))
]
)))
] |}]
;;

(* List *)

let%expect_test _ =
test_parse {| [] |};
[%expect {| [(SExpression EEmptyList)] |}]
;;

(* Tuple *)

0 comments on commit 8214d42

Please sign in to comment.