@@ -2,6 +2,9 @@ create or replace package demo_expectations is
22
33 -- %suite(Demoing asserts)
44
5+ -- %test(demo of expectations with nulls)
6+ procedure demo_nulls_on_expectations;
7+
58 -- %test(demo of failure for to_equal expectation on value mismatch)
69 procedure demo_to_equal_failure;
710
5356
5457create or replace package body demo_expectations is
5558
59+ procedure demo_nulls_on_expectations is
60+ begin
61+ --fails on incompatible data types
62+ ut.expect( to_clob('a text'), 'this should fail' ).to_equal( 'a text' );
63+ ut.expect( to_clob('a text'), 'this should fail' ).to_( equal( 'a text' ) );
64+ ut.expect( cast(systimestamp as timestamp), 'this should fail' ).to_( equal( systimestamp ) );
65+ ut.expect( to_clob('a text'), 'this should fail' ).not_to( equal( 'a text' ) );
66+ ut.expect( cast(systimestamp as timestamp), 'this should fail' ).not_to( equal( systimestamp ) );
67+
68+ --fails on incompatible data types even if values are null
69+ ut.expect( to_char(null), 'this should fail' ).to_( equal( to_char(null) ) );
70+ ut.expect( to_char(null), 'this should fail' ).not_to( equal( to_char(null) ) );
71+
72+ --fails on nulls not beeig equal
73+ ut_assert_processor.nulls_are_equal(false);
74+ ut.expect( to_char(null), 'fails when global null_are_equal=false' ).to_( equal(to_char(null) ) );
75+ ut_assert_processor.nulls_are_equal( true );
76+ ut.expect( to_char(null), 'fails when local null_are_equal=false' ).to_( equal(to_char(null), a_nulls_are_equal => false ) );
77+
78+ --succeeds when nulls are considered equal
79+ ut_assert_processor.nulls_are_equal(false);
80+ ut.expect( to_char(null) , 'succeeds when local null_are_equal=true' ).to_( equal( to_char(null), a_nulls_are_equal => true ) );
81+ ut_assert_processor.nulls_are_equal( true );
82+ ut.expect( to_char(null), 'succeeds when global null_are_equal=true' ).to_( equal( to_char(null) ) );
83+
84+ --fails as null is not comparable with not null
85+ ut.expect( to_char(null), 'fails on null = not null' ).to_( equal( 'a text' ) );
86+ ut.expect( 'a text', 'fails on not null = null' ).to_( equal( to_char(null) ) );
87+ ut.expect( to_char(null), 'fails on null <> not null' ).not_to( equal( 'a text' ) );
88+ ut.expect( 'a text', 'fails on not null <> null' ).not_to( equal( to_char(null) ) );
89+ ut.expect( to_char(null), 'fails on null <> not null, with a_nulls_are_equal => true' ).not_to( equal( 'a text', a_nulls_are_equal => true ) );
90+ ut.expect( 'a text', 'fails on not null <> null, with a_nulls_are_equal => false' ).not_to( equal( to_char(null), a_nulls_are_equal => false ) );
91+
92+ ut.expect( to_char(null), 'fails on null like ''text''' ).to_( be_like( 'a text' ) );
93+ ut.expect( to_char(null), 'fails on null not like ''text''' ).not_to( be_like( 'a text' ) );
94+
95+ ut.expect( cast(null as boolean), 'fails on null = true' ).to_( be_true );
96+ ut.expect( cast(null as boolean), 'fails on null <> true' ).not_to( be_true );
97+ ut.expect( cast(null as boolean), 'fails on null = false' ).to_( be_false );
98+ ut.expect( cast(null as boolean), 'fails on null <> false' ).not_to( be_false );
99+
100+ end;
101+
56102 procedure demo_to_equal_failure is
57103 l_expected_anydata anydata := anydata.convertObject( department$('IT') );
58104 l_expected_blob blob := to_blob('AF12FF');
0 commit comments