Skip to content

Commit bf6959f

Browse files
committed
Update tests and code
1 parent 3d77514 commit bf6959f

File tree

5 files changed

+62
-22
lines changed

5 files changed

+62
-22
lines changed

source/core/ut_utils.pkb

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,24 +1000,30 @@ create or replace package body ut_utils is
10001000
return l_result;
10011001
end;
10021002

1003+
function tokenize_tags_string(a_tags in varchar2) return ut_varchar2_list is
1004+
l_tags_tokens ut_varchar2_list := ut_varchar2_list();
1005+
begin
1006+
--Tokenize a string into operators and tags
1007+
select regexp_substr(a_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
1008+
bulk collect into l_tags_tokens
1009+
from dual connect by regexp_substr (a_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
1010+
1011+
return l_tags_tokens;
1012+
end;
1013+
10031014
/*
10041015
https://stackoverflow.com/questions/29634992/shunting-yard-validate-expression
10051016
*/
10061017
function shunt_logical_expression(a_tags in varchar2) return ut_varchar2_list is
10071018
l_tags varchar2(32767) := a_tags;
10081019
l_operator_stack ut_stack := ut_stack();
1009-
l_input_tokens ut_varchar2_list := ut_varchar2_list();
1020+
l_input_tokens ut_varchar2_list := tokenize_tags_string(a_tags);
10101021
l_rnp_tokens ut_varchar2_list := ut_varchar2_list();
10111022
l_token varchar2(32767);
10121023
l_expect_operand boolean := true;
10131024
l_expect_operator boolean := false;
10141025
l_idx pls_integer;
10151026
begin
1016-
--Tokenize a string into operators and tags
1017-
select regexp_substr(l_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
1018-
bulk collect into l_input_tokens
1019-
from dual connect by regexp_substr (l_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
1020-
10211027
l_idx := l_input_tokens.first;
10221028
--Exuecute modified shunting algorithm
10231029
WHILE (l_idx is not null) loop
@@ -1071,7 +1077,7 @@ create or replace package body ut_utils is
10711077
l_idx := l_input_tokens.next(l_idx);
10721078
end loop;
10731079

1074-
while l_operator_stack.top > 0 loop
1080+
while l_operator_stack.peek is not null loop
10751081
if l_operator_stack.peek in ('(',')') then
10761082
raise ex_invalid_tag_expression;
10771083
end if;
@@ -1082,12 +1088,6 @@ create or replace package body ut_utils is
10821088
return l_rnp_tokens;
10831089
end shunt_logical_expression;
10841090

1085-
procedure shunt_logical_expression(a_tags in varchar2) is
1086-
a_postfix ut_varchar2_list;
1087-
begin
1088-
a_postfix := ut_utils.shunt_logical_expression(a_tags);
1089-
end shunt_logical_expression;
1090-
10911091
function convert_postfix_to_infix(a_postfix_exp in ut_varchar2_list)
10921092
return varchar2 is
10931093
l_infix_stack ut_stack := ut_stack();
@@ -1112,8 +1112,6 @@ create or replace package body ut_utils is
11121112
l_left_side := l_infix_stack.pop;
11131113
l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11141114
l_infix_stack.push(l_infix_exp);
1115-
else
1116-
null;
11171115
end if;
11181116
l_idx := a_postfix_exp.next(l_idx);
11191117
end loop;
@@ -1149,8 +1147,6 @@ create or replace package body ut_utils is
11491147
l_left_side := l_infix_stack.pop;
11501148
l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11511149
l_infix_stack.push(l_infix_exp);
1152-
else
1153-
null;
11541150
end if;
11551151
l_idx := a_postfix_exp.next(l_idx);
11561152
end loop;

source/core/ut_utils.pks

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ create or replace package ut_utils authid definer is
476476
* Return value of interval in plain english
477477
*/
478478
function interval_to_text(a_interval yminterval_unconstrained) return varchar2;
479+
480+
/*
481+
* Return table of tokens character by character
482+
*/
483+
function tokenize_tags_string(a_tags in varchar2) return ut_varchar2_list;
479484

480485
/*
481486
* Function that uses Dijkstra algorithm to parse mathematical and logical expression
@@ -484,8 +489,6 @@ create or replace package ut_utils authid definer is
484489
*/
485490
function shunt_logical_expression(a_tags in varchar2) return ut_varchar2_list;
486491

487-
procedure shunt_logical_expression(a_tags in varchar2);
488-
489492
/*
490493
* Function that converts postfix notation into infix
491494
*/

test/ut3_tester/core/test_ut_utils.pkb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,11 @@ end;
504504

505505
l_postfix := ut3_develop.ut_utils.shunt_logical_expression('(a|b)|c&d');
506506
l_postfix_string := ut3_develop.ut_utils.table_to_clob(l_postfix,'');
507-
ut.expect(l_postfix_string).to_equal('ab|cd&|');
507+
ut.expect(l_postfix_string).to_equal('ab|cd&|');
508+
509+
l_postfix := ut3_develop.ut_utils.shunt_logical_expression('!a|b');
510+
l_postfix_string := ut3_develop.ut_utils.table_to_clob(l_postfix,'');
511+
ut.expect(l_postfix_string).to_equal('a!b|');
508512
end;
509513

510514
procedure test_conv_from_rpn_to_infix is
@@ -521,7 +525,28 @@ end;
521525

522526
l_postfix_rpn := ut3_develop.ut_varchar2_list('a','b','|','c','d','&','|');
523527
l_infix_string := ut3_develop.ut_utils.convert_postfix_to_infix(l_postfix_rpn);
524-
ut.expect(l_infix_string).to_equal('((a|b)|(c&d))');
528+
ut.expect(l_infix_string).to_equal('((a|b)|(c&d))');
529+
530+
l_postfix_rpn := ut3_develop.ut_varchar2_list('a','b','!','|');
531+
l_infix_string := ut3_develop.ut_utils.convert_postfix_to_infix(l_postfix_rpn);
532+
ut.expect(l_infix_string).to_equal('(a|(!b))');
533+
end;
534+
535+
procedure conv_from_rpn_to_sql_filter is
536+
l_postfix_rpn ut3_develop.ut_varchar2_list;
537+
l_infix_string varchar2(4000);
538+
begin
539+
l_postfix_rpn := ut3_develop.ut_varchar2_list('A');
540+
l_infix_string := ut3_develop.ut_utils.conv_postfix_to_infix_sql(l_postfix_rpn);
541+
ut.expect(l_infix_string).to_equal(q'['A' member of tags]');
542+
543+
l_postfix_rpn := ut3_develop.ut_varchar2_list('A','B','|');
544+
l_infix_string := ut3_develop.ut_utils.conv_postfix_to_infix_sql(l_postfix_rpn);
545+
ut.expect(l_infix_string).to_equal(q'[('A' member of tags|'B' member of tags)]');
546+
547+
l_postfix_rpn := ut3_develop.ut_varchar2_list('a','b','!','|');
548+
l_infix_string := ut3_develop.ut_utils.conv_postfix_to_infix_sql(l_postfix_rpn);
549+
ut.expect(l_infix_string).to_equal(q'[('a' member of tags|!('b' member of tags))]');
525550
end;
526551

527552
end test_ut_utils;

test/ut3_tester/core/test_ut_utils.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,8 @@ create or replace package test_ut_utils is
163163
--%test( Test conversion of expression from Reverse Polish Notation into infix)
164164
procedure test_conv_from_rpn_to_infix;
165165

166+
--%test( Test conversion of expression from Reverse Polish Notation into custom where filter for SQL)
167+
procedure conv_from_rpn_to_sql_filter;
168+
166169
end test_ut_utils;
167170
/

test/ut3_user/api/test_ut_run.pkb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,20 @@ procedure tag_exclude_run_fun_pth_lst_lg is
12601260

12611261
l_results := ut3_tester_helper.run_helper.run(a_tags => '(!development&end_to_end|)');
12621262
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).to_match('^\s*invalid_tag_expression \[[,\.0-9]+ sec\]\s*$','m');
1263-
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).not_to_be_like('%(FAILED -%');
1263+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).not_to_be_like('%(FAILED -%');
1264+
1265+
l_results := ut3_tester_helper.run_helper.run(a_tags => '(!development&!!end_to_end)');
1266+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).to_match('^\s*invalid_tag_expression \[[,\.0-9]+ sec\]\s*$','m');
1267+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).not_to_be_like('%(FAILED -%');
1268+
1269+
l_results := ut3_tester_helper.run_helper.run(a_tags => '(&development&end_to_end)');
1270+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).to_match('^\s*invalid_tag_expression \[[,\.0-9]+ sec\]\s*$','m');
1271+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).not_to_be_like('%(FAILED -%');
1272+
1273+
l_results := ut3_tester_helper.run_helper.run(a_tags => '(development|end_to_end))');
1274+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).to_match('^\s*invalid_tag_expression \[[,\.0-9]+ sec\]\s*$','m');
1275+
ut.expect( ut3_tester_helper.main_helper.table_to_clob(l_results) ).not_to_be_like('%(FAILED -%');
1276+
12641277
end;
12651278

12661279
procedure set_application_info is

0 commit comments

Comments
 (0)