44
44
. " CREATE TABLE mytab123 (f1 int, f2 text);\n "
45
45
. " CREATE TABLE mytab246 (f1 int, f2 text);\n "
46
46
. " CREATE TABLE \" mixedName\" (f1 int, f2 text);\n "
47
- . " CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n " );
47
+ . " CREATE TYPE enum1 AS ENUM ('foo', 'bar', 'baz', 'BLACK');\n "
48
+ . " CREATE PUBLICATION some_publication;\n " );
48
49
49
50
# Developers would not appreciate this test adding a bunch of junk to
50
51
# their ~/.psql_history, so be sure to redirect history into a temp file.
@@ -131,7 +132,8 @@ sub clear_query
131
132
{
132
133
local $Test::Builder::Level = $Test::Builder::Level + 1;
133
134
134
- check_completion(" \\ r\n " , qr / postgres=# / , " \\ r works" );
135
+ check_completion(" \\ r\n " , qr / Query buffer reset.*postgres=# / s ,
136
+ " \\ r works" );
135
137
return ;
136
138
}
137
139
@@ -188,18 +190,26 @@ sub clear_line
188
190
qr / "mytab123" +"mytab246"/ ,
189
191
" offer multiple quoted table choices" );
190
192
191
- check_completion(" 2\t " , qr / 246" / ,
193
+ # note: broken versions of libedit want to backslash the closing quote;
194
+ # not much we can do about that
195
+ check_completion(" 2\t " , qr / 246\\ ?" / ,
192
196
" finish completion of one of multiple quoted table choices" );
193
197
194
- clear_query();
198
+ # note: broken versions of libedit may leave us in a state where psql
199
+ # thinks there's an unclosed double quote, so that we have to use
200
+ # clear_line not clear_query here
201
+ clear_line();
195
202
196
203
# check handling of mixed-case names
204
+ # note: broken versions of libedit want to backslash the closing quote;
205
+ # not much we can do about that
197
206
check_completion(
198
207
" select * from \" mi\t " ,
199
- qr / "mixedName" / ,
208
+ qr / "mixedName\\ ?" / ,
200
209
" complete a mixed-case name" );
201
210
202
- clear_query();
211
+ # as above, must use clear_line not clear_query here
212
+ clear_line();
203
213
204
214
# check case folding
205
215
check_completion(
@@ -214,7 +224,8 @@ sub clear_line
214
224
# differently, so just check that the replacement comes out correctly
215
225
check_completion(" \\ DRD\t " , qr / drds / , " complete \\ DRD<tab> to \\ drds" );
216
226
217
- clear_query();
227
+ # broken versions of libedit require clear_line not clear_query here
228
+ clear_line();
218
229
219
230
# check completion of a schema-qualified name
220
231
check_completion(
@@ -258,6 +269,15 @@ sub clear_line
258
269
259
270
clear_query();
260
271
272
+ # check variant where we're completing a qualified name from a refname
273
+ # (this one also checks successful completion in a multiline command)
274
+ check_completion(
275
+ " comment on constraint tab1_pkey \n on public.\t " ,
276
+ qr / public\. tab1/ ,
277
+ " complete qualified name from object reference" );
278
+
279
+ clear_query();
280
+
261
281
# check filename completion
262
282
check_completion(
263
283
" \\ lo_import tmp_check/some\t " ,
@@ -272,7 +292,8 @@ sub clear_line
272
292
qr | tmp_check/af\a ?ile| ,
273
293
" filename completion with multiple possibilities" );
274
294
275
- clear_query();
295
+ # broken versions of libedit require clear_line not clear_query here
296
+ clear_line();
276
297
277
298
# COPY requires quoting
278
299
# note: broken versions of libedit want to backslash the closing quote;
@@ -342,6 +363,72 @@ sub clear_line
342
363
clear_query();
343
364
}
344
365
366
+ # alternate path where keyword comes from SchemaQuery
367
+ check_completion(
368
+ " DROP TYPE big\t " ,
369
+ qr / DROP TYPE bigint / ,
370
+ " offer keyword from SchemaQuery" );
371
+
372
+ clear_query();
373
+
374
+ # check create_command_generator
375
+ check_completion(
376
+ " CREATE TY\t " ,
377
+ qr / CREATE TYPE / ,
378
+ " check create_command_generator" );
379
+
380
+ clear_query();
381
+
382
+ # check words_after_create infrastructure
383
+ check_completion(
384
+ " CREATE TABLE mytab\t\t " ,
385
+ qr / mytab123 +mytab246/ ,
386
+ " check words_after_create" );
387
+
388
+ clear_query();
389
+
390
+ # check VersionedQuery infrastructure
391
+ check_completion(
392
+ " DROP PUBLIC\t \t\t " ,
393
+ qr / DROP PUBLICATION\s +some_publication / ,
394
+ " check VersionedQuery" );
395
+
396
+ clear_query();
397
+
398
+ # hits ends_with() and logic for completing in multi-line queries
399
+ check_completion(" analyze (\n\t\t " , qr / VERBOSE/ ,
400
+ " check ANALYZE (VERBOSE ..." );
401
+
402
+ clear_query();
403
+
404
+ # check completions for GUCs
405
+ check_completion(
406
+ " set interval\t\t " ,
407
+ qr / intervalstyle TO/ ,
408
+ " complete a GUC name" );
409
+ check_completion(" iso\t " , qr / iso_8601 / , " complete a GUC enum value" );
410
+
411
+ clear_query();
412
+
413
+ # check completions for psql variables
414
+ check_completion(" \\ set VERB\t " , qr / VERBOSITY / ,
415
+ " complete a psql variable name" );
416
+ check_completion(" def\t " , qr / default / , " complete a psql variable value" );
417
+
418
+ clear_query();
419
+
420
+ check_completion(
421
+ " \\ echo :VERB\t " ,
422
+ qr / :VERBOSITY / ,
423
+ " complete an interpolated psql variable name" );
424
+
425
+ clear_query();
426
+
427
+ # check no-completions code path
428
+ check_completion(" blarg \t\t " , qr // , " check completion failure path" );
429
+
430
+ clear_query();
431
+
345
432
# send psql an explicit \q to shut it down, else pty won't close properly
346
433
$timer -> start(5);
347
434
$in .= " \\ q\n " ;
0 commit comments