Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd54710

Browse files
committed
Adding short-name for unordered columns option UC.
1 parent 2ff110d commit bd54710

7 files changed

Lines changed: 99 additions & 3 deletions

File tree

docs/userguide/expectations.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ utPLSQL is capable of comparing compound data-types including:
713713

714714
- Attributes in nested table and array types are compared as **ordered lists of elements**. If order of attributes in nested table and array differ, expectation will fail.
715715

716-
- Columns in cursors are compared as **ordered list of elements** by default. If order of columns in cursor is not of importance the option has to be passed to enforce column order comparison ` unordered_columns` e.g.
716+
- Columns in cursors are compared as **ordered list of elements** by default. If order of columns in cursor is not of importance the option has to be passed to enforce column order comparison ` unordered_columns` or a short version `uc` e.g.
717717

718718
```sql
719719
procedure ut_refcursors1 is
@@ -725,7 +725,8 @@ utPLSQL is capable of comparing compound data-types including:
725725
open l_actual for select 1 user_id,'s' a_col,'test' username from dual;
726726
open l_expected for select 'test' username,'s' a_col,1 user_id from dual;
727727
--Act
728-
ut.expect(l_actual).to_equal(l_expected).join_by('USER_ID').unordered_columns;
728+
ut.expect(l_actual).to_equal(l_expected).join_by('USER_ID').unordered_columns();
729+
ut.expect(l_actual).to_equal(l_expected).join_by('USER_ID').uc();
729730
end;
730731
```
731732

source/expectations/matchers/ut_equal.tpb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ create or replace type body ut_equal as
254254
return ( coalesce(join_columns, ut_varchar2_list()) );
255255
end;
256256

257+
member function uc return ut_equal is
258+
begin
259+
return unordered_columns;
260+
end;
261+
257262
member function unordered_columns return ut_equal is
258263
l_result ut_equal := self;
259264
begin

source/expectations/matchers/ut_equal.tps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ create or replace type ut_equal force under ut_comparison_matcher(
8282
overriding member function failure_message(a_actual ut_data_value) return varchar2,
8383
overriding member function failure_message_when_negated(a_actual ut_data_value) return varchar2,
8484
member function unordered_columns return ut_equal,
85+
member function uc return ut_equal,
8586
member function get_ordered_columns return boolean
8687
)
8788
not final

source/expectations/ut_expectation_compound.tpb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,16 @@ create or replace type body ut_expectation_compound as
245245
end if;
246246
end;
247247

248+
member function uc return ut_expectation_compound is
249+
l_result ut_expectation_compound;
250+
begin
251+
return unordered_columns;
252+
end;
253+
254+
member procedure uc(self in ut_expectation_compound) is
255+
begin
256+
unordered_columns;
257+
end;
258+
248259
end;
249260
/

source/expectations/ut_expectation_compound.tps

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ create or replace type ut_expectation_compound under ut_expectation(
5050
member procedure join_by(self in ut_expectation_compound, a_columns varchar2),
5151
member procedure join_by(self in ut_expectation_compound, a_columns ut_varchar2_list),
5252
member function unordered_columns return ut_expectation_compound,
53-
member procedure unordered_columns(self in ut_expectation_compound)
53+
member procedure unordered_columns(self in ut_expectation_compound),
54+
member function uc return ut_expectation_compound,
55+
member procedure uc(self in ut_expectation_compound)
5456
)
5557
final
5658
/

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ create or replace package body test_expectations_cursor is
319319
ut.expect(expectations.failed_expectations_data()).to_be_empty();
320320
end;
321321

322+
procedure pass_on_diff_column_ord_uc
323+
as
324+
l_expected sys_refcursor;
325+
l_actual sys_refcursor;
326+
begin
327+
--Arrange
328+
open l_expected for select 1 as col_1, 2 as col_2 from dual;
329+
open l_actual for select 2 as col_2, 1 as col_1 from dual;
330+
--Act
331+
ut3.ut.expect( l_actual ).to_equal( l_expected ).uc;
332+
--Assert
333+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
334+
end;
335+
322336
procedure fail_on_multi_diff_col_order
323337
as
324338
l_expected sys_refcursor;
@@ -342,6 +356,29 @@ create or replace package body test_expectations_cursor is
342356
ut.expect(l_actual_message).to_be_like(l_expected_message);
343357
end;
344358

359+
procedure fail_on_multi_diff_col_ord_uc
360+
as
361+
l_expected sys_refcursor;
362+
l_actual sys_refcursor;
363+
l_actual_message varchar2(32767);
364+
l_expected_message varchar2(32767);
365+
begin
366+
--Arrange
367+
open l_expected for select 1 as col_1, 2 as col_2,3 as col_3, 4 as col_4,5 col_5 from dual;
368+
open l_actual for select 2 as col_2, 1 as col_1,40 as col_4, 5 as col_5, 30 col_3 from dual;
369+
--Act
370+
ut3.ut.expect( l_actual ).to_equal( l_expected ).uc;
371+
--Assert
372+
l_expected_message := q'[Actual: refcursor [ count = 1 ] was expected to equal: refcursor [ count = 1 ]
373+
%Diff:
374+
%Rows: [ 1 differences ]
375+
%Row No. 1 - Actual: <COL_4>40</COL_4><COL_3>30</COL_3>
376+
%Row No. 1 - Expected: <COL_3>3</COL_3><COL_4>4</COL_4>]';
377+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
378+
--Assert
379+
ut.expect(l_actual_message).to_be_like(l_expected_message);
380+
end;
381+
345382
procedure fail_on_different_row_order
346383
as
347384
l_expected sys_refcursor;
@@ -1095,6 +1132,19 @@ Rows: [ 4 differences ]
10951132
ut.expect(expectations.failed_expectations_data()).to_be_empty();
10961133
end;
10971134

1135+
procedure cursor_unord_compr_success_uc is
1136+
l_actual SYS_REFCURSOR;
1137+
l_expected SYS_REFCURSOR;
1138+
begin
1139+
--Arrange
1140+
open l_actual for select user_id, username from all_users order by username asc;
1141+
open l_expected for select username , user_id from all_users order by username desc;
1142+
--Act
1143+
ut3.ut.expect(l_actual).to_equal(l_expected).unordered().uc();
1144+
--Assert
1145+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
1146+
end;
1147+
10981148
procedure cursor_unordered_compare_fail is
10991149
l_actual SYS_REFCURSOR;
11001150
l_expected SYS_REFCURSOR;
@@ -1122,6 +1172,20 @@ Rows: [ 4 differences ]
11221172
--Assert
11231173
ut.expect(l_actual_message).to_be_like(l_expected_message);
11241174
end;
1175+
1176+
procedure cursor_joinby_compare_uc is
1177+
l_actual SYS_REFCURSOR;
1178+
l_expected SYS_REFCURSOR;
1179+
begin
1180+
--Arrange
1181+
open l_actual for select owner, object_id, object_name,object_type from all_objects where owner = user;
1182+
open l_expected for select object_id, owner, object_name,object_type from all_objects where owner = user;
1183+
1184+
--Act
1185+
ut3.ut.expect(l_actual).to_equal(l_expected).join_by('OBJECT_ID').uc();
1186+
--Assert
1187+
ut.expect(expectations.failed_expectations_data()).to_be_empty();
1188+
end;
11251189

11261190
procedure cursor_joinby_compare is
11271191
l_actual SYS_REFCURSOR;

test/core/expectations/test_expectations_cursor.pks

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ create or replace package test_expectations_cursor is
7474
--%test(Pass when different column ordering is used in cursors)
7575
procedure pass_on_different_column_order;
7676

77+
--%test(Pass when different column ordering is used in cursors - shortname)
78+
procedure pass_on_diff_column_ord_uc;
79+
7780
--%test(Fail and highlight diffrence between columns when columns are unordered and different value)
7881
procedure fail_on_multi_diff_col_order;
7982

83+
--%test(Fail and highlight diffrence between columns when columns are unordered and different value - shortname)
84+
procedure fail_on_multi_diff_col_ord_uc;
85+
8086
--%test(Gives failure when different row ordering is used in cursors)
8187
procedure fail_on_different_row_order;
8288

@@ -205,12 +211,18 @@ create or replace package test_expectations_cursor is
205211
--%test( Compare cursors using unordered method success)
206212
procedure cursor_unorderd_compr_success;
207213

214+
--%test( Compare cursors using unordered method success and unordered columns position)
215+
procedure cursor_unord_compr_success_uc;
216+
208217
--%test( Compare cursors using unordered method failure)
209218
procedure cursor_unordered_compare_fail;
210219

211220
--%test( Compare cursors join by single key )
212221
procedure cursor_joinby_compare;
213222

223+
--%test( Compare cursors join by single key with unordered columns position using shortname)
224+
procedure cursor_joinby_compare_uc;
225+
214226
--%test(Compare cursors by single key with unordered columns position)
215227
procedure cursor_joinby_col_not_ord;
216228

0 commit comments

Comments
 (0)