Skip to content

Commit

Permalink
add test cases to reproduce #62
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippSalvisberg committed Jan 16, 2024
1 parent 443ff79 commit bf26595
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,48 @@ public void subtypeNameOk() {
var issues = getIssues(stmt);
Assert.assertEquals(0, issues.stream().filter(it -> it.getCode().equals("G-9115")).toList().size());
}

// issue 62 https://github.com/Trivadis/plsql-cop-validators/issues/62

@Test
public void ignorelocalVariableInBasicLoopExitCondition() {
var stmt = """
declare
a integer := 0; -- violates G-2185, not used in while loop condition nor exit condition, violates G-9102
b integer; -- does not violate G-2185, used in exit condition, violates G-9102
begin
<<demo>>
loop
b := a;
exit demo when b = 10;
a := a + 1;
end loop demo;
end;
/
""";
var issues = getIssues(stmt).stream().filter(it -> it.getCode().equals("G-9102")).toList();
Assert.assertEquals(1, issues.size());
Assert.assertEquals(2, issues.get(0).getLineNumber().intValue());
}

@Test
public void ignorelocalVariableInWhileLoopCondition() {
var stmt = """
declare
a pls_integer := 0;
b integer;
begin
while a < 10
loop
b := a;
dbms_output.put_line(b);
a := a + 1;
end loop;
end;
""";
var issues = getIssues(stmt).stream().filter(it -> it.getCode().equals("G-9102")).toList();
Assert.assertEquals(1, issues.size());
Assert.assertEquals(3, issues.get(0).getLineNumber().intValue());
}

}

0 comments on commit bf26595

Please sign in to comment.