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

Skip to content

Commit 46f3d12

Browse files
committed
Update tests
1 parent 6c513be commit 46f3d12

4 files changed

Lines changed: 164 additions & 9 deletions

File tree

source/core/annotations/ut_annotation_parser.pkb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,17 @@ create or replace package body ut_annotation_parser as
7272
a_subobject_name varchar2 := null
7373
) is
7474
l_loop_index binary_integer := 1;
75-
l_annotation_index binary_integer;
75+
l_annotation_index binary_integer := 1;
7676
begin
7777

7878
-- loop while there are unprocessed comment blocks
79-
loop
79+
while l_annotation_index is not null loop
8080
-- define index of the comment block and get it's content from cache
8181
l_annotation_index := regexp_substr( a_source ,gc_comment_replacer_regex_ptrn ,1 ,l_loop_index ,subexpression => 1);
82-
exit when l_annotation_index is null;
83-
add_annotation( a_annotations, l_annotation_index, a_comments( l_annotation_index ), a_subobject_name );
84-
l_loop_index := l_loop_index + 1;
82+
if l_annotation_index is not null then
83+
add_annotation( a_annotations, l_annotation_index, a_comments( l_annotation_index ), a_subobject_name );
84+
l_loop_index := l_loop_index + 1;
85+
end if;
8586
end loop;
8687

8788
end add_annotations;
@@ -343,7 +344,7 @@ create or replace package body ut_annotation_parser as
343344

344345
dbms_lob.freetemporary(l_source);
345346

346-
select /*+ no_parallel */ value(x) bulk collect into l_result from table(l_annotations) x order by x.position;
347+
select /*+ no_parallel */ value(x) bulk collect into l_result from table(l_annotations) x order by x.position asc;
347348

348349
return l_result;
349350
end parse_object_annotations;

source/core/ut_utils.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ create or replace package body ut_utils is
2323
gc_invalid_xml_char constant varchar2(50) := '[^_[:alnum:]\.-]';
2424
gc_full_valid_xml_name constant varchar2(50) := '^([[:alpha:]])([_[:alnum:]\.-])*$';
2525
gc_owner_hash constant integer(11) := dbms_utility.get_hash_value( ut_owner(), 0, power(2,31)-1);
26-
gc_open_chars constant varchar2(4):= chr(91) || chr(123) || chr(40) || chr(60); -- [{(
27-
gc_close_chars constant varchar2(4):= chr(93) || chr(125) || chr(41) || chr(62); -- ]})>
26+
gc_open_chars constant varchar2(4):= chr(91) || chr(123) || chr(40) || chr(60); -- [{( this has very specific purpose to not confuse lexer in IDE
27+
gc_close_chars constant varchar2(4):= chr(93) || chr(125) || chr(41) || chr(62); -- ]})> this has very specific purpose to not confuse lexer in IDE
2828
gc_max_plsql_source_len constant integer := 32767;
2929

3030
function surround_with(a_value varchar2, a_quote_char varchar2) return varchar2 is

test/ut3_tester/core/annotations/test_annotation_parser.pkb

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,5 +919,150 @@ procedure test_windows_newline_lines
919919
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
920920
end;
921921

922+
procedure test_multiline_proc_header_lines is
923+
l_source dbms_preprocessor.source_lines_t;
924+
l_actual ut3_develop.ut_annotations;
925+
l_expected ut3_develop.ut_annotations;
926+
begin
927+
--Arrange
928+
-- procedure header spans multiple lines before terminating ;
929+
l_source := make_source(ut_varchar2_list(
930+
'PACKAGE test_tt AS' || chr(10),
931+
' -- %suite' || chr(10),
932+
'' || chr(10),
933+
' --%test' || chr(10),
934+
' procedure foo(' || chr(10),
935+
' a_param1 varchar2' || chr(10),
936+
' ,a_param2 number default null' || chr(10),
937+
' );' || chr(10),
938+
' END;' || chr(10)
939+
));
940+
941+
--Act
942+
l_actual := ut3_develop.ut_annotation_parser.parse_object_annotations(l_source, 'PACKAGE');
943+
944+
--Assert
945+
l_expected := ut3_develop.ut_annotations(
946+
ut3_develop.ut_annotation( 2, 'suite', null, null ),
947+
ut3_develop.ut_annotation( 4, 'test', null, 'foo' )
948+
);
949+
950+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
951+
end;
952+
953+
procedure test_non_comment_line_resets_block_lines is
954+
l_source dbms_preprocessor.source_lines_t;
955+
l_actual ut3_develop.ut_annotations;
956+
l_expected ut3_develop.ut_annotations;
957+
begin
958+
--Arrange
959+
-- a non-comment non-proc line between annotation and procedure breaks the association
960+
-- %test becomes a floating top-level annotation with no subobject
961+
l_source := make_source(ut_varchar2_list(
962+
'PACKAGE test_tt AS' || chr(10),
963+
' -- %suite' || chr(10),
964+
'' || chr(10),
965+
' --%test' || chr(10),
966+
' pragma serially_reusable;' || chr(10), -- resets accumulator
967+
' procedure foo;' || chr(10),
968+
' END;' || chr(10)
969+
));
970+
971+
--Act
972+
l_actual := ut3_develop.ut_annotation_parser.parse_object_annotations(l_source, 'PACKAGE');
973+
974+
--Assert
975+
-- %test is NOT associated with foo — accumulator was reset by pragma line
976+
-- it surfaces as a top-level annotation with no subobject_name
977+
l_expected := ut3_develop.ut_annotations(
978+
ut3_develop.ut_annotation( 2, 'suite', null, null ),
979+
ut3_develop.ut_annotation( 4, 'test', null, null )
980+
);
981+
982+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
983+
end;
984+
985+
procedure test_annotation_not_at_line_start_ignored_lines is
986+
l_source dbms_preprocessor.source_lines_t;
987+
l_actual ut3_develop.ut_annotations;
988+
l_expected ut3_develop.ut_annotations;
989+
begin
990+
--Arrange
991+
-- % appears in line but comment is not at start of line — should be ignored
992+
l_source := make_source(ut_varchar2_list(
993+
'PACKAGE test_tt AS' || chr(10),
994+
' -- %suite' || chr(10),
995+
' x := ''value%with%percent'';' || chr(10), -- % present but -- not at line start
996+
' procedure foo;' || chr(10),
997+
' END;' || chr(10)
998+
));
999+
1000+
--Act
1001+
l_actual := ut3_develop.ut_annotation_parser.parse_object_annotations(l_source, 'PACKAGE');
1002+
1003+
--Assert
1004+
l_expected := ut3_develop.ut_annotations(
1005+
ut3_develop.ut_annotation( 2, 'suite', null, null )
1006+
);
1007+
1008+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
1009+
end;
1010+
1011+
procedure test_space_between_dashes_and_qualifier_lines is
1012+
l_source dbms_preprocessor.source_lines_t;
1013+
l_actual ut3_develop.ut_annotations;
1014+
l_expected ut3_develop.ut_annotations;
1015+
begin
1016+
--Arrange
1017+
-- spaces between -- and % are skipped and annotation is still recognised
1018+
-- annotations are not adjacent to a procedure so they are top-level
1019+
l_source := make_source(ut_varchar2_list(
1020+
'PACKAGE test_tt AS' || chr(10),
1021+
' -- %suite' || chr(10), -- multiple spaces between -- and %
1022+
' -- %displayname(my suite)' || chr(10),
1023+
'' || chr(10), -- blank line breaks association with foo
1024+
' procedure foo;' || chr(10),
1025+
' END;' || chr(10)
1026+
));
1027+
1028+
--Act
1029+
l_actual := ut3_develop.ut_annotation_parser.parse_object_annotations(l_source, 'PACKAGE');
1030+
1031+
--Assert
1032+
l_expected := ut3_develop.ut_annotations(
1033+
ut3_develop.ut_annotation( 2, 'suite', null, null ),
1034+
ut3_develop.ut_annotation( 3, 'displayname', 'my suite', null )
1035+
);
1036+
1037+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
1038+
end;
1039+
1040+
procedure test_percent_not_after_dashes_ignored_lines is
1041+
l_source dbms_preprocessor.source_lines_t;
1042+
l_actual ut3_develop.ut_annotations;
1043+
l_expected ut3_develop.ut_annotations;
1044+
begin
1045+
--Arrange
1046+
-- -- present and % present on line but % is not immediately after --
1047+
-- e.g. a regular comment that happens to mention 100%
1048+
l_source := make_source(ut_varchar2_list(
1049+
'PACKAGE test_tt AS' || chr(10),
1050+
' -- %suite' || chr(10),
1051+
' -- coverage is 100% on this module' || chr(10), -- % after text, not annotation
1052+
' procedure foo;' || chr(10),
1053+
' END;' || chr(10)
1054+
));
1055+
1056+
--Act
1057+
l_actual := ut3_develop.ut_annotation_parser.parse_object_annotations(l_source, 'PACKAGE');
1058+
1059+
--Assert
1060+
l_expected := ut3_develop.ut_annotations(
1061+
ut3_develop.ut_annotation( 2, 'suite', null, null )
1062+
);
1063+
1064+
ut.expect(anydata.convertCollection(l_actual)).to_equal(anydata.convertCollection(l_expected));
1065+
end;
1066+
9221067
end test_annotation_parser;
9231068
/

test/ut3_tester/core/annotations/test_annotation_parser.pks

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,16 @@ create or replace package test_annotation_parser is
7373
procedure test_windows_newline_lines;
7474
--%test(parse annotations with very long procedure name using source lines overload)
7575
procedure test_annot_very_long_name_lines;
76-
76+
--%test(Procedure header spanning multiple lines is handled correctly)
77+
procedure test_multiline_proc_header_lines;
78+
--%test(Non-comment line between annotation and procedure resets association)
79+
procedure test_non_comment_line_resets_block_lines;
80+
--%test(Comment with non-whitespace before dashes is not treated as annotation)
81+
procedure test_annotation_not_at_line_start_ignored_lines;
82+
--%test(Spaces between dashes and annotation qualifier are skipped correctly)
83+
procedure test_space_between_dashes_and_qualifier_lines;
84+
--%test(Percent sign not immediately after dashes is not treated as annotation)
85+
procedure test_percent_not_after_dashes_ignored_lines;
7786

7887
end test_annotation_parser;
7988
/

0 commit comments

Comments
 (0)