-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTestTypeErrors.fs
148 lines (130 loc) · 3.79 KB
/
TestTypeErrors.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
module Rezoom.SQL.Test.TestTypeErrors
open System
open NUnit.Framework
open FsUnit
open Rezoom.SQL.Compiler
open Rezoom.SQL.Mapping
[<Test>]
let ``incompatible types can't be compared for equality`` () =
expectError (Error.cannotUnify "INT" "STRING")
"""
select g.*, u.*
from Users u
left join UserGroupMaps gm on gm.UserId = u.Id
left join Groups g on g.Id = 'a'
where g.Name like '%grp%' escape '%'
"""
[<Test>]
let ``unioned queries must have the same number of columns`` () =
expectError (Error.expectedKnownColumnCount 2 3)
"""
select 1 a, 2 b, 3 c
union all
select 4, 5
"""
[<Test>]
let ``updates must set actual columns`` () =
expectError (Error.noSuchColumnToSet "Users" "Nane")
"""
update Users
set Id = 1, Nane = ''
where Id > 5
"""
[<Test>]
let ``updated column types must match`` () =
expectError (Error.cannotUnify "INT" "STRING")
"""
update Users
set Id = 'five'
"""
[<Test>]
let ``inserted column types must match`` () =
expectError (Error.cannotUnify "INT" "STRING")
"""
insert into Users(Id, Name, Email, Password, Salt)
values ('one', 'jim', 'jim@example.com', x'', x'')
"""
[<Test>]
let ``inserted columns must exist`` () =
expectError (Error.noSuchColumn "Goober")
"""
insert into Users(Goober, Booger) values ('one', 'jim')
"""
[<Test>]
let ``sum argument must be numeric`` () =
expectError (Error.cannotUnify "<numeric>" "STRING")
"""
select sum(Name) as Sum from Users
"""
[<Test>]
let ``can't use list-parameter as a scalar result`` () =
expectError (Error.cannotUnify "<scalar>" "[INT]")
"""
select @p as x
from Users
where Id in @p
"""
[<Test>]
let ``insert without values for columns`` () =
expectError (Error.expectedKnownColumnCount 1 5)
"""
insert into Users(Id, Name, Email, Password, Salt) values (1)
"""
[<Test>]
let ``insert without columns required in table`` () =
expectError (Error.insertMissingColumns ["Email"])
"""
insert into Users(Name) values ('x')
"""
[<Test>]
let ``insert into view bad`` () =
expectError Error.insertIntoNonTable
"""
insert into ViewUsers(Id) values (1)
"""
[<Test>]
let ``update view bad`` () =
expectError (Error.objectNotATable "ViewUsers")
"""
update ViewUsers set Id = 1
"""
[<Test>]
let ``delete from view bad`` () =
expectError (Error.objectNotATable "ViewUsers")
"""
delete from ViewUsers
"""
[<Test>]
let ``where clause must be bool`` ()=
expectError (Error.cannotUnify StringType BooleanType)
"""
select 1 as it from ViewUsers where 'a'
"""
[<Test>]
let ``cte is not in scope for update`` () =
expectError (Error.objectNotATable "cte")
"""
with cte(x) as (select 1) update cte set x = 1;
"""
[<Test>]
let ``ambiguous columns`` () =
expectError (Error.ambiguousColumn "Id")
"""
select *
from users u
join usergroupmaps ugm on ugm.userid = u.id
join groups g on g.id = ugm.groupid
"""
[<Test>]
let ``duplicate column insert`` () =
expectError (Error.insertDuplicateColumn "Email")
"""
insert into Users(Name, Email, Email) values ('', '', '');
"""
[<Test>]
let ``duplicate column update`` () =
expectError (Error.updateDuplicateColumn "Name")
"""
update Users set Name = 'foo', Email = 'bar', Name = 'car'
where Id = 1
"""