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

Skip to content

Commit 5dee7de

Browse files
committed
Added support for anydata in ut.expect
1 parent 51e6c55 commit 5dee7de

18 files changed

Lines changed: 73 additions & 29 deletions

source/assertions/ut.pkb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
create or replace package body ut is
22

3+
function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata is
4+
begin
5+
return ut_assertion_anydata(ut_data_value_anydata(a_actual), a_message);
6+
end;
7+
38
function expect(a_actual in blob, a_message varchar2 := null) return ut_assertion_blob is
49
begin
510
return ut_assertion_blob(ut_data_value_blob(a_actual), a_message);
@@ -50,8 +55,5 @@ create or replace package body ut is
5055
return ut_assertion_refcursor(ut_data_value_refcursor(a_actual), a_message);
5156
end;
5257

53-
-- function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata;
54-
--
55-
5658
end ut;
5759
/

source/assertions/ut.pks

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
create or replace package ut authid current_user as
22

3+
function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata;
4+
35
function expect(a_actual in blob, a_message varchar2 := null) return ut_assertion_blob;
46

57
function expect(a_actual in boolean, a_message varchar2 := null) return ut_assertion_boolean;
@@ -10,6 +12,8 @@ create or replace package ut authid current_user as
1012

1113
function expect(a_actual in number, a_message varchar2 := null) return ut_assertion_number;
1214

15+
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_assertion_refcursor;
16+
1317
function expect(a_actual in timestamp_unconstrained, a_message varchar2 := null) return ut_assertion_timestamp;
1418

1519
function expect(a_actual in timestamp_ltz_unconstrained, a_message varchar2 := null) return ut_assertion_timestamp_ltz;
@@ -18,10 +22,5 @@ create or replace package ut authid current_user as
1822

1923
function expect(a_actual in varchar2, a_message varchar2 := null) return ut_assertion_varchar2;
2024

21-
function expect(a_actual in sys_refcursor, a_message varchar2 := null) return ut_assertion_refcursor;
22-
23-
-- function expect(a_actual in anydata, a_message varchar2 := null) return ut_assertion_anydata;
24-
--
25-
2625
end ut;
2726
/

source/assertions/ut_assertion.tpb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ create or replace type body ut_assertion as
1111
);
1212
end;
1313

14+
member procedure to_equal(self in ut_assertion, a_expected anydata, a_nulls_are_equal boolean := null) is
15+
begin
16+
ut_utils.debug_log('ut_assertion.to_equal(self in ut_assertion, a_expected anydata, a_nulls_are_equal boolean := null)');
17+
self.build_assert_result( false, 'to_equal', ut_utils.to_string(xmltype(a_expected).getclobval()), 'anydata');
18+
end;
19+
1420
member procedure to_equal(self in ut_assertion, a_expected blob, a_nulls_are_equal boolean := null) is
1521
begin
1622
ut_utils.debug_log('ut_assertion.to_equal(self in ut_assertion, a_expected blob, a_nulls_are_equal boolean := null)');
@@ -77,6 +83,7 @@ create or replace type body ut_assertion as
7783
ut_utils.debug_log('ut_assertion.to_(self in ut_assertion, a_expectation ut_expectation)');
7884
l_assert_result :=
7985
case
86+
when self.actual_data is of (ut_data_value_anydata) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_anydata) )
8087
when self.actual_data is of (ut_data_value_blob) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_blob) )
8188
when self.actual_data is of (ut_data_value_boolean) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_boolean) )
8289
when self.actual_data is of (ut_data_value_clob) then a_expectation.run_expectation( treat(self.actual_data as ut_data_value_clob) )

source/assertions/ut_assertion.tps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ create or replace type ut_assertion as object
44
message varchar2(4000 char),
55
final member procedure build_assert_result( self in ut_assertion, a_assert_result boolean, a_assert_name varchar2,
66
a_expected_value_string in varchar2, a_expected_data_type varchar2 := null),
7+
member procedure to_equal(self in ut_assertion, a_expected anydata, a_nulls_are_equal boolean := null),
78
member procedure to_equal(self in ut_assertion, a_expected blob, a_nulls_are_equal boolean := null),
89
member procedure to_equal(self in ut_assertion, a_expected boolean, a_nulls_are_equal boolean := null),
910
member procedure to_equal(self in ut_assertion, a_expected clob, a_nulls_are_equal boolean := null),

source/assertions/ut_assertion_anydata.tpb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
create or replace type body ut_assertion_refcursor as
1+
create or replace type body ut_assertion_anydata as
22

3-
overriding member procedure to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null) is
3+
overriding member procedure to_equal(self in ut_assertion_anydata, a_expected anydata, a_nulls_are_equal boolean := null) is
44
begin
5-
ut_utils.debug_log('ut_assertion_refcursor.to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)');
5+
ut_utils.debug_log('ut_assertion_anydata.to_equal(self in ut_assertion_anydata, a_expected anydata, a_nulls_are_equal boolean := null)');
66
self.to_( equal(a_expected, a_nulls_are_equal) );
77
end;
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
create or replace type ut_assertion_refcursor under ut_assertion
1+
create or replace type ut_assertion_anydata under ut_assertion
22
(
3-
overriding member procedure to_equal(self in ut_assertion_refcursor, a_expected sys_refcursor, a_nulls_are_equal boolean := null)
3+
overriding member procedure to_equal(self in ut_assertion_anydata, a_expected anydata, a_nulls_are_equal boolean := null)
44
)
55
/

source/expectation_data_values/ut_data_value_anydata.tpb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
create or replace type body ut_data_value_clob as
2-
constructor function ut_data_value_clob(self in out nocopy ut_data_value_clob, a_value clob) return self as result is
1+
create or replace type body ut_data_value_anydata as
2+
constructor function ut_data_value_anydata(self in out nocopy ut_data_value_anydata, a_value anydata) return self as result is
33
begin
44
self.value := a_value;
5-
self.init('clob', ut_utils.boolean_to_int(a_value is null), ut_utils.to_string(a_value));
5+
self.init('anydata', ut_utils.boolean_to_int(a_value is null), ut_utils.to_string(xmltype(a_value).getclobval()));
66
return;
77
end;
88
end;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
create or replace type ut_data_value_clob under ut_data_value(
2-
value clob,
3-
constructor function ut_data_value_clob(self in out nocopy ut_data_value_clob, a_value clob) return self as result
1+
create or replace type ut_data_value_anydata under ut_data_value(
2+
value anydata,
3+
constructor function ut_data_value_anydata(self in out nocopy ut_data_value_anydata, a_value anydata) return self as result
44
)
55
/

source/expectations/equal.tpb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ create or replace type body equal as
1717
);
1818
end;
1919

20+
constructor function equal(self in out nocopy equal, a_expected anydata, a_nulls_are_equal boolean := null) return self as result is
21+
begin
22+
init(ut_data_value_anydata(a_expected), a_nulls_are_equal);
23+
return;
24+
end;
25+
2026
constructor function equal(self in out nocopy equal, a_expected blob, a_nulls_are_equal boolean := null) return self as result is
2127
begin
2228
init(ut_data_value_blob(a_expected), a_nulls_are_equal);
@@ -77,6 +83,16 @@ create or replace type body equal as
7783
return;
7884
end;
7985

86+
overriding member function run_expectation(a_actual ut_data_value_anydata) return ut_assert_result is
87+
l_expected anydata;
88+
begin
89+
l_expected := case when self.expected is of (ut_data_value_anydata) then treat(self.expected as ut_data_value_anydata).value end;
90+
return self.build_assert_result(
91+
xmltype(l_expected).getclobval() = xmltype(a_actual.value).getclobval()
92+
, a_actual
93+
);
94+
end;
95+
8096
overriding member function run_expectation(a_actual ut_data_value_blob) return ut_assert_result is
8197
begin
8298
return self.build_assert_result(

source/expectations/equal.tps

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ create or replace type equal under ut_expectation(
22
nulls_are_equal number(1,0),
33
member procedure init(self in out nocopy equal, a_expected ut_data_value, a_nulls_are_equal boolean),
44
overriding member function build_assert_result( self in equal, a_assert_result boolean, a_actual ut_data_value) return ut_assert_result,
5+
constructor function equal(self in out nocopy equal, a_expected anydata, a_nulls_are_equal boolean := null) return self as result,
56
constructor function equal(self in out nocopy equal, a_expected blob, a_nulls_are_equal boolean := null) return self as result,
67
constructor function equal(self in out nocopy equal, a_expected boolean, a_nulls_are_equal boolean := null) return self as result,
78
constructor function equal(self in out nocopy equal, a_expected clob, a_nulls_are_equal boolean := null) return self as result,
@@ -12,6 +13,7 @@ create or replace type equal under ut_expectation(
1213
constructor function equal(self in out nocopy equal, a_expected timestamp_tz_unconstrained, a_nulls_are_equal boolean := null) return self as result,
1314
constructor function equal(self in out nocopy equal, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null) return self as result,
1415
constructor function equal(self in out nocopy equal, a_expected varchar2, a_nulls_are_equal boolean := null) return self as result,
16+
overriding member function run_expectation(a_actual ut_data_value_anydata) return ut_assert_result,
1517
overriding member function run_expectation(a_actual ut_data_value_blob) return ut_assert_result,
1618
overriding member function run_expectation(a_actual ut_data_value_boolean) return ut_assert_result,
1719
overriding member function run_expectation(a_actual ut_data_value_clob) return ut_assert_result,

0 commit comments

Comments
 (0)