PageRenderTime 9ms CodeModel.GetById 6ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

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