Skip to content

Commit 4185a37

Browse files
committed
Improved examples on expectations.
1 parent 3677fb1 commit 4185a37

3 files changed

Lines changed: 137 additions & 1 deletion

File tree

examples/RunAllExamples.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ prompt RunExpectations
2727
@@award_bonus/run_award_bonus_test.sql
2828
@@between_string/run_betwnstr_test.sql
2929
@@remove_rooms_by_name/run_remove_rooms_by_name_test.sql
30-
30+
@@demo_of_expectations/run.sql
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
create or replace type demo_department as object(
2+
dept_name varchar2(30)
3+
)
4+
/
5+
6+
create or replace type demo_department_new as object(
7+
dept_name varchar2(30)
8+
)
9+
/
10+
11+
create or replace type demo_departments as table of demo_department
12+
/
13+
14+
create or replace package demo_equal_matcher as
15+
16+
-- %suite(Equal matcher)
17+
-- %suitepackage(org.utplsql.v3.demo.matchers)
18+
19+
-- TODO this should go into context(compare_objects, Comparing objects)
20+
-- %context(compare_objects, Comparing objects)
21+
22+
-- %test(Gives success when comparing identical objects containing identical data)
23+
procedure object_compare_success;
24+
25+
-- %test(Gives failure when comparing to a null actual)
26+
procedure object_compare_null_actual;
27+
28+
-- %test(Gives failure when comparing to a null expected)
29+
procedure object_compare_null_expected;
30+
31+
-- %test(Gives success when comparing null actual to a null expected)
32+
procedure object_compare_null_both_ok;
33+
34+
-- %test(Gives failure when comparing null actual to a null expected, setting null equal to false)
35+
procedure object_compare_null_both_fail;
36+
37+
-- %test(Gives failure when comparing identical objects containing different data)
38+
procedure object_compare_different_data;
39+
40+
-- %test(Gives failure when comparing different objects containing identical data)
41+
procedure object_compare_different_type;
42+
43+
-- %end_context
44+
45+
end;
46+
/
47+
48+
create or replace package body demo_equal_matcher as
49+
50+
procedure object_compare_success is
51+
l_expected demo_department;
52+
l_actual demo_department;
53+
begin
54+
--setup the expected
55+
l_expected := demo_department('Sales');
56+
--get the actual data
57+
l_actual := demo_department('Sales');
58+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
59+
);
60+
end;
61+
62+
procedure object_compare_null_actual is
63+
l_expected demo_department;
64+
l_actual demo_department;
65+
begin
66+
--setup the expected
67+
l_expected := demo_department('Sales');
68+
--get the actual data
69+
-- nothing done
70+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
71+
);
72+
end;
73+
74+
procedure object_compare_null_expected is
75+
l_expected demo_department;
76+
l_actual demo_department;
77+
begin
78+
l_actual := demo_department('Sales');
79+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
80+
);
81+
end;
82+
83+
procedure object_compare_null_both_ok is
84+
l_expected demo_department;
85+
l_actual demo_department;
86+
begin
87+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
88+
);
89+
end;
90+
91+
procedure object_compare_null_both_fail is
92+
l_expected demo_department;
93+
l_actual demo_department;
94+
begin
95+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected),false)
96+
);
97+
end;
98+
99+
100+
procedure object_compare_different_data is
101+
l_expected demo_department;
102+
l_actual demo_department;
103+
begin
104+
--setup the expected
105+
l_expected := demo_department('Sales');
106+
--get the actual data
107+
l_actual := demo_department('HR');
108+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
109+
);
110+
end;
111+
112+
procedure object_compare_different_type is
113+
l_expected demo_department;
114+
l_actual demo_department_new;
115+
begin
116+
--setup the expected
117+
l_expected := demo_department('Sales');
118+
--get the actual data
119+
l_actual := demo_department_new('Sales');
120+
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
121+
);
122+
end;
123+
124+
end;
125+
/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@@demo_equal_matcher.sql
2+
3+
set serveroutput on size unlimited format truncated
4+
5+
exec ut_runner.run(user||'.demo_equal_matcher');
6+
7+
drop package demo_equal_matcher;
8+
drop type demo_departments;
9+
drop type demo_department_new;
10+
drop type demo_department;
11+

0 commit comments

Comments
 (0)