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

Skip to content

Commit 5a6e5f1

Browse files
committed
Fixed a bug in be_between matcher (for null values).
Refactored and added more tests.
1 parent b5c8cbc commit 5a6e5f1

34 files changed

Lines changed: 254 additions & 198 deletions

File tree

source/expectations/matchers/ut_be_between.tpb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ create or replace type body ut_be_between is
7575
end;
7676

7777
overriding member function run_matcher(self in out nocopy ut_be_between, a_actual ut_data_value) return boolean is
78+
l_lower_result boolean;
79+
l_upper_result boolean;
7880
l_result boolean;
7981
begin
8082
if self.lower_bound.data_type = a_actual.data_type then
81-
l_result := a_actual >= self.lower_bound and a_actual <= self.upper_bound;
83+
l_lower_result := a_actual >= self.lower_bound;
84+
l_upper_result := a_actual <= self.upper_bound;
85+
if l_lower_result is not null and l_upper_result is not null then
86+
l_result := l_lower_result and l_upper_result;
87+
end if;
8288
else
8389
l_result := (self as ut_matcher).run_matcher(a_actual);
8490
end if;

tests/RunAll.sql

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,11 @@ exec ut_coverage.coverage_start_develop();
4242
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
4343
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
4444

45-
@@ut_expectations/ut.expect.to_be_between.GivesFailureForDifferentValues.sql
46-
@@ut_expectations/ut.expect.to_be_between.GivesFailureWhenActualIsNull.sql
47-
@@ut_expectations/ut.expect.to_be_between.GivesFailureWhenBothActualAndExpectedRangeIsNull.sql
48-
@@ut_expectations/ut.expect.to_be_between.GivesFailureWhenExpectedRangeIsNull.sql
49-
@@ut_expectations/ut.expect.to_be_between.GivesSuccessWhenDifferentTypes.sql
50-
@@ut_expectations/ut.expect.to_be_between.GivesTrueForCorrectValues.sql
51-
@@ut_expectations/ut.expect.to_be_between.with_text.GivesTheProvidedTextAsMessage.sql
52-
@@ut_expectations/ut.expect.not_to_be_between.GivesTrueForCorrectValues.sql
45+
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNotBoolean.sql
5346
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsNull.sql
5447
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesFailureWhenExpessionIsTrue.sql
5548
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_false.GivesSuccessWhenExpessionIsFalse.sql
56-
@@ut_expectations/ut.expect.to_be_like.sql
49+
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_like.FailsForUnsupportedDatatype.sql
5750
@@ut_expectations/ut.expect.to_be_not_null.GivesFailureWhenActualIsNull.sql
5851
@@ut_expectations/ut.expect.to_be_not_null.GivesSuccessWhenActualIsNotNull.sql
5952
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_null.anydata.GivesSuccessWhenAnydataIsNull.sql
@@ -63,6 +56,7 @@ exec ut_coverage.coverage_start_develop();
6356
@@ut_expectations/ut.expect.to_be_null.GivesSuccessWhenActualIsNull.sql
6457
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_null.refcursor.GivesSuccessWhenCursorIsNull.sql
6558
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsFalse.sql
59+
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNotBoolean.sql
6660
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesFailureWhenExpessionIsNull.sql
6761
@@lib/RunTest.sql ut_expectations/ut.expect.to_be_true.GivesSuccessWhenExpessionIsTrue.sql
6862
@@lib/RunTest.sql ut_expectations/ut.expect.to_equal.anydata.GivesFailureWhenBothObjectsAreNullButDifferentType.sql
@@ -99,18 +93,21 @@ exec ut_coverage.coverage_start_develop();
9993
@@ut_expectations/ut.expect.to_equal.PutsNullIntoStringValueWhenActualIsNull.sql
10094
@@ut_expectations/ut.expect.to_equal.PutsNullIntoStringValueWhenExpectedIsNull.sql
10195
@@ut_expectations/ut.expect.to_equal.with_text.GivesTheProvidedTextAsMessage.sql
96+
@@ut_expectations/ut.expect.not_to_equal.GivesFailureForDifferentDataTypes.sql
10297
@@ut_expectations/ut.expect.not_to_equal.GivesFailureForEqualValues.sql
10398
@@ut_expectations/ut.expect.not_to_equal.GivesSuccessForDifferentValues.sql
104-
@@ut_expectations/ut.expect.to_match.sql
99+
@@lib/RunTest.sql ut_expectations/ut.expect.to_match.FailsForUnsupportedDatatype.sql
105100
@@lib/RunTest.sql ut_expectations/ut_data_value_object.compare.Gives0WhenComparingIdenticalObjects.sql
106101
@@lib/RunTest.sql ut_expectations/ut_expectation_processor.nulls_are_equal.raisesExceptionWhenTryingToSetNullValue.sql
107102

108103
@@ut_matchers/be_between.sql
104+
@@ut_matchers/be_empty.sql
105+
@@ut_matchers/be_like.sql
109106
@@ut_matchers/greater_or_equal.sql
110107
@@ut_matchers/greater_than.sql
111108
@@ut_matchers/less_or_equal.sql
112109
@@ut_matchers/less_than.sql
113-
@@ut_matchers/be_empty.sql
110+
@@ut_matchers/match.sql
114111

115112
@@lib/RunTest.sql ut_matchers/timestamp_between.sql
116113
@@lib/RunTest.sql ut_matchers/timestamp_ltz_between.sql

tests/ut_expectations/common/ut.expect.not_to_be_between.scalar.common.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ut_expectations/common/ut.expect.to_be_between.scalar.common.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ut_expectations/common/ut.expect.to_be_between.scalar.different_types.common.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ut_expectations/common/ut.expect.to_be_between.scalar.with_message.common.sql

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare
55
l_result integer;
66
begin
77
--Act
8-
ut.expect(l_actual).to_equal(l_expected);
8+
ut.expect(l_actual).&&5.to_equal(l_expected);
99
l_result := ut_expectation_processor.get_status();
1010
--Assert
1111
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure then

tests/ut_expectations/ut.expect.not_to_be_between.GivesTrueForCorrectValues.sql

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'blob' 'clob' 'to_blob(''ABC'')' '''ABC''' 'not_'"
2+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'clob' 'blob' '''ABC''' 'to_blob(''ABC'')' 'not_'"
3+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'clob' 'anydata' '''ABC''' 'null' 'not_'"
4+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'anydata' 'sys_refcursor' 'null' 'null' 'not_'"
5+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'sys_refcursor' 'anydata' 'null' 'null' 'not_'"
6+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'clob' 'varchar2(4000)' '''Abc''' '''Abc''' 'not_'"
7+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'date' 'timestamp' 'sysdate' 'sysdate' 'not_'"
8+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'date' 'timestamp with local time zone' 'sysdate' 'sysdate' 'not_'"
9+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'timestamp' 'date' 'sysdate' 'sysdate' 'not_'"
10+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'timestamp with local time zone' 'timestamp' 'sysdate' 'sysdate' 'not_'"
11+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'timestamp with local time zone' 'timestamp with time zone' 'sysdate' 'sysdate' 'not_'"
12+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'number' 'varchar2(4000)' '1' '''1''' 'not_'"
13+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'varchar2(4000)' 'number' '''1''' '1' 'not_'"
14+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'varchar2(4000)' 'boolean' '''true''' 'true' 'not_'"
15+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'interval day to second' 'interval year to month' '''2 01:00:00''' '''1-1''' 'not_'"
16+
@@lib/RunTest.sql "ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql 'interval year to month' 'interval day to second' '''1-1''' '''2 01:00:00''' 'not_'"
17+

tests/ut_expectations/ut.expect.to_be_between.GivesFailureForDifferentValues.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)