/
ref.t
202 lines (180 loc) · 2.79 KB
/
ref.t
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# vi:ft=
use strict;
use warnings;
use t::Cheater;
plan tests => 1 * blocks();
no_diff;
run_tests;
__DATA__
=== TEST 1: int ref
--- src
table dogs (
id serial 1..50;
age integer not null;
)
table cats (
id serial;
friend references dogs.id;
)
4 dogs;
7 cats;
--- out
cats
id friend
96371 44
170828 37
577303 NULL
692194 20
749901 23
785799 44
870465 20
dogs
id age
20 -224492
23 -239639
37 424094
44 -64078
=== TEST 2: text ref
--- src
table dogs (
id serial 1..50;
grades text /[A-E]/ not null;
)
table cats (
id serial;
friend_grades references dogs.grades;
)
4 dogs;
8 cats;
--- out
cats
id friend_grades
96371 B
170828 B
368766 D
577303 D
692194 B
749901 NULL
785799 B
870465 D
dogs
id grades
6 B
16 D
22 A
27 B
=== TEST 3: text ref (not null on foreign keys)
--- src
table dogs (
id serial 1..50;
grades text /[A-E]/ not null;
)
table cats (
id serial;
friend_grades references dogs.grades not null;
)
4 dogs;
8 cats;
--- out
cats
id friend_grades
96371 A
170828 B
368766 B
577303 B
692194 D
749901 D
785799 B
870465 D
dogs
id grades
7 B
8 D
44 A
48 B
=== TEST 4: text refs in parallel
--- src
table dogs (
id serial 1..50;
grades text /[A-E]/ not null;
)
table cats (
id serial;
friend_grades references dogs.grades not null;
)
table birds (
id serial;
foo references dogs.grades not null;
);
4 dogs;
4 cats;
4 birds;
--- out
birds
id foo
96371 B
170828 B
749901 D
870465 B
cats
id friend_grades
163189 B
568585 B
867719 A
959066 B
dogs
id grades
7 B
8 B
44 D
48 A
=== TEST 5: text refs in series
--- src
table dogs (
id serial 1..50;
grades text /[A-E]/ not null;
)
table cats (
id serial;
friend_grades references dogs.grades not null;
)
table birds (
id serial;
foo references cats.friend_grades not null;
);
4 dogs;
4 cats;
4 birds;
--- out
birds
id foo
96371 D
170828 B
749901 B
870465 B
cats
id friend_grades
260361 B
275508 B
435922 D
924094 B
dogs
id grades
7 B
8 B
44 D
48 A
=== TEST 6: int ref
--- src
table dogs (
id serial 1..50;
self_id references dogs.id not null;
)
4 dogs;
--- out
dogs
id self_id
19 44
38 40
40 38
44 38