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

Skip to content

Commit 98beb1c

Browse files
authored
Merge pull request #155 from Pazus/fix_annotations
fix multiline annotations parsing and accessible by
2 parents febf883 + 87bf121 commit 98beb1c

4 files changed

Lines changed: 86 additions & 4 deletions

source/core/annotations/ut_annotations.pkb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ create or replace package body ut_annotations as
1818

1919

2020
function delete_multiline_comments(a_source in clob) return clob is
21-
l_tmp_clob clob;
2221
begin
2322

2423
/* l_tmp_clob := regexp_replace(srcstr => a_source
@@ -135,9 +134,9 @@ create or replace package body ut_annotations as
135134
l_package_comments varchar2(32767);
136135
begin
137136
l_package_comments := regexp_substr(srcstr => a_source
138-
,pattern => '^\s*(CREATE\s+(OR\s+REPLACE)?(\s+(NON)?EDITIONABLE)?\s+)?PACKAGE .*?\s+(AS|IS)\s+((.*?{COMMENT#\d+}\s?)+)'
137+
,pattern => '^\s*(CREATE\s+(OR\s+REPLACE)?(\s+(NON)?EDITIONABLE)?\s+)?PACKAGE\s[^;]*?(\s+(AS|IS)\s+)((.*?{COMMENT#\d+}\s?)+)'
139138
,modifier => 'i'
140-
,subexpression => 6);
139+
,subexpression => 7);
141140

142141
-- parsing for package annotations
143142
return
@@ -329,7 +328,7 @@ create or replace package body ut_annotations as
329328

330329
l_source := ut_metadata.get_package_spec_source(a_owner_name, a_name);
331330

332-
if l_source is null then
331+
if l_source is null or sys.dbms_lob.getlength(l_source)=0 then
333332
return null;
334333
else
335334
return parse_package_annotations(l_source);

tests/RunAll.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ create table ut$test_table (val varchar2(1));
6767
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParseComplexPackage.sql
6868
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageAndProcedureLevelAnnotations.sql
6969
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotation.sql
70+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationAccessibleBy.sql
71+
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationMultilineDeclare.sql
7072
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithKeyValue.sql
7173
@@lib/RunTest.sql ut_annotations/ut_annotations.parse_package_annotations.ParsePackageLevelAnnotationWithMultilineComment.sql
7274
@@lib/RunTest.sql ut_metadata/ut_metadata.form_name.TrimStandaloneProgramName.sql
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
PROMPT Parse package level annotations Accessible by
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 accessible by (foo) AS
12+
-- %suite
13+
-- %displayname(Name of suite)
14+
-- %suitepath(all.globaltests)
15+
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.val := 'Name of suite';
25+
l_expected.package_annotations('suite') := cast( null as ut_annotations.tt_annotation_params);
26+
l_expected.package_annotations('displayname')(1) := l_ann_param;
27+
28+
l_ann_param := null;
29+
l_ann_param.val := 'all.globaltests';
30+
l_expected.package_annotations('suitepath')(1) := l_ann_param;
31+
32+
check_annotation_parsing(l_expected, l_parsing_result);
33+
34+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
35+
:test_result := ut_utils.tr_success;
36+
end if;
37+
38+
end;
39+
/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
PROMPT Parse package level annotations with multiline declaration
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
12+
ACCESSIBLE BY (calling_proc)
13+
authid current_user
14+
AS
15+
-- %suite
16+
-- %displayname(Name of suite)
17+
-- %suitepath(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.val := 'Name of suite';
28+
l_expected.package_annotations('suite') := cast( null as ut_annotations.tt_annotation_params);
29+
l_expected.package_annotations('displayname')(1) := l_ann_param;
30+
31+
l_ann_param := null;
32+
l_ann_param.val := 'all.globaltests';
33+
l_expected.package_annotations('suitepath')(1) := l_ann_param;
34+
35+
check_annotation_parsing(l_expected, l_parsing_result);
36+
37+
if ut_assert_processor.get_aggregate_asserts_result = ut_utils.tr_success then
38+
:test_result := ut_utils.tr_success;
39+
end if;
40+
41+
end;
42+
/

0 commit comments

Comments
 (0)