get_type.ml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. module Get_type = Qsp_syntax.Get_type
  2. module T = Qsp_syntax.T
  3. let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
  4. let type_of : Get_type.t Alcotest.testable =
  5. Alcotest.testable Get_type.pp Get_type.equal
  6. let add_number () =
  7. let actual =
  8. Get_type.boperator _position T.Plus
  9. (Get_type.integer _position "0")
  10. (Get_type.integer _position "1")
  11. in
  12. let expected = Get_type.(Raw Integer) in
  13. let msg = "Adding integer" in
  14. Alcotest.(check' type_of ~msg ~expected ~actual)
  15. let add_literal_number () =
  16. let actual =
  17. Get_type.boperator _position T.Plus
  18. (Get_type.literal _position [ T.Text "2" ])
  19. (Get_type.integer _position "1")
  20. in
  21. let expected = Get_type.(Raw Integer) in
  22. let msg = "A string containing integer is considered as integer" in
  23. Alcotest.(check' type_of ~msg ~expected ~actual)
  24. let concat_text () =
  25. let actual =
  26. Get_type.boperator _position T.Plus
  27. (Get_type.literal _position [ T.Text "a" ])
  28. (Get_type.integer _position "1")
  29. in
  30. let expected = Get_type.(Raw String) in
  31. let msg = "Concatenate" in
  32. Alcotest.(check' type_of ~msg ~expected ~actual)
  33. let test =
  34. ( "Type expression",
  35. [
  36. Alcotest.test_case "int + int" `Quick add_number;
  37. Alcotest.test_case "'int' + int" `Quick add_literal_number;
  38. Alcotest.test_case "str + int" `Quick concat_text;
  39. ] )