@@ -708,15 +708,49 @@ create or replace package body ut_suite_builder is
708708 a_context_ann_pos t_annotation_position,
709709 a_package_annotations in out nocopy tt_annotations_by_name
710710 ) return t_annotation_position is
711- l_result t_annotation_position;
711+ l_next_endcontext_pos t_annotation_position;
712+ l_next_context_pos t_annotation_position;
713+ l_open_count integer := 0;
712714 begin
713715 if a_package_annotations.exists(gc_endcontext) then
714- l_result := a_package_annotations(gc_endcontext).first;
715- while l_result <= a_context_ann_pos loop
716- l_result := a_package_annotations(gc_endcontext).next(l_result );
716+ l_next_endcontext_pos := a_package_annotations(gc_endcontext).first;
717+ while l_next_endcontext_pos <= a_context_ann_pos loop
718+ l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos );
717719 end loop;
720+
721+ l_next_context_pos := a_package_annotations(gc_context).next(a_context_ann_pos);
722+ loop
723+ -- Get all the %context annotations between start and first %endcontext
724+ while l_next_context_pos is not null and l_next_context_pos < l_next_endcontext_pos loop
725+ l_open_count := l_open_count+1;
726+ l_next_context_pos := a_package_annotations(gc_context).next(l_next_context_pos);
727+ end loop;
728+ -- Skip as many %endcontexts as we had additional contexts open
729+ while l_open_count > 0 loop
730+ l_open_count := l_open_count-1;
731+ l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos);
732+ end loop;
733+ -- Repeat until the next %context is later than next %endcontext
734+ exit when l_next_context_pos is null or l_next_context_pos > l_next_endcontext_pos;
735+ end loop;
718736 end if;
719- return l_result;
737+ return l_next_endcontext_pos;
738+ end;
739+
740+ function has_nested_context(
741+ a_context_ann_pos t_annotation_position,
742+ a_package_annotations in out nocopy tt_annotations_by_name
743+ ) return boolean is
744+ l_next_endcontext_pos t_annotation_position;
745+ begin
746+ if ( a_package_annotations.exists(gc_endcontext) and a_package_annotations.exists(gc_context)) then
747+ l_next_endcontext_pos := a_package_annotations(gc_endcontext).first;
748+ while l_next_endcontext_pos <= a_context_ann_pos loop
749+ l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos);
750+ end loop;
751+ return l_next_endcontext_pos > a_package_annotations(gc_context).next(a_context_ann_pos);
752+ end if;
753+ return false;
720754 end;
721755
722756 function get_annotations_in_context(
@@ -753,7 +787,8 @@ create or replace package body ut_suite_builder is
753787 a_parent in out nocopy ut_suite,
754788 a_annotations in out nocopy t_annotations_info,
755789 a_suite_items out nocopy ut_suite_items,
756- a_parent_context_pos in integer := 0
790+ a_parent_context_pos in integer := 0,
791+ a_parent_end_context_pos in integer default null
757792 ) is
758793 l_context_pos t_annotation_position;
759794 l_next_context_pos t_annotation_position;
@@ -802,7 +837,6 @@ create or replace package body ut_suite_builder is
802837 l_default_context_name := 'nested_context_#'||l_context_no;
803838 l_context_name := null;
804839 l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
805-
806840 l_next_context_pos := a_annotations.by_name(gc_context).next(l_context_pos);
807841 if a_annotations.by_name.exists(gc_name) then
808842 l_context_name :=
@@ -841,9 +875,8 @@ create or replace package body ut_suite_builder is
841875 l_context.parse_time := a_annotations.parse_time;
842876
843877 --if nested context found
844- if l_next_context_pos < l_end_context_pos or l_end_context_pos is null then
845- get_context_items( l_context, a_annotations, l_context_items, l_context_pos );
846- l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
878+ if has_nested_context(l_context_pos, a_annotations.by_name) then
879+ get_context_items( l_context, a_annotations, l_context_items, l_context_pos, l_end_context_pos );
847880 else
848881 l_context_items := ut_suite_items();
849882 end if;
@@ -870,6 +903,9 @@ create or replace package body ut_suite_builder is
870903 exit when not a_annotations.by_name.exists( gc_context);
871904
872905 l_context_pos := a_annotations.by_name( gc_context).next( l_context_pos);
906+ if ( a_parent_end_context_pos is not null and a_parent_end_context_pos <= l_context_pos ) then
907+ l_context_pos := null;
908+ end if;
873909 l_context_no := l_context_no + 1;
874910 end loop;
875911 end;
0 commit comments