Skip to content

Commit

Permalink
feat(parser-tests): add tests for binary and unary operations parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ksenmel committed Nov 18, 2024
1 parent fb92dfb commit ea61bd9
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions lib/tests/parser/test_parser.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
(* * Copyright 2024, raf-nr and ksenmel *)

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

open Base
open Parser


(* 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)); (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))])))
] |}]


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))]))
]
))
]
)))
] |}]



0 comments on commit ea61bd9

Please sign in to comment.