Skip to content

Commit 57c74f9

Browse files
Add hasnt_operator, hasnt_leftop, hasnt_rightop (#251)
1 parent 33a2a62 commit 57c74f9

File tree

6 files changed

+1165
-387
lines changed

6 files changed

+1165
-387
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Revision history for pgTAP
3030
pull request (#249).
3131
* Added docker files for local test environment. Thanks to Wolfgang Walther for
3232
the pull request (#250).
33+
* Added `hasnt_operator()`, `hasnt_leftop()`, `hasnt_rightop()` (#38). Thanks to
34+
Wolfgang Walther for the pull request (#251).
3335

3436
1.1.0 2019-11-25T19:05:38Z
3537
--------------------------

doc/pgtap.mmd

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3893,7 +3893,7 @@ cast does *not* exist.
38933893

38943894
Tests for the presence of a binary operator. If the operator exists with the
38953895
given schema, name, left and right arguments, and return value, the test will
3896-
fail. If the operator does not exist, the test will fail. Example:
3896+
pass. If the operator does not exist, the test will fail. Example:
38973897

38983898
SELECT has_operator( 'integer', 'pg_catalog', '<=', 'integer', 'boolean' );
38993899

@@ -3903,6 +3903,38 @@ for you. The return value is also optional. If you need to test for a left
39033903
(prefix) or right (postfix) unary operator, use `has_leftop()` or
39043904
`has_rightop()` instead.
39053905

3906+
### `hasnt_operator()` ###
3907+
3908+
SELECT hasnt_operator( :left_type, :schema, :name, :right_type, :return_type, :description );
3909+
SELECT hasnt_operator( :left_type, :schema, :name, :right_type, :return_type );
3910+
SELECT hasnt_operator( :left_type, :name, :right_type, :return_type, :description );
3911+
SELECT hasnt_operator( :left_type, :name, :right_type, :return_type );
3912+
SELECT hasnt_operator( :left_type, :name, :right_type, :description );
3913+
SELECT hasnt_operator( :left_type, :name, :right_type );
3914+
3915+
**Parameters**
3916+
3917+
`:left_type`
3918+
: Data type of the left operand.
3919+
3920+
`:schema`
3921+
: Schema in which to find the operator.
3922+
3923+
`:name`
3924+
: Name of the operator.
3925+
3926+
`:right_type`
3927+
: Data type of the right operand.
3928+
3929+
`:return_type`
3930+
: Data type of the return value.
3931+
3932+
`:description`
3933+
: A short description of the test.
3934+
3935+
This function is the inverse of `has_operator()`. The test passes if the
3936+
specified operator does *not* exist.
3937+
39063938
### `has_leftop()` ###
39073939

39083940
SELECT has_leftop( :schema, :name, :type, :return_type, :description );
@@ -3939,6 +3971,35 @@ If you omit the schema name, then the operator must be visible in the search
39393971
path. If you omit the test description, pgTAP will generate a reasonable one
39403972
for you. The return type is also optional.
39413973

3974+
### `hasnt_leftop()` ###
3975+
3976+
SELECT hasnt_leftop( :schema, :name, :type, :return_type, :description );
3977+
SELECT hasnt_leftop( :schema, :name, :type, :return_type );
3978+
SELECT hasnt_leftop( :name, :type, :return_type, :description );
3979+
SELECT hasnt_leftop( :name, :type, :return_type );
3980+
SELECT hasnt_leftop( :name, :type, :description );
3981+
SELECT hasnt_leftop( :name, :type );
3982+
3983+
**Parameters**
3984+
3985+
`:schema`
3986+
: Schema in which to find the operator.
3987+
3988+
`:name`
3989+
: Name of the operator.
3990+
3991+
`:type`
3992+
: Data type of the operand.
3993+
3994+
`:return_type`
3995+
: Data type of the return value.
3996+
3997+
`:description`
3998+
: A short description of the test.
3999+
4000+
This function is the inverse of `has_leftop()`. The test passes if the
4001+
specified operator does *not* exist.
4002+
39424003
### `has_rightop()` ###
39434004

39444005
SELECT has_rightop( :schema, :name, :type, :return_type, :description );
@@ -3976,6 +4037,35 @@ If you omit the schema name, then the operator must be visible in the search
39764037
path. If you omit the test description, pgTAP will generate a reasonable one
39774038
for you. The return type is also optional.
39784039

4040+
### `hasnt_rightop()` ###
4041+
4042+
SELECT hasnt_rightop( :schema, :name, :type, :return_type, :description );
4043+
SELECT hasnt_rightop( :schema, :name, :type, :return_type );
4044+
SELECT hasnt_rightop( :name, :type, :return_type, :description );
4045+
SELECT hasnt_rightop( :name, :type, :return_type );
4046+
SELECT hasnt_rightop( :name, :type, :description );
4047+
SELECT hasnt_rightop( :name, :type );
4048+
4049+
**Parameters**
4050+
4051+
`:schema`
4052+
: Schema in which to find the operator.
4053+
4054+
`:name`
4055+
: Name of the operator.
4056+
4057+
`:type`
4058+
: Data type of the operand.
4059+
4060+
`:return_type`
4061+
: Data type of the return value.
4062+
4063+
`:description`
4064+
: A short description of the test.
4065+
4066+
This function is the inverse of `hasnt_rightop()`. The test passes if the
4067+
specified operator does *not* exist.
4068+
39794069
### `has_opclass()` ###
39804070

39814071
SELECT has_opclass( :schema, :name, :description );

sql/pgtap--1.1.0--1.2.0.sql

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,146 @@ BEGIN
3737
END;
3838
$$ LANGUAGE plpgsql;
3939

40+
-- hasnt_operator( left_type, schema, name, right_type, return_type, description )
41+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME, NAME, NAME, TEXT )
42+
RETURNS TEXT AS $$
43+
SELECT ok( NOT _op_exists($1, $2, $3, $4, $5 ), $6 );
44+
$$ LANGUAGE SQL;
45+
46+
-- hasnt_operator( left_type, schema, name, right_type, return_type )
47+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME, NAME, NAME )
48+
RETURNS TEXT AS $$
49+
SELECT ok(
50+
NOT _op_exists($1, $2, $3, $4, $5 ),
51+
'Operator ' || quote_ident($2) || '.' || $3 || '(' || $1 || ',' || $4
52+
|| ') RETURNS ' || $5 || ' should not exist'
53+
);
54+
$$ LANGUAGE SQL;
55+
56+
-- hasnt_operator( left_type, name, right_type, return_type, description )
57+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME, NAME, TEXT )
58+
RETURNS TEXT AS $$
59+
SELECT ok( NOT _op_exists($1, $2, $3, $4 ), $5 );
60+
$$ LANGUAGE SQL;
61+
62+
-- hasnt_operator( left_type, name, right_type, return_type )
63+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME, NAME )
64+
RETURNS TEXT AS $$
65+
SELECT ok(
66+
NOT _op_exists($1, $2, $3, $4 ),
67+
'Operator ' || $2 || '(' || $1 || ',' || $3
68+
|| ') RETURNS ' || $4 || ' should not exist'
69+
);
70+
$$ LANGUAGE SQL;
71+
72+
-- hasnt_operator( left_type, name, right_type, description )
73+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME, TEXT )
74+
RETURNS TEXT AS $$
75+
SELECT ok( NOT _op_exists($1, $2, $3 ), $4 );
76+
$$ LANGUAGE SQL;
77+
78+
-- hasnt_operator( left_type, name, right_type )
79+
CREATE OR REPLACE FUNCTION hasnt_operator ( NAME, NAME, NAME )
80+
RETURNS TEXT AS $$
81+
SELECT ok(
82+
NOT _op_exists($1, $2, $3 ),
83+
'Operator ' || $2 || '(' || $1 || ',' || $3
84+
|| ') should not exist'
85+
);
86+
$$ LANGUAGE SQL;
87+
88+
-- hasnt_leftop( schema, name, right_type, return_type, description )
89+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME, NAME, NAME, TEXT )
90+
RETURNS TEXT AS $$
91+
SELECT ok( NOT _op_exists(NULL, $1, $2, $3, $4), $5 );
92+
$$ LANGUAGE SQL;
93+
94+
-- hasnt_leftop( schema, name, right_type, return_type )
95+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME, NAME, NAME )
96+
RETURNS TEXT AS $$
97+
SELECT ok(
98+
NOT _op_exists(NULL, $1, $2, $3, $4 ),
99+
'Left operator ' || quote_ident($1) || '.' || $2 || '(NONE,'
100+
|| $3 || ') RETURNS ' || $4 || ' should not exist'
101+
);
102+
$$ LANGUAGE SQL;
103+
104+
-- hasnt_leftop( name, right_type, return_type, description )
105+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME, NAME, TEXT )
106+
RETURNS TEXT AS $$
107+
SELECT ok( NOT _op_exists(NULL, $1, $2, $3), $4 );
108+
$$ LANGUAGE SQL;
109+
110+
-- hasnt_leftop( name, right_type, return_type )
111+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME, NAME )
112+
RETURNS TEXT AS $$
113+
SELECT ok(
114+
NOT _op_exists(NULL, $1, $2, $3 ),
115+
'Left operator ' || $1 || '(NONE,' || $2 || ') RETURNS ' || $3 || ' should not exist'
116+
);
117+
$$ LANGUAGE SQL;
118+
119+
-- hasnt_leftop( name, right_type, description )
120+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME, TEXT )
121+
RETURNS TEXT AS $$
122+
SELECT ok( NOT _op_exists(NULL, $1, $2), $3 );
123+
$$ LANGUAGE SQL;
124+
125+
-- hasnt_leftop( name, right_type )
126+
CREATE OR REPLACE FUNCTION hasnt_leftop ( NAME, NAME )
127+
RETURNS TEXT AS $$
128+
SELECT ok(
129+
NOT _op_exists(NULL, $1, $2 ),
130+
'Left operator ' || $1 || '(NONE,' || $2 || ') should not exist'
131+
);
132+
$$ LANGUAGE SQL;
133+
134+
-- hasnt_rightop( left_type, schema, name, return_type, description )
135+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME, NAME, NAME, TEXT )
136+
RETURNS TEXT AS $$
137+
SELECT ok( NOT _op_exists( $1, $2, $3, NULL, $4), $5 );
138+
$$ LANGUAGE SQL;
139+
140+
-- hasnt_rightop( left_type, schema, name, return_type )
141+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME, NAME, NAME )
142+
RETURNS TEXT AS $$
143+
SELECT ok(
144+
NOT _op_exists($1, $2, $3, NULL, $4 ),
145+
'Right operator ' || quote_ident($2) || '.' || $3 || '('
146+
|| $1 || ',NONE) RETURNS ' || $4 || ' should not exist'
147+
);
148+
$$ LANGUAGE SQL;
149+
150+
-- hasnt_rightop( left_type, name, return_type, description )
151+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME, NAME, TEXT )
152+
RETURNS TEXT AS $$
153+
SELECT ok( NOT _op_exists( $1, $2, NULL, $3), $4 );
154+
$$ LANGUAGE SQL;
155+
156+
-- hasnt_rightop( left_type, name, return_type )
157+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME, NAME )
158+
RETURNS TEXT AS $$
159+
SELECT ok(
160+
NOT _op_exists($1, $2, NULL, $3 ),
161+
'Right operator ' || $2 || '('
162+
|| $1 || ',NONE) RETURNS ' || $3 || ' should not exist'
163+
);
164+
$$ LANGUAGE SQL;
165+
166+
-- hasnt_rightop( left_type, name, description )
167+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME, TEXT )
168+
RETURNS TEXT AS $$
169+
SELECT ok( NOT _op_exists( $1, $2, NULL), $3 );
170+
$$ LANGUAGE SQL;
171+
172+
-- hasnt_rightop( left_type, name )
173+
CREATE OR REPLACE FUNCTION hasnt_rightop ( NAME, NAME )
174+
RETURNS TEXT AS $$
175+
SELECT ok(
176+
NOT _op_exists($1, $2, NULL ),
177+
'Right operator ' || $2 || '(' || $1 || ',NONE) should not exist'
178+
);
179+
=======
40180
-- isnt_member_of( role, members[], description )
41181
CREATE OR REPLACE FUNCTION isnt_member_of( NAME, NAME[], TEXT )
42182
RETURNS TEXT AS $$

0 commit comments

Comments
 (0)