/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscExpressions.lhs

http://github.com/JakeWheat/hssqlppp · Haskell · 63 lines · 56 code · 7 blank · 0 comment · 0 complexity · 8de757c8b158768297e6939a8115fd11 MD5 · raw file

  1. > module Database.HsSqlPpp.Tests.TypeChecking.MiscExpressions
  2. > (miscExpressionsTestData) where
  3. >
  4. > import Database.HsSqlPpp.Tests.TypeChecking.Utils
  5. > import Database.HsSqlPpp.Types
  6. >
  7. >
  8. > miscExpressionsTestData :: Item
  9. > miscExpressionsTestData =
  10. > Group "misc expressions" [
  11. ~~~~
  12. implicit casting and function/operator choice tests:
  13. check when multiple implicit and one exact match on num args
  14. check multiple matches with num args, only one with implicit conversions
  15. check multiple implicit matches with one preferred
  16. check multiple implicit matches with one preferred highest count
  17. check casts from unknown string lits
  18. ~~~~
  19. > Group "some expressions" [
  20. > e "3 + '4'" $ Right typeInt
  21. > ,e "3.0 + '4'" $ Right typeNumeric
  22. > ,e "'3' + '4'" $ Left [NoMatchingOperator "+" [UnknownType
  23. > ,UnknownType]]
  24. > ]
  25. > ,Group "exists expressions" [
  26. > e "exists (select 1 from pg_type)" $ Right typeBool
  27. > ,e "exists (select testit from pg_type)"
  28. > $ Left [UnrecognisedIdentifier "testit"]
  29. > ]
  30. > ,Group "polymorphic functions" [
  31. > e "array_append(ARRAY[1,2], 3)"
  32. > $ Right (ArrayType typeInt)
  33. > ,e "array_append(ARRAY['a','b'], 'c')"
  34. > $ Right (ArrayType UnknownType)
  35. > ,e "array_append(ARRAY['a','b'], 'c'::text)"
  36. > $ Right (ArrayType $ ScalarType "text")
  37. > ,e "array_append(ARRAY['a','b'::text], 'c')"
  38. > $ Right (ArrayType $ ScalarType "text")
  39. > ,e "array_append(ARRAY['a'::int,'b'], 'c')"
  40. > $ Right (ArrayType typeInt)
  41. > ]
  42. > ,Group "cast expressions" [
  43. > e "cast ('1' as integer)"
  44. > $ Right typeInt
  45. > ,e "cast ('1' as baz)"
  46. > $ Left [UnknownTypeName "baz"]
  47. > ,e "array[]" -- FIXME: this isn't quite right but not sure how to do it atm
  48. > -- no point fixing this case since need a load of other
  49. > -- test cases where the behaviour is different
  50. > $ Right (Pseudo AnyArray) -- Left [TypelessEmptyArray]
  51. > ,e "array[] :: text[]"
  52. > $ Right (ArrayType (ScalarType "text"))
  53. > ]
  54. > ]
  55. > where
  56. > e = Expr