Skip to content

Commit 20e3177

Browse files
committed
Changing to use Dijkstra algorithm to parse infix notation into postfix ( Reverse Polish Notation).
This allows us to more flexibility of using boolean expressions and not limited to flaky regex.
1 parent 0d3cfa1 commit 20e3177

File tree

8 files changed

+363
-20
lines changed

8 files changed

+363
-20
lines changed

source/api/ut_runner.pkb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ create or replace package body ut_runner is
9595
ut_event_manager.trigger_event(ut_event_manager.gc_initialize);
9696
ut_event_manager.trigger_event(ut_event_manager.gc_debug, ut_run_info());
9797

98-
if ut_utils.valid_tag_expression(l_tags) = 0 then
99-
raise_application_error(ut_utils.gc_invalid_tag_expression, 'Invalid Tag expression');
100-
end if;
101-
10298
if a_random_test_order_seed is not null then
10399
l_random_test_order_seed := a_random_test_order_seed;
104100
elsif a_random_test_order then

source/core/types/ut_stack.tpb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
create or replace type body ut_stack as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
constructor function ut_stack( self in out nocopy ut_stack) return self as result is
20+
begin
21+
self.tokens := ut_varchar2_list();
22+
self.top := 0;
23+
return;
24+
end ut_stack;
25+
26+
member function peek(self in out nocopy ut_stack) return varchar2 is
27+
l_token varchar2(32767);
28+
begin
29+
if self.tokens.count =0 or self.tokens is null then
30+
l_token := null;
31+
else
32+
l_token := self.tokens(self.tokens.last);
33+
end if;
34+
return l_token;
35+
end;
36+
37+
member procedure push(self in out nocopy ut_stack, a_token varchar2) is
38+
begin
39+
self.tokens.extend;
40+
self.tokens(self.tokens.last) := a_token;
41+
self.top := self.tokens.count;
42+
end push;
43+
44+
member procedure pop(self in out nocopy ut_stack,a_cnt in integer default 1) is
45+
begin
46+
self.tokens.trim(a_cnt);
47+
self.top := self.tokens.count;
48+
end pop;
49+
50+
member function pop(self in out nocopy ut_stack) return varchar2 is
51+
l_token varchar2(32767) := self.tokens(self.tokens.last);
52+
begin
53+
self.pop();
54+
return l_token;
55+
end;
56+
end;
57+
/
58+

source/core/types/ut_stack.tps

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
create or replace type ut_stack as object (
2+
top integer,
3+
tokens ut_varchar2_list,
4+
/*
5+
utPLSQL - Version 3
6+
Copyright 2016 - 2021 utPLSQL Project
7+
8+
Licensed under the Apache License, Version 2.0 (the "License"):
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
constructor function ut_stack( self in out nocopy ut_stack) return self as result,
21+
member function peek(self in out nocopy ut_stack) return varchar2,
22+
member procedure push(self in out nocopy ut_stack, a_token varchar2),
23+
member procedure pop(self in out nocopy ut_stack,a_cnt in integer default 1),
24+
member function pop(self in out nocopy ut_stack) return varchar2
25+
)
26+

source/core/ut_suite_cache_manager.pkb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ create or replace package body ut_suite_cache_manager is
234234
function replace_legacy_tag_notation(a_tags varchar2
235235
) return varchar2 is
236236
l_tags ut_varchar2_list := ut_utils.string_to_table(a_tags,',');
237-
l_tags_include varchar2(2000);
238-
l_tags_exclude varchar2(2000);
237+
l_tags_include varchar2(4000);
238+
l_tags_exclude varchar2(4000);
239239
l_return_tag varchar2(4000);
240240
begin
241-
select listagg( t.column_value,' | ')
241+
select listagg( t.column_value,'|')
242242
within group( order by column_value)
243243
into l_tags_include
244244
from table(l_tags) t
@@ -268,15 +268,14 @@ create or replace package body ut_suite_cache_manager is
268268
if instr(l_tags,',') > 0 or instr(l_tags,'-') > 0 then
269269
l_tags := replace(replace_legacy_tag_notation(l_tags),' ');
270270
end if;
271-
l_tags := REGEXP_REPLACE(l_tags,
272-
'(\(|\)|\||\!|\&)?([^|&!-()]+)(\(|\)|\||\!|\&)?',
273-
q'[\1q'<\2>' member of tags\3]');
274-
--replace operands to XPath
271+
l_tags := ut_utils.convert_postfix_to_infix_where_sql(ut_utils.shunt_logical_expression(l_tags));
275272
l_tags := REPLACE(l_tags, '|',' or ');
276-
l_tags := REPLACE(l_tags , '&',' and ');
277-
l_tags := REGEXP_REPLACE(l_tags,q'[(\!)(q'<[^|&!]+?>')( member of tags)]','\2 not \3');
278-
l_tags := '('||l_tags||')';
279-
return l_tags;
273+
l_tags := REPLACE(l_tags ,'&',' and ');
274+
l_tags := REPLACE(l_tags ,'!','not');
275+
return l_tags;
276+
exception
277+
when ut_utils.ex_invalid_tag_expression then
278+
raise_application_error(ut_utils.gc_invalid_tag_expression, 'Invalid Tag expression');
280279
end;
281280

282281
/*

0 commit comments

Comments
 (0)