mirror of
https://github.com/postgres/postgres.git
synced 2025-05-29 16:21:20 +03:00
Improve regression test coverage of regress.c.
It's a bit silly to have test functions that aren't tested, so test them. In passing, rename int44in/int44out to city_budget_in/_out so that they match how the regression tests use them. Also, fix city_budget_out so that it emits the format city_budget_in expects to read; otherwise we'd have dump/reload failures when testing pg_dump against the regression database. (We avoided that in the past only because no data of type city_budget was actually stored anywhere.) Discussion: https://postgr.es/m/29322.1519701006@sss.pgh.pa.us
This commit is contained in:
parent
db3af9feb1
commit
be42eb9d62
@ -24,6 +24,16 @@ INSERT INTO equipment_r (name, hobby) VALUES ('advil', 'posthacking');
|
|||||||
INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
|
INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
|
||||||
INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
|
INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
|
||||||
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
|
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
|
||||||
|
INSERT INTO city VALUES
|
||||||
|
('Podunk', '(1,2),(3,4)', '100,127,1000'),
|
||||||
|
('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
|
||||||
|
TABLE city;
|
||||||
|
name | location | budget
|
||||||
|
--------+----------------------+-----------------------
|
||||||
|
Podunk | (3,4),(1,2) | 100,127,1000,0
|
||||||
|
Gotham | (1100,334),(1000,34) | 123456,127,-1000,6789
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
INTO TABLE ramp
|
INTO TABLE ramp
|
||||||
FROM road
|
FROM road
|
||||||
|
@ -26,6 +26,14 @@ CREATE OPERATOR #%# (
|
|||||||
leftarg = int8, -- right unary
|
leftarg = int8, -- right unary
|
||||||
procedure = numeric_fac
|
procedure = numeric_fac
|
||||||
);
|
);
|
||||||
|
-- Test operator created above
|
||||||
|
SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
|
||||||
|
point '(1,2)' <% widget '(0,0,1)' AS f;
|
||||||
|
t | f
|
||||||
|
---+---
|
||||||
|
t | f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Test comments
|
-- Test comments
|
||||||
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
|
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
|
||||||
ERROR: operator does not exist: integer ######
|
ERROR: operator does not exist: integer ######
|
||||||
|
@ -16,8 +16,8 @@ CREATE TYPE widget (
|
|||||||
);
|
);
|
||||||
CREATE TYPE city_budget (
|
CREATE TYPE city_budget (
|
||||||
internallength = 16,
|
internallength = 16,
|
||||||
input = int44in,
|
input = city_budget_in,
|
||||||
output = int44out,
|
output = city_budget_out,
|
||||||
element = int4,
|
element = int4,
|
||||||
category = 'x', -- just to verify the system will take it
|
category = 'x', -- just to verify the system will take it
|
||||||
preferred = true -- ditto
|
preferred = true -- ditto
|
||||||
@ -182,3 +182,12 @@ WHERE attrelid = 'mytab'::regclass AND attnum > 0;
|
|||||||
widget(42,13)
|
widget(42,13)
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- might as well exercise the widget type while we're here
|
||||||
|
INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
|
||||||
|
TABLE mytab;
|
||||||
|
foo
|
||||||
|
--------------
|
||||||
|
(1,2,3)
|
||||||
|
(-44,5.5,12)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ CREATE FUNCTION widget_out(widget)
|
|||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
|
|
||||||
CREATE FUNCTION int44in(cstring)
|
CREATE FUNCTION city_budget_in(cstring)
|
||||||
RETURNS city_budget
|
RETURNS city_budget
|
||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
|
|
||||||
CREATE FUNCTION int44out(city_budget)
|
CREATE FUNCTION city_budget_out(city_budget)
|
||||||
RETURNS cstring
|
RETURNS cstring
|
||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
|
@ -12,13 +12,13 @@ CREATE FUNCTION widget_out(widget)
|
|||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
NOTICE: argument type widget is only a shell
|
NOTICE: argument type widget is only a shell
|
||||||
CREATE FUNCTION int44in(cstring)
|
CREATE FUNCTION city_budget_in(cstring)
|
||||||
RETURNS city_budget
|
RETURNS city_budget
|
||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
NOTICE: type "city_budget" is not yet defined
|
NOTICE: type "city_budget" is not yet defined
|
||||||
DETAIL: Creating a shell type definition.
|
DETAIL: Creating a shell type definition.
|
||||||
CREATE FUNCTION int44out(city_budget)
|
CREATE FUNCTION city_budget_out(city_budget)
|
||||||
RETURNS cstring
|
RETURNS cstring
|
||||||
AS '@libdir@/regress@DLSUFFIX@'
|
AS '@libdir@/regress@DLSUFFIX@'
|
||||||
LANGUAGE C STRICT IMMUTABLE;
|
LANGUAGE C STRICT IMMUTABLE;
|
||||||
|
@ -427,19 +427,19 @@ set_ttdummy(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Type int44 has no real-world use, but the regression tests use it.
|
* Type city_budget has no real-world use, but the regression tests use it.
|
||||||
* It's a four-element vector of int4's.
|
* It's a four-element vector of int4's.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int44in - converts "num num ..." to internal form
|
* city_budget_in - converts "num, num, ..." to internal form
|
||||||
*
|
*
|
||||||
* Note: Fills any missing positions with zeroes.
|
* Note: Fills any missing positions with zeroes.
|
||||||
*/
|
*/
|
||||||
PG_FUNCTION_INFO_V1(int44in);
|
PG_FUNCTION_INFO_V1(city_budget_in);
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
int44in(PG_FUNCTION_ARGS)
|
city_budget_in(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *input_string = PG_GETARG_CSTRING(0);
|
char *input_string = PG_GETARG_CSTRING(0);
|
||||||
int32 *result = (int32 *) palloc(4 * sizeof(int32));
|
int32 *result = (int32 *) palloc(4 * sizeof(int32));
|
||||||
@ -458,27 +458,22 @@ int44in(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int44out - converts internal form to "num num ..."
|
* city_budget_out - converts internal form to "num, num, ..."
|
||||||
*/
|
*/
|
||||||
PG_FUNCTION_INFO_V1(int44out);
|
PG_FUNCTION_INFO_V1(city_budget_out);
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
int44out(PG_FUNCTION_ARGS)
|
city_budget_out(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
|
int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
|
||||||
char *result = (char *) palloc(16 * 4); /* Allow 14 digits + sign */
|
char *result = (char *) palloc(16 * 4);
|
||||||
int i;
|
|
||||||
char *walk;
|
snprintf(result, 16 * 4, "%d,%d,%d,%d",
|
||||||
|
an_array[0],
|
||||||
|
an_array[1],
|
||||||
|
an_array[2],
|
||||||
|
an_array[3]);
|
||||||
|
|
||||||
walk = result;
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
pg_ltoa(an_array[i], walk);
|
|
||||||
while (*++walk != '\0')
|
|
||||||
;
|
|
||||||
*walk++ = ' ';
|
|
||||||
}
|
|
||||||
*--walk = '\0';
|
|
||||||
PG_RETURN_CSTRING(result);
|
PG_RETURN_CSTRING(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,5 +856,6 @@ PG_FUNCTION_INFO_V1(test_fdw_handler);
|
|||||||
Datum
|
Datum
|
||||||
test_fdw_handler(PG_FUNCTION_ARGS)
|
test_fdw_handler(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
elog(ERROR, "test_fdw_handler is not implemented");
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,11 @@ INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
|
|||||||
|
|
||||||
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
|
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
|
||||||
|
|
||||||
|
INSERT INTO city VALUES
|
||||||
|
('Podunk', '(1,2),(3,4)', '100,127,1000'),
|
||||||
|
('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
|
||||||
|
TABLE city;
|
||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
INTO TABLE ramp
|
INTO TABLE ramp
|
||||||
FROM road
|
FROM road
|
||||||
|
@ -32,6 +32,10 @@ CREATE OPERATOR #%# (
|
|||||||
procedure = numeric_fac
|
procedure = numeric_fac
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Test operator created above
|
||||||
|
SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
|
||||||
|
point '(1,2)' <% widget '(0,0,1)' AS f;
|
||||||
|
|
||||||
-- Test comments
|
-- Test comments
|
||||||
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
|
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ CREATE TYPE widget (
|
|||||||
|
|
||||||
CREATE TYPE city_budget (
|
CREATE TYPE city_budget (
|
||||||
internallength = 16,
|
internallength = 16,
|
||||||
input = int44in,
|
input = city_budget_in,
|
||||||
output = int44out,
|
output = city_budget_out,
|
||||||
element = int4,
|
element = int4,
|
||||||
category = 'x', -- just to verify the system will take it
|
category = 'x', -- just to verify the system will take it
|
||||||
preferred = true -- ditto
|
preferred = true -- ditto
|
||||||
@ -144,3 +144,7 @@ CREATE TEMP TABLE mytab (foo widget(42,13));
|
|||||||
|
|
||||||
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
|
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
|
||||||
WHERE attrelid = 'mytab'::regclass AND attnum > 0;
|
WHERE attrelid = 'mytab'::regclass AND attnum > 0;
|
||||||
|
|
||||||
|
-- might as well exercise the widget type while we're here
|
||||||
|
INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
|
||||||
|
TABLE mytab;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user