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

Skip to content

Commit 2b07eb1

Browse files
committed
fast and operating
added parsing tests
1 parent f13c57e commit 2b07eb1

8 files changed

Lines changed: 339 additions & 0 deletions

tests/RunAll.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ set serveroutput on size unlimited format truncated
1010
--Global setup
1111
@@helpers/ut_example_tests.pks
1212
@@helpers/ut_example_tests.pkb
13+
@@helpers/check_annotation_parsing.prc
1314

1415
--Tests to invoke
16+
1517
@@lib/RunTest.sql ut_test/ut_test.OwnerNameInvalid.sql
1618
@@lib/RunTest.sql ut_test/ut_test.OwnerNameNull.sql
1719
@@lib/RunTest.sql ut_test/ut_test.PackageInInvalidState.sql
@@ -92,8 +94,18 @@ set serveroutput on size unlimited format truncated
9294
@@lib/RunTest.sql ut_utils/ut_utils.to_string.veryBigNumber.sql
9395
@@lib/RunTest.sql ut_utils/ut_utils.to_string.Date.sql
9496
@@lib/RunTest.sql ut_utils/ut_utils.to_string.Timestamp.sql
97+
98+
99+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotation.sql
100+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
101+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
102+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseAnnotationNotBeforeProcedure.sql
103+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageAndProcedureLevelAnnotations.sql
104+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseComplexPackage.sql
105+
95106
--Global cleanup
96107
drop package ut_example_tests;
108+
drop procedure check_annotation_parsing;
97109

98110
--Finally
99111
@@lib/RunSummary
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
create or replace procedure check_annotation_parsing(a_expected ut_annotations.typ_annotated_package, a_parsing_result ut_annotations.typ_annotated_package) is
2+
procedure check_annotation_params(a_msg varchar2, a_expected ut_annotations.tt_annotation_params, a_actual ut_annotations.tt_annotation_params) is
3+
begin
4+
ut_assert.are_equal('['||a_msg||']Check number of annotation params', a_expected.count, a_actual.count);
5+
6+
if a_expected.count = a_actual.count and a_expected.count > 0 then
7+
for i in 1..a_expected.count loop
8+
if a_expected(i).key is not null then
9+
ut_assert.are_equal('['||a_msg||'('||i||')]Check annotation param key',a_expected(i).key,a_actual(i).key);
10+
else
11+
ut_assert.is_null('['||a_msg||'('||i||')]Check annotation param key',a_actual(i).key);
12+
end if;
13+
14+
if a_expected(i).value is not null then
15+
ut_assert.are_equal('['||a_msg||'('||i||')]Check annotation param value',a_expected(i).value,a_actual(i).value);
16+
else
17+
ut_assert.is_null('['||a_msg||'('||i||')]Check annotation param value',a_actual(i).value);
18+
end if;
19+
end loop;
20+
end if;
21+
end;
22+
23+
procedure check_annotations(a_msg varchar2, a_expected ut_annotations.tt_annotations, a_actual ut_annotations.tt_annotations) is
24+
l_ind varchar2(500);
25+
begin
26+
ut_assert.are_equal('['||a_msg||']Check number of annotations parsed',a_expected.count,a_actual.count);
27+
28+
if a_expected.count = a_actual.count and a_expected.count > 0 then
29+
l_ind := a_expected.first;
30+
while l_ind is not null loop
31+
32+
ut_assert.this('['||a_msg||']Check annotation exists', a_actual.exists(l_ind));
33+
if a_actual.exists(l_ind) then
34+
check_annotation_params(a_msg||'.'||l_ind,a_expected(l_ind),a_actual(l_ind));
35+
end if;
36+
l_ind := a_expected.next(l_ind);
37+
end loop;
38+
end if;
39+
end;
40+
41+
procedure check_procedures(a_msg varchar2, a_expected ut_annotations.tt_procedure_annotations, a_actual ut_annotations.tt_procedure_annotations) is
42+
l_ind varchar2(500);
43+
begin
44+
ut_assert.are_equal('['||a_msg||']Check number of procedures parsed',a_expected.count,a_actual.count);
45+
46+
if a_expected.count = a_actual.count and a_expected.count > 0 then
47+
l_ind := a_expected.first;
48+
while l_ind is not null loop
49+
50+
ut_assert.this('['||a_msg||']Check procedure exists', a_actual.exists(l_ind));
51+
if a_actual.exists(l_ind) then
52+
check_annotations(a_msg||'.'||l_ind,a_expected(l_ind),a_actual(l_ind));
53+
end if;
54+
l_ind := a_expected.next(l_ind);
55+
end loop;
56+
end if;
57+
end;
58+
begin
59+
check_annotations('PACKAGE',a_expected.package_annotations,a_parsing_result.package_annotations);
60+
check_procedures('PROCEDURES',a_expected.procedure_annotations,a_parsing_result.procedure_annotations);
61+
end check_annotation_parsing;
62+
/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PROMPT Parse package level annotations with annotations "in the air"
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(Name of suite)
13+
-- %suitepackage(all.globaltests)
14+
15+
-- %ann1(Name of suite)
16+
-- %ann2(all.globaltests)
17+
18+
procedure foo;
19+
END;';
20+
21+
--Act
22+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
23+
24+
--Assert
25+
l_ann_param := null;
26+
l_ann_param.value := 'Name of suite';
27+
l_expected.package_annotations('suite')(1) := l_ann_param;
28+
29+
l_ann_param := null;
30+
l_ann_param.value := 'all.globaltests';
31+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
32+
33+
check_annotation_parsing(l_expected, l_parsing_result);
34+
35+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
36+
:test_result := ut_utils.tr_success;
37+
end if;
38+
39+
end;
40+
/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
PROMPT Parse complex package
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(Name of suite)
13+
-- %suitepackage(all.globaltests)
14+
15+
--%test
16+
procedure foo;
17+
18+
19+
--%setup
20+
procedure foo2;
21+
22+
--test comment
23+
-- wrong comment
24+
25+
26+
/*
27+
describtion of the procedure
28+
*/
29+
--%setup(key=testval)
30+
PROCEDURE foo3(a_value number default null);
31+
32+
function foo4(a_val number default null
33+
, a_par varchar2 default := ''asdf'');
34+
END;';
35+
36+
--Act
37+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
38+
39+
--Assert
40+
l_ann_param := null;
41+
l_ann_param.value := 'Name of suite';
42+
l_expected.package_annotations('suite')(1) := l_ann_param;
43+
44+
l_ann_param := null;
45+
l_ann_param.value := 'all.globaltests';
46+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
47+
48+
l_expected.procedure_annotations('foo')('test') := cast( null as ut_annotations.tt_annotation_params);
49+
l_expected.procedure_annotations('foo2')('setup') := cast( null as ut_annotations.tt_annotation_params);
50+
51+
l_ann_param := null;
52+
l_ann_param.key := 'key';
53+
l_ann_param.value := 'testval';
54+
l_expected.procedure_annotations('foo3')('setup')(1) := l_ann_param;
55+
56+
check_annotation_parsing(l_expected, l_parsing_result);
57+
58+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
59+
:test_result := ut_utils.tr_success;
60+
end if;
61+
62+
end;
63+
/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PROMPT Parse package level annotations
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(Name of suite)
13+
-- %suitepackage(all.globaltests)
14+
15+
--%test
16+
procedure foo;
17+
END;';
18+
19+
--Act
20+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
21+
22+
--Assert
23+
l_ann_param := null;
24+
l_ann_param.value := 'Name of suite';
25+
l_expected.package_annotations('suite')(1) := l_ann_param;
26+
27+
l_ann_param := null;
28+
l_ann_param.value := 'all.globaltests';
29+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
30+
31+
l_expected.procedure_annotations('foo')('test') := cast( null as ut_annotations.tt_annotation_params);
32+
33+
check_annotation_parsing(l_expected, l_parsing_result);
34+
35+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
36+
:test_result := ut_utils.tr_success;
37+
end if;
38+
39+
end;
40+
/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
PROMPT Parse package level annotations
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(Name of suite)
13+
-- %suitepackage(all.globaltests)
14+
15+
procedure foo;
16+
END;';
17+
18+
--Act
19+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
20+
21+
--Assert
22+
l_ann_param := null;
23+
l_ann_param.value := 'Name of suite';
24+
l_expected.package_annotations('suite')(1) := l_ann_param;
25+
26+
l_ann_param := null;
27+
l_ann_param.value := 'all.globaltests';
28+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
29+
30+
check_annotation_parsing(l_expected, l_parsing_result);
31+
32+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
33+
:test_result := ut_utils.tr_success;
34+
end if;
35+
36+
end;
37+
/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PROMPT Parse package level annotations
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
-- %suite(name = Name of suite)
13+
-- %suitepackage(key=all.globaltests,key2=foo)
14+
15+
procedure foo;
16+
END;';
17+
18+
--Act
19+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
20+
21+
--Assert
22+
l_ann_param := null;
23+
l_ann_param.key := 'name';
24+
l_ann_param.value := 'Name of suite';
25+
l_expected.package_annotations('suite')(1) := l_ann_param;
26+
27+
l_ann_param := null;
28+
l_ann_param.key := 'key';
29+
l_ann_param.value := 'all.globaltests';
30+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
31+
32+
l_ann_param := null;
33+
l_ann_param.key := 'key2';
34+
l_ann_param.value := 'foo';
35+
l_expected.package_annotations('suitepackage')(2) := l_ann_param;
36+
37+
check_annotation_parsing(l_expected, l_parsing_result);
38+
39+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
40+
:test_result := ut_utils.tr_success;
41+
end if;
42+
43+
end;
44+
/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
PROMPT Parse package level annotations with multiline comment
2+
3+
--Arrange
4+
declare
5+
l_source clob;
6+
l_parsing_result ut_annotations.typ_annotated_package;
7+
l_expected ut_annotations.typ_annotated_package;
8+
l_ann_param ut_annotations.typ_annotation_param;
9+
10+
begin
11+
l_source := 'PACKAGE test_tt AS
12+
/*
13+
Some comment
14+
-- inlined
15+
*/
16+
-- %suite(Name of suite)
17+
-- %suitepackage(all.globaltests)
18+
19+
procedure foo;
20+
END;';
21+
22+
--Act
23+
l_parsing_result := ut_annotations.parse_package_annotations(l_source);
24+
25+
--Assert
26+
l_ann_param := null;
27+
l_ann_param.value := 'Name of suite';
28+
l_expected.package_annotations('suite')(1) := l_ann_param;
29+
30+
l_ann_param := null;
31+
l_ann_param.value := 'all.globaltests';
32+
l_expected.package_annotations('suitepackage')(1) := l_ann_param;
33+
34+
check_annotation_parsing(l_expected, l_parsing_result);
35+
36+
if ut_assert.get_aggregate_asserts_result = ut_utils.tr_success then
37+
:test_result := ut_utils.tr_success;
38+
end if;
39+
40+
end;
41+
/

0 commit comments

Comments
 (0)