@@ -6,7 +6,7 @@ To do that we use concept of expectation and a matcher to perform the check on t
66Example of unit test procedure body with a single expectation.
77``` sql
88begin
9- ut .expect ( ' the tested value' ).to_( equal( ' the expected value' ) );
9+ ut .expect ( ' the tested value' ).to_equal( ' the expected value' );
1010end;
1111```
1212
@@ -19,6 +19,12 @@ Pseudo-code:
1919 ut .expect ( a_actual {data- type} ).not_to( {matcher} );
2020```
2121
22+ Most of the matchers have shortcuts like:
23+ ``` sql
24+ ut .expect ( a_actual {data- type} ).to_{matcher};
25+ ut .expect ( a_actual {data- type} ).not_to{matcher};
26+ ```
27+
2228
2329# Matchers
2430utPLSQL provides following matchers to perform checks on the expected and actual values.
@@ -42,8 +48,8 @@ Validates that the actual value is between the lower and upper bound.
4248Example:
4349``` sql
4450begin
45- ut .expect ( a_actual => 3 ).to_( be_between( a_lower_bound => 1 , a_upper_bound => 3 ) );
46- ut .expect ( 3 ).to_( be_between( 1 , 3 ) );
51+ ut .expect ( a_actual => 3 ).to_be_between( a_lower_bound => 1 , a_upper_bound => 3 );
52+ ut .expect ( 3 ).to_be_between( 1 , 3 );
4753end;
4854```
4955
@@ -56,7 +62,7 @@ procedure test_if_cursor_is_empty is
5662 l_cursor sys_refcursor;
5763begin
5864 open l_cursor for select * from dual where 1 = 0 ;
59- ut .expect ( l_cursor ).to_( be_empty() );
65+ ut .expect ( l_cursor ).to_be_empty( );
6066end;
6167```
6268
@@ -68,7 +74,7 @@ Unary matcher that validates if the provided value is false.
6874Usage:
6975``` sql
7076begin
71- ut .expect ( ( 1 = 0 ) ).to_( be_false() );
77+ ut .expect ( ( 1 = 0 ) ).to_be_false( );
7278end;
7379```
7480
@@ -78,7 +84,7 @@ Allows to check if the actual value is greater or equal than the expected.
7884Usage:
7985``` sql
8086begin
81- ut .expect ( sysdate ).to_( be_greater_or_equal( sysdate - 1 ) );
87+ ut .expect ( sysdate ).to_be_greater_or_equal( sysdate - 1 );
8288end;
8389```
8490
@@ -88,7 +94,7 @@ Allows to check if the actual value is greater than the expected.
8894Usage:
8995``` sql
9096begin
91- ut .expect ( 2 ).to_( be_greater_than( 1 ) );
97+ ut .expect ( 2 ).to_be_greater_than( 1 );
9298end;
9399```
94100
@@ -98,7 +104,7 @@ Allows to check if the actual value is less or equal than the expected.
98104Usage:
99105``` sql
100106begin
101- ut .expect ( 3 ).to_( be_less_or_equal( 3 ) );
107+ ut .expect ( 3 ).to_be_less_or_equal( 3 );
102108end;
103109```
104110
@@ -108,7 +114,7 @@ Allows to check if the actual value is less than the expected.
108114Usage:
109115``` sql
110116begin
111- ut .expect ( 3 ).to_( be_less_than( 2 ) );
117+ ut .expect ( 3 ).to_be_less_than( 2 );
112118end;
113119```
114120
@@ -119,8 +125,8 @@ Validates that the actual value is like the expected expression.
119125Usage:
120126``` sql
121127begin
122- ut .expect ( ' Lorem_impsum' ).to_( be_like( a_mask => ' %rem\_ %' , a_escape_char => ' \' ) );
123- ut.expect( ' Lorem_impsum' ).to_( be_like( ' %rem\_%' , ' \' ) );
128+ ut .expect ( ' Lorem_impsum' ).to_be_like( a_mask => ' %rem\_ %' , a_escape_char => ' \' );
129+ ut.expect( ' Lorem_impsum' ).to_be_like( ' %rem\_%' , ' \' );
124130end;
125131```
126132
@@ -133,7 +139,7 @@ Unary matcher that validates if the actual value is not null.
133139Usage:
134140```sql
135141begin
136- ut.expect( to_clob(' ABC' ) ).to_( be_not_null() );
142+ ut.expect( to_clob(' ABC' ) ).to_be_not_null( );
137143end;
138144```
139145
@@ -143,7 +149,7 @@ Unary matcher that validates if the actual value is null.
143149Usage:
144150```sql
145151begin
146- ut.expect( cast(null as varchar2(100)) ).to_( be_null() );
152+ ut.expect( cast(null as varchar2(100)) ).to_be_null( );
147153end;
148154```
149155
@@ -154,7 +160,7 @@ Unary matcher that validates if the provided value is false.
154160Usage:
155161```sql
156162begin
157- ut.expect( ( 1 = 1 ) ).to_( be_true() );
163+ ut.expect( ( 1 = 1 ) ).to_be_true( );
158164end;
159165```
160166
@@ -171,12 +177,14 @@ procedure check_if_cursors_are_equal is
171177 x sys_refcursor;
172178 y sys_refcursor;
173179begin
174- ut.expect( ' a dog' ).to_( equal( ' a dog' ) );
175- ut.expect( a_actual => y ).to_( equal( a_expected => x, a_nulls_are_equal => true ) );
180+ ut.expect( ' a dog' ).to_equal( ' a dog' );
181+ ut.expect( a_actual => y ).to_equal( a_expected => x, a_nulls_are_equal => true );
176182end;
177183```
178184The `a_nulls_are_equal` parameter decides on the behavior of `null=null` comparison (**this comparison by default is true!**)
179185
186+ There are no shortcuts for `not_to_equal`, so use `not_to (equal(...))`
187+
180188### Comparing cursors
181189
182190The `equal` matcher accepts additional parameter `a_exclude varchar2` or `a_exclude ut_varchar2_list`, when used to compare `cursor` data.
@@ -193,7 +201,7 @@ procedure test_cursors_skip_columns is
193201begin
194202 open x for select 'text' ignore_me, d.* from user_tables d;
195203 open y for select sysdate "ADate", d.* from user_tables d;
196- ut.expect( a_actual => y ).to_( equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' ) );
204+ ut.expect( a_actual => y ).to_equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' );
197205end;
198206` ` `
199207
@@ -261,7 +269,7 @@ create or replace package body test_get_events is
261269 l_actual := get_events(gc_event_date-1, gc_event_date+1);
262270 ut.reset_nls();
263271
264- ut.expect(l_actual).to_( equal( l_expected) );
272+ ut.expect(l_actual).to_equal( l_expected);
265273 ut.expect(l_actual).not_to( equal(l_expected_bad_date) );
266274 end;
267275
@@ -309,7 +317,7 @@ create or replace package body demo_dept as
309317 begin
310318 v_expected := department('HR');
311319 v_actual := department('IT');
312- ut.expect( anydata.convertObject(v_expected) ).to_( equal( anydata.convertObject(v_actual) ) );
320+ ut.expect( anydata.convertObject(v_expected) ).to_equal( anydata.convertObject(v_actual) );
313321 end;
314322
315323 procedure test_department is
@@ -318,7 +326,7 @@ create or replace package body demo_dept as
318326 begin
319327 v_expected := departments(department('HR'));
320328 v_actual := departments(department('IT'));
321- ut.expect( anydata.convertCollection(v_expected) ).to_( equal( anydata.convertCollection(v_actual) ) );
329+ ut.expect( anydata.convertCollection(v_expected) ).to_equal( anydata.convertCollection(v_actual) );
322330 end;
323331
324332end;
@@ -333,8 +341,8 @@ Validates that the actual value is matching the expected regular expression.
333341Usage:
334342` ` ` sql
335343begin
336- ut.expect( a_actual => '123-456-ABcd' ).to_( match( a_pattern => '\d {3}-\d {3}-[a-z]', a_modifiers => 'i' ) );
337- ut.expect( 'some value' ).to_( match( '^some.*' ) );
344+ ut.expect( a_actual => '123-456-ABcd' ).to_match( a_pattern => '\d {3}-\d {3}-[a-z]', a_modifiers => 'i' );
345+ ut.expect( 'some value' ).to_match( '^some.*' );
338346end;
339347` ` `
340348
@@ -370,14 +378,16 @@ Expectations provide a very convenient way to check for a negative of the expect
370378Syntax of check for matcher evaluating to true:
371379` ` ` sql
372380begin
373- ut.expect( a_actual {data-type} ).to_( {matcher} );
381+ ut.expect( a_actual {data-type} ).to_{matcher};
382+ ut.expect( a_actual {data-type} ).to_{ (matcher} );
374383end;
375384` ` `
376385
377386Syntax of check for matcher evaluating to false:
378387` ` ` sql
379388begin
380389 ut.expect( a_actual {data-type} ).not_to( {matcher} );
390+ ut.expect( a_actual {data-type} ).not_to_{matcher};
381391end;
382392` ` `
383393
@@ -386,7 +396,7 @@ If a matcher evaluated to NULL, then both `to_` and `not_to` will cause the expe
386396Example:
387397` ` ` sql
388398begin
389- ut.expect( null ).to_( be_true() );
399+ ut.expect( null ).to_be_true( );
390400 ut.expect( null ).not_to( be_true() );
391401end;
392402` ` `
0 commit comments