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

Skip to content

Commit 436eb5b

Browse files
committed
Addressing test failures and sonar smells
1 parent cbdf83a commit 436eb5b

3 files changed

Lines changed: 71 additions & 21 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,17 @@ create or replace package body ut_utils is
10111011
l_token varchar2(32767);
10121012
l_expect_operand boolean := true;
10131013
l_expect_operator boolean := false;
1014+
l_idx pls_integer;
10141015
begin
10151016
--Tokenize a string into operators and tags
10161017
select regexp_substr(l_tags,'([^!()|&]+)|([!()|&])', 1, level) as string_parts
10171018
bulk collect into l_input_tokens
10181019
from dual connect by regexp_substr (l_tags, '([^!()|&]+)|([!()|&])', 1, level) is not null;
10191020

1021+
l_idx := l_input_tokens.first;
10201022
--Exuecute modified shunting algorithm
1021-
for token in 1..l_input_tokens.count loop
1022-
l_token := l_input_tokens(token);
1023+
WHILE (l_idx is not null) loop
1024+
l_token := l_input_tokens(l_idx);
10231025
if (l_token member of gc_operators and l_token member of gc_binary_operator) then
10241026
if not(l_expect_operator) then
10251027
raise ex_invalid_tag_expression;
@@ -1028,21 +1030,21 @@ create or replace package body ut_utils is
10281030
l_rnp_tokens.extend;
10291031
l_rnp_tokens(l_rnp_tokens.last) := l_operator_stack.pop;
10301032
end loop;
1031-
l_operator_stack.push(l_input_tokens(token));
1033+
l_operator_stack.push(l_input_tokens(l_idx));
10321034
l_expect_operand := true;
10331035
l_expect_operator:= false;
10341036
elsif (l_token member of gc_operators and l_token member of gc_unary_operator) then
10351037
if not(l_expect_operand) then
10361038
raise ex_invalid_tag_expression;
10371039
end if;
1038-
l_operator_stack.push(l_input_tokens(token));
1040+
l_operator_stack.push(l_input_tokens(l_idx));
10391041
l_expect_operand := true;
10401042
l_expect_operator:= false;
10411043
elsif l_token = '(' then
10421044
if not(l_expect_operand) then
10431045
raise ex_invalid_tag_expression;
10441046
end if;
1045-
l_operator_stack.push(l_input_tokens(token));
1047+
l_operator_stack.push(l_input_tokens(l_idx));
10461048
l_expect_operand := true;
10471049
l_expect_operator:= false;
10481050
elsif l_token = ')' then
@@ -1066,6 +1068,7 @@ create or replace package body ut_utils is
10661068
l_expect_operand := false;
10671069
end if;
10681070

1071+
l_idx := l_input_tokens.next(l_idx);
10691072
end loop;
10701073

10711074
while l_operator_stack.top > 0 loop
@@ -1091,25 +1094,28 @@ create or replace package body ut_utils is
10911094
l_right_side varchar2(32767);
10921095
l_left_side varchar2(32767);
10931096
l_infix_exp varchar2(32767);
1097+
l_idx pls_integer;
10941098
begin
1095-
for i in 1..a_postfix_exp.count loop
1099+
l_idx := a_postfix_exp.first;
1100+
while (l_idx is not null) loop
10961101
--If token is operand but also single tag
1097-
if a_postfix_exp(i) not member of gc_operators then --its operand
1098-
l_infix_stack.push(a_postfix_exp(i));
1102+
if a_postfix_exp(l_idx) not member of gc_operators then --its operand
1103+
l_infix_stack.push(a_postfix_exp(l_idx));
10991104
--If token is unary operator not
1100-
elsif a_postfix_exp(i) member of gc_unary_operator then
1105+
elsif a_postfix_exp(l_idx) member of gc_unary_operator then
11011106
l_right_side := l_infix_stack.pop;
1102-
l_infix_exp := '('||a_postfix_exp(i)||l_right_side||')';
1107+
l_infix_exp := '('||a_postfix_exp(l_idx)||l_right_side||')';
11031108
l_infix_stack.push(l_infix_exp);
11041109
--If token is binary operator
1105-
elsif a_postfix_exp(i) member of gc_binary_operator then
1110+
elsif a_postfix_exp(l_idx) member of gc_binary_operator then
11061111
l_right_side := l_infix_stack.pop;
11071112
l_left_side := l_infix_stack.pop;
1108-
l_infix_exp := '('||l_left_side||a_postfix_exp(i)||l_right_side||')';
1113+
l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11091114
l_infix_stack.push(l_infix_exp);
11101115
else
11111116
null;
11121117
end if;
1118+
l_idx := a_postfix_exp.next(l_idx);
11131119
end loop;
11141120

11151121
return l_infix_stack.pop;
@@ -1122,28 +1128,31 @@ create or replace package body ut_utils is
11221128
l_left_side varchar2(32767);
11231129
l_infix_exp varchar2(32767);
11241130
l_member_token varchar2(20) := ' member of tags';
1131+
l_idx pls_integer;
11251132
begin
1126-
for i in 1..a_postfix_exp.count loop
1133+
l_idx := a_postfix_exp.first;
1134+
while ( l_idx is not null) loop
11271135
--If token is operand but also single tag
1128-
if regexp_count(a_postfix_exp(i),'[!()|&]') = 0 then
1129-
l_infix_stack.push(q'[']'||a_postfix_exp(i)||q'[']'||l_member_token);
1136+
if regexp_count(a_postfix_exp(l_idx),'[!()|&]') = 0 then
1137+
l_infix_stack.push(q'[']'||a_postfix_exp(l_idx)||q'[']'||l_member_token);
11301138
--If token is operand but containing other expressions
1131-
elsif a_postfix_exp(i) not member of gc_operators then
1132-
l_infix_stack.push(a_postfix_exp(i));
1139+
elsif a_postfix_exp(l_idx) not member of gc_operators then
1140+
l_infix_stack.push(a_postfix_exp(l_idx));
11331141
--If token is unary operator not
1134-
elsif a_postfix_exp(i) member of gc_unary_operator then
1142+
elsif a_postfix_exp(l_idx) member of gc_unary_operator then
11351143
l_right_side := l_infix_stack.pop;
1136-
l_infix_exp := a_postfix_exp(i)||'('||l_right_side||')';
1144+
l_infix_exp := a_postfix_exp(l_idx)||'('||l_right_side||')';
11371145
l_infix_stack.push(l_infix_exp);
11381146
--If token is binary operator
1139-
elsif a_postfix_exp(i) member of gc_binary_operator then
1147+
elsif a_postfix_exp(l_idx) member of gc_binary_operator then
11401148
l_right_side := l_infix_stack.pop;
11411149
l_left_side := l_infix_stack.pop;
1142-
l_infix_exp := '('||l_left_side||a_postfix_exp(i)||l_right_side||')';
1150+
l_infix_exp := '('||l_left_side||a_postfix_exp(l_idx)||l_right_side||')';
11431151
l_infix_stack.push(l_infix_exp);
11441152
else
11451153
null;
11461154
end if;
1155+
l_idx := a_postfix_exp.next(l_idx);
11471156
end loop;
11481157

11491158
return l_infix_stack.pop;

test/ut3_tester/core/test_ut_utils.pkb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,40 @@ end;
489489
ut.expect(l_expected).to_equal(l_actual);
490490
end;
491491

492+
493+
procedure test_conversion_to_rpn is
494+
l_postfix ut3_develop.ut_varchar2_list;
495+
l_postfix_string varchar2(4000);
496+
begin
497+
l_postfix := ut3_develop.ut_utils.shunt_logical_expression('A');
498+
l_postfix_string := ut3_develop.ut_utils.table_to_clob(l_postfix,'');
499+
ut.expect(l_postfix_string).to_equal('A');
500+
501+
l_postfix := ut3_develop.ut_utils.shunt_logical_expression('A|B');
502+
l_postfix_string := ut3_develop.ut_utils.table_to_clob(l_postfix,'');
503+
ut.expect(l_postfix_string).to_equal('AB|');
504+
505+
l_postfix := ut3_develop.ut_utils.shunt_logical_expression('(a|b)|c&d');
506+
l_postfix_string := ut3_develop.ut_utils.table_to_clob(l_postfix,'');
507+
ut.expect(l_postfix_string).to_equal('ab|cd&|');
508+
end;
509+
510+
procedure test_conversion_from_rpn_to_infix is
511+
l_postfix_rpn ut3_develop.ut_varchar2_list;
512+
l_infix_string varchar2(4000);
513+
begin
514+
l_postfix_rpn := ut3_develop.ut_varchar2_list('A');
515+
l_infix_string := ut3_develop.ut_utils.convert_postfix_to_infix(l_postfix_rpn);
516+
ut.expect(l_infix_string).to_equal('A');
517+
518+
l_postfix_rpn := ut3_develop.ut_varchar2_list('A','B','|');
519+
l_infix_string := ut3_develop.ut_utils.convert_postfix_to_infix(l_postfix_rpn);
520+
ut.expect(l_infix_string).to_equal('(A|B)');
521+
522+
l_postfix_rpn := ut3_develop.ut_varchar2_list('a','b','|','c','d','&','|');
523+
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))');
525+
end;
526+
492527
end test_ut_utils;
493528
/

test/ut3_tester/core/test_ut_utils.pks

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ create or replace package test_ut_utils is
156156

157157

158158
--%endcontext
159+
160+
--%test( Test conversion of expression into Reverse Polish Notation)
161+
procedure test_conversion_to_rpn;
162+
163+
--%test( Test conversion of expression from Reverse Polish Notation into infix)
164+
procedure test_conversion_from_rpn_to_infix;
159165

160166
end test_ut_utils;
161167
/

0 commit comments

Comments
 (0)