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

Skip to content

Commit 917828c

Browse files
committed
Refactoring.
Moved `is_negated_flag` to `ut_matcher` Changed behavior of `to_` function to consider the `negated` flag. Started refactoring `ut_compound_data_helper`
1 parent f850428 commit 917828c

10 files changed

Lines changed: 174 additions & 237 deletions

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 97 additions & 95 deletions
Large diffs are not rendered by default.

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ create or replace package ut_compound_data_helper authid definer is
6060
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false
6161
) return tt_column_diffs;
6262

63-
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;
64-
6563
function get_rows_diff(
6664
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
6765
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
@@ -76,6 +74,7 @@ create or replace package ut_compound_data_helper authid definer is
7674
subtype t_hash is raw(128);
7775

7876
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash;
77+
7978
function get_hash(a_data clob, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash;
8079

8180
function get_fixed_size_hash(a_string varchar2, a_base integer :=0,a_size integer :=9999999) return number;

source/expectations/matchers/ut_include.tpb

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,15 @@ create or replace type body ut_include as
2323
return;
2424
end;
2525

26-
member function get_inclusion_compare return boolean is
27-
begin
28-
return true;
29-
end;
30-
31-
member function negated return ut_include is
32-
l_result ut_include := self;
33-
begin
34-
l_result.is_negated := ut_utils.boolean_to_int(true);
35-
return l_result;
36-
end;
37-
38-
member function get_negated return boolean is
39-
begin
40-
return ut_utils.int_to_boolean(nvl(is_negated,0));
41-
end;
42-
4326
overriding member function run_matcher(self in out nocopy ut_include, a_actual ut_data_value) return boolean is
4427
l_result boolean;
45-
l_result1 integer;
4628
begin
4729
if self.expected.data_type = a_actual.data_type then
48-
l_result :=
49-
( 0
50-
= treat( self.expected as ut_data_value_refcursor )
51-
.compare_implementation( a_actual, self.options, get_inclusion_compare(), get_negated() )
52-
);
30+
l_result :=
31+
( 0
32+
= treat( self.expected as ut_data_value_refcursor )
33+
.compare_implementation( a_actual, self.options, true, self.is_negated() )
34+
);
5335
else
5436
l_result := (self as ut_matcher).run_matcher(a_actual);
5537
end if;

source/expectations/matchers/ut_include.tps

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ create or replace type ut_include under ut_equal(
2222
* e.g. set can fail at same time not_include and include. By that we mean
2323
* that false include not necessary mean true not include.
2424
*/
25-
is_negated number(1,0),
26-
25+
2726
constructor function ut_include(self in out nocopy ut_include, a_expected sys_refcursor) return self as result,
28-
member function get_inclusion_compare return boolean,
29-
member function negated return ut_include,
30-
member function get_negated return boolean,
3127
overriding member function run_matcher(self in out nocopy ut_include, a_actual ut_data_value) return boolean,
3228
overriding member function run_matcher_negated(self in out nocopy ut_include, a_actual ut_data_value) return boolean,
3329
overriding member function failure_message(a_actual ut_data_value) return varchar2,

source/expectations/matchers/ut_matcher.tpb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,22 @@ create or replace type body ut_matcher as
6767
return 'Actual: ' || a_actual.to_string_report(true) || description_when_negated();
6868
end;
6969

70+
member procedure negated is
71+
begin
72+
is_negated_flag := ut_utils.boolean_to_int(true);
73+
end;
74+
75+
member function negated return ut_matcher is
76+
l_result ut_matcher := self;
77+
begin
78+
l_result.negated();
79+
return l_result;
80+
end;
81+
82+
member function is_negated return boolean is
83+
begin
84+
return coalesce(ut_utils.int_to_boolean(is_negated_flag), false);
85+
end;
86+
7087
end;
7188
/

source/expectations/matchers/ut_matcher.tps

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ create or replace type ut_matcher authid current_user as object(
1717
*/
1818
self_type varchar2(250),
1919
is_errored integer,
20+
is_negated_flag number(1,0),
2021

2122
/*
2223
function: run_matcher
@@ -35,6 +36,9 @@ create or replace type ut_matcher authid current_user as object(
3536
member function description_when_negated return varchar2,
3637
member function error_message(a_actual ut_data_value) return varchar2,
3738
member function failure_message(a_actual ut_data_value) return varchar2,
38-
member function failure_message_when_negated(a_actual ut_data_value) return varchar2
39+
member function failure_message_when_negated(a_actual ut_data_value) return varchar2,
40+
member procedure negated,
41+
member function negated return ut_matcher,
42+
member function is_negated return boolean
3943
) not final not instantiable
4044
/

source/expectations/ut_expectation.tpb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ create or replace type body ut_expectation as
2020
l_matcher ut_matcher := a_matcher;
2121
l_message varchar2(32767);
2222
begin
23-
24-
l_expectation_result := l_matcher.run_matcher( self.actual_data );
25-
l_expectation_result := coalesce(l_expectation_result,false);
26-
l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message( self.actual_data ) );
27-
ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) );
23+
if a_matcher.is_negated() then
24+
self.not_to( a_matcher );
25+
else
26+
l_expectation_result := l_matcher.run_matcher( self.actual_data );
27+
l_expectation_result := coalesce(l_expectation_result,false);
28+
l_message := coalesce( l_matcher.error_message( self.actual_data ), l_matcher.failure_message( self.actual_data ) );
29+
ut_expectation_processor.add_expectation_result( ut_expectation_result( ut_utils.to_test_result( l_expectation_result ), self.description, l_message ) );
30+
end if;
2831
end;
2932

3033
member procedure not_to(self in ut_expectation, a_matcher ut_matcher) is
@@ -682,7 +685,7 @@ create or replace type body ut_expectation as
682685

683686
member procedure to_include(self in ut_expectation, a_expected sys_refcursor) is
684687
begin
685-
self.to_( ut_include(a_expected) );
688+
to_contain( a_expected );
686689
end;
687690

688691
member procedure to_contain(self in ut_expectation, a_expected sys_refcursor) is
@@ -692,12 +695,12 @@ create or replace type body ut_expectation as
692695

693696
member procedure not_to_include(self in ut_expectation, a_expected sys_refcursor) is
694697
begin
695-
self.not_to( ut_include(a_expected).negated );
698+
not_to_contain( a_expected );
696699
end;
697700

698701
member procedure not_to_contain(self in ut_expectation, a_expected sys_refcursor) is
699702
begin
700-
self.not_to( ut_include(a_expected).negated );
703+
self.not_to( ut_include(a_expected).negated() );
701704
end;
702705

703706
end;

source/expectations/ut_expectation_compound.tpb

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ create or replace type body ut_expectation_compound as
2020
begin
2121
self.actual_data := a_actual_data;
2222
self.description := a_description;
23-
negated := ut_utils.boolean_to_int(false);
2423
return;
2524
end;
2625

@@ -55,105 +54,69 @@ create or replace type body ut_expectation_compound as
5554
member function not_to_equal(a_expected anydata, a_nulls_are_equal boolean := null) return ut_expectation_compound is
5655
l_result ut_expectation_compound := self;
5756
begin
58-
l_result.matcher := ut_equal(a_expected, a_nulls_are_equal);
59-
l_result.negated := ut_utils.boolean_to_int(true);
57+
l_result.matcher := ut_equal(a_expected, a_nulls_are_equal).negated();
6058
return l_result;
61-
6259
end;
6360

6461
member function include(a_items varchar2) return ut_expectation_compound is
65-
l_result ut_expectation_compound;
6662
begin
67-
l_result := self;
68-
l_result.matcher := treat(l_result.matcher as ut_equal).include(a_items);
69-
return l_result;
63+
return include( ut_varchar2_list( a_items ) );
7064
end;
7165

7266
member function include(a_items ut_varchar2_list) return ut_expectation_compound is
73-
l_result ut_expectation_compound;
67+
l_result ut_expectation_compound := self;
7468
begin
75-
l_result := self;
7669
l_result.matcher := treat(l_result.matcher as ut_equal).include(a_items);
7770
return l_result;
7871
end;
7972

8073
member procedure include(self in ut_expectation_compound, a_items varchar2) is
8174
begin
82-
if ut_utils.int_to_boolean(negated) then
83-
self.not_to( treat(matcher as ut_equal).include(a_items) );
84-
else
85-
self.to_( treat(matcher as ut_equal).include(a_items) );
86-
end if;
87-
end;
75+
include( ut_varchar2_list( a_items ) );
76+
end;
8877

8978
member procedure include(self in ut_expectation_compound, a_items ut_varchar2_list) is
9079
begin
91-
if ut_utils.int_to_boolean(negated) then
92-
self.not_to( treat(matcher as ut_equal).include(a_items) );
93-
else
94-
self.to_( treat(matcher as ut_equal).include(a_items) );
95-
end if;
96-
end;
97-
98-
80+
self.to_( treat(matcher as ut_equal).include(a_items) );
81+
end;
9982

10083
member function exclude(a_items varchar2) return ut_expectation_compound is
101-
l_result ut_expectation_compound;
102-
begin
103-
l_result := self;
104-
l_result.matcher := treat(l_result.matcher as ut_equal).exclude(a_items);
105-
return l_result;
106-
end;
84+
begin
85+
return exclude( ut_varchar2_list( a_items ) );
86+
end;
10787

10888
member function exclude(a_items ut_varchar2_list) return ut_expectation_compound is
109-
l_result ut_expectation_compound;
110-
begin
111-
l_result := self;
112-
l_result.matcher := treat(l_result.matcher as ut_equal).exclude(a_items);
113-
return l_result;
114-
end;
89+
l_result ut_expectation_compound := self;
90+
begin
91+
l_result.matcher := treat(l_result.matcher as ut_equal).exclude(a_items);
92+
return l_result;
93+
end;
11594

11695
member procedure exclude(self in ut_expectation_compound, a_items varchar2) is
117-
begin
118-
if ut_utils.int_to_boolean(negated) then
119-
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
120-
else
121-
self.to_( treat(matcher as ut_equal).exclude(a_items) );
122-
end if;
123-
end;
96+
begin
97+
exclude( ut_varchar2_list( a_items ) );
98+
end;
12499

125100
member procedure exclude(self in ut_expectation_compound, a_items ut_varchar2_list) is
126-
begin
127-
if ut_utils.int_to_boolean(negated) then
128-
self.not_to( treat(matcher as ut_equal).exclude(a_items) );
129-
else
130-
self.to_( treat(matcher as ut_equal).exclude(a_items) );
131-
end if;
132-
end;
101+
begin
102+
self.to_( treat(matcher as ut_equal).exclude(a_items) );
103+
end;
133104

134105
member function unordered return ut_expectation_compound is
135-
l_result ut_expectation_compound;
106+
l_result ut_expectation_compound := self;
136107
begin
137-
l_result := self;
138-
l_result.matcher := treat(l_result.matcher as ut_equal).unordered;
108+
l_result.matcher := treat(l_result.matcher as ut_equal).unordered();
139109
return l_result;
140110
end;
141111

142112
member procedure unordered(self in ut_expectation_compound) is
143113
begin
144-
if ut_utils.int_to_boolean(negated) then
145-
self.not_to( treat(matcher as ut_equal).unordered );
146-
else
147-
self.to_( treat(matcher as ut_equal).unordered );
148-
end if;
114+
self.to_( treat(matcher as ut_equal).unordered() );
149115
end;
150116

151117
member function join_by(a_columns varchar2) return ut_expectation_compound is
152-
l_result ut_expectation_compound;
153118
begin
154-
l_result := self;
155-
l_result.matcher := treat(l_result.matcher as ut_equal).join_by(a_columns);
156-
return l_result;
119+
return join_by( ut_varchar2_list( a_columns ) );
157120
end;
158121

159122
member function join_by(a_columns ut_varchar2_list) return ut_expectation_compound is
@@ -166,20 +129,12 @@ create or replace type body ut_expectation_compound as
166129

167130
member procedure join_by(self in ut_expectation_compound, a_columns varchar2) is
168131
begin
169-
if ut_utils.int_to_boolean(negated) then
170-
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
171-
else
172-
self.to_( treat(matcher as ut_equal).join_by(a_columns) );
173-
end if;
132+
join_by( ut_varchar2_list( a_columns ) );
174133
end;
175134

176135
member procedure join_by(self in ut_expectation_compound, a_columns ut_varchar2_list) is
177136
begin
178-
if ut_utils.int_to_boolean(negated) then
179-
self.not_to( treat(matcher as ut_equal).join_by(a_columns) );
180-
else
181-
self.to_( treat(matcher as ut_equal).join_by(a_columns) );
182-
end if;
137+
self.to_( treat(matcher as ut_equal).join_by(a_columns) );
183138
end;
184139

185140
end;

source/expectations/ut_expectation_compound.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_expectation_compound under ut_expectation(
1+
create or replace type ut_expectation_compound force under ut_expectation(
22
/*
33
utPLSQL - Version 3
44
Copyright 2016 - 2018 utPLSQL Project
@@ -16,7 +16,6 @@ create or replace type ut_expectation_compound under ut_expectation(
1616
limitations under the License.
1717
*/
1818
matcher ut_matcher,
19-
negated integer,
2019

2120
constructor function ut_expectation_compound(self in out nocopy ut_expectation_compound, a_actual_data ut_data_value, a_description varchar2) return self as result,
2221

0 commit comments

Comments
 (0)