Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit afd60a9

Browse files
Merge pull request #174 from Trivadis/feature/issue-118-extend-plsql-test-cases
Feature/issue 118 extend plsql test cases to cover all PL/SQL language elements
2 parents a7689ca + 8791ba6 commit afd60a9

24 files changed

+1759
-9
lines changed

settings/sql_developer/trivadis_custom_format.arbori

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,12 @@ a5_star_star:
11971197
& [node-1) '*'
11981198
;
11991199

1200+
a5_pragma_references_args:
1201+
[node) pragma_args
1202+
& [node^) pragma
1203+
& ?node-1 = 'restrict_references'
1204+
;
1205+
12001206
a5_no_space_before:
12011207
a5_semicolon
12021208
| a5_dot
@@ -1215,6 +1221,7 @@ a5_no_space_before:
12151221
| a5_brackets
12161222
| a5_indicator_variable
12171223
| a5_star_star
1224+
| a5_pragma_references_args
12181225
-> {
12191226
var node = tuple.get("node");
12201227
var content = target.src.get(node.from).content;
@@ -1387,6 +1394,22 @@ a7_for:
13871394
& [node^) sql_stmt
13881395
;
13891396

1397+
a7_collect:
1398+
[node) 'COLLECT'
1399+
& [node^) BULK_COLLECT_opt
1400+
;
1401+
1402+
a7_sharing:
1403+
[node) '=' & [node-1) 'SHARING' & ([node+1) 'METADATA' | [node+1) 'NONE')
1404+
| [node) 'METADATA' & [node-1) '=' & [node-2) 'SHARING'
1405+
| [node) 'NONE' & [node-1) '=' & [node-2) 'SHARING'
1406+
;
1407+
1408+
a7_update_set_clause_expr:
1409+
[node) '=' & [node-1) identifier & [node^) update_set_clause_expr
1410+
| [node-1) '=' & [node-2) identifier & [node^) update_set_clause_expr
1411+
;
1412+
13901413
a7_one_space_before:
13911414
a7_param_list
13921415
| a7_as_alias
@@ -1406,6 +1429,9 @@ a7_one_space_before:
14061429
| a7_reverse_loop
14071430
| a7_in_out_mode
14081431
| a7_for
1432+
| a7_collect
1433+
| a7_sharing
1434+
| a7_update_set_clause_expr
14091435
-> {
14101436
var node = tuple.get("node");
14111437
if (!hasCommentsBetweenPos(node.from, node.to)) {
@@ -1573,6 +1599,33 @@ a8_using:
15731599
& [node-1) subprg_spec
15741600
;
15751601

1602+
a8_raise:
1603+
[node) 'RAISE'
1604+
& [node^) raise_stmt
1605+
& [node+1) identifier
1606+
;
1607+
1608+
a8_return_stmt:
1609+
[node) 'RETURN'
1610+
& [node^) return_stmt
1611+
& [node+1) pls_expr
1612+
;
1613+
1614+
a8_returning:
1615+
[node) 'RETURNING'
1616+
& [node^) returning_clause
1617+
;
1618+
1619+
a8_update_set_clause:
1620+
[node) 'SET'
1621+
& [node^) update_set_clause
1622+
;
1623+
1624+
a8_while:
1625+
[node) 'WHILE'
1626+
& [node^) iteration_scheme
1627+
;
1628+
15761629
a8_one_space_after:
15771630
a8_if
15781631
| a8_end
@@ -1600,6 +1653,11 @@ a8_one_space_after:
16001653
| a8_aggregate
16011654
| a8_polymorphic
16021655
| a8_using
1656+
| a8_raise
1657+
| a8_return_stmt
1658+
| a8_returning
1659+
| a8_update_set_clause
1660+
| a8_while
16031661
-> {
16041662
var node = tuple.get("node");
16051663
if (!hasCommentsBetweenPos(node.from, node.to)) {
@@ -1621,7 +1679,6 @@ a17_whitespace_around_node:
16211679
| [node) 'OR'
16221680
| [node) 'RETURN' & [node-1) fml_part
16231681
| [node) is_or_as
1624-
16251682
-> {
16261683
var node = tuple.get("node");
16271684
if (getIndent(node.from).length == 0) {
@@ -3190,6 +3247,7 @@ r7_delete:
31903247
| [keyword) 'WHERE'
31913248
| [keyword) 'RETURN'
31923249
| [keyword) 'RETURNING'
3250+
| [keyword) 'BULK'
31933251
| [keyword) 'INTO'
31943252
| [keyword) 'LOG'
31953253
| [keyword) 'REJECT'

tests/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Fetch_statement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ public void bulk_collect() throws IOException {
6565
begin
6666
open c1;
6767
fetch c1
68-
bulk
69-
collect into a,
70-
b,
71-
c
68+
bulk collect into a,
69+
b,
70+
c
7271
limit 10;
7372
close c1;
7473
end;

tests/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Function_declaration_and_definition.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ create function f(
9797
result_cache relies_on (emp, dept, bonus)
9898
is
9999
begin
100-
return
101-
to_char(p);
100+
return to_char(p);
102101
end;
103102
/
104103
""";
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.trivadis.plsql.formatter.settings.tests.grammar.plsql;
2+
3+
import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter;
4+
import oracle.dbtools.app.Format;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.IOException;
9+
10+
public class Qualified_expression extends ConfiguredTestFormatter {
11+
12+
@BeforeEach
13+
public void setup() {
14+
getFormatter().options.put(getFormatter().idCase, Format.Case.lower);
15+
}
16+
17+
@Test
18+
public void example_6_11() throws IOException {
19+
// Assigning Values to Associative Array Type Variables Using Qualified Expressions
20+
var input = """
21+
DECLARE
22+
TYPE t_aa IS TABLE OF BOOLEAN INDEX BY PLS_INTEGER;
23+
v_aa1 t_aa := t_aa(1=>FALSE,
24+
2=>TRUE,
25+
3=>NULL);
26+
BEGIN
27+
DBMS_OUTPUT.PUT_LINE(print_bool(v_aa1(1)));
28+
DBMS_OUTPUT.PUT_LINE(print_bool(v_aa1(2)));
29+
DBMS_OUTPUT.PUT_LINE(print_bool(v_aa1(3)));
30+
END;
31+
""";
32+
var actual = formatter.format(input);
33+
var expected = """
34+
declare
35+
type t_aa is table of boolean index by pls_integer;
36+
v_aa1 t_aa := t_aa(1 => false,
37+
2 => true,
38+
3 => null);
39+
begin
40+
dbms_output.put_line(print_bool(v_aa1(1)));
41+
dbms_output.put_line(print_bool(v_aa1(2)));
42+
dbms_output.put_line(print_bool(v_aa1(3)));
43+
end;
44+
""";
45+
assertEquals(expected, actual);
46+
}
47+
48+
@Test
49+
public void example_6_8() throws IOException {
50+
// Iterator Choice Association in Qualified Expressions
51+
var input = """
52+
BEGIN
53+
result := vec_t (FOR i IN 1..n => fib(i));
54+
result := vec_t (FOR i IN 1..n => 2*i);
55+
END;
56+
""";
57+
var actual = formatter.format(input);
58+
var expected = """
59+
begin
60+
result := vec_t(for i in 1..n => fib(i));
61+
result := vec_t(for i in 1..n => 2 * i);
62+
end;
63+
""";
64+
assertEquals(expected, actual);
65+
}
66+
67+
@Test
68+
public void example_6_9() throws IOException {
69+
// Index Iterator Choice Association in Qualified Expressions
70+
var input = """
71+
BEGIN
72+
result := vec_t (FOR I,j IN PAIRS OF vec INDEX I => j+n);
73+
result := vec_t (FOR i IN 2..n BY 2 INDEX i/2 => i);
74+
END;
75+
""";
76+
var actual = formatter.format(input);
77+
var expected = """
78+
begin
79+
result := vec_t(for i, j in pairs of vec index i => j + n);
80+
result := vec_t(for i in 2..n by 2 index i / 2 => i);
81+
end;
82+
""";
83+
assertEquals(expected, actual);
84+
}
85+
86+
@Test
87+
public void example_6_10() throws IOException {
88+
// Index Iterator Choice Association in Qualified Expressions
89+
var input = """
90+
BEGIN
91+
result := vec_t (FOR v IN VALUES OF v1,
92+
REVERSE VALUES OF v2
93+
SEQUENCE => v);
94+
result := vec_t (FOR i IN 1..n WHEN is_prime(i)
95+
SEQUENCE => i);
96+
END;
97+
""";
98+
var actual = formatter.format(input);
99+
var expected = """
100+
begin
101+
result := vec_t(for v in values of v1, reverse values of v2 sequence => v);
102+
result := vec_t(for i in 1..n when is_prime(i) sequence => i);
103+
end;
104+
""";
105+
assertEquals(expected, actual);
106+
}
107+
108+
@Test
109+
public void example_5_26() throws IOException {
110+
// Using Dynamic SQL As An Iteration Control In a Qualified Expression
111+
var input = """
112+
v := vec_rec_t( FOR r rec_t IN (EXECUTE IMMEDIATE query_var) SEQUENCE => r);
113+
""";
114+
var actual = formatter.format(input);
115+
var expected = """
116+
v := vec_rec_t(for r rec_t in (execute immediate query_var) sequence => r);
117+
""";
118+
assertEquals(expected, actual);
119+
}
120+
121+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.trivadis.plsql.formatter.settings.tests.grammar.plsql;
2+
3+
import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter;
4+
import oracle.dbtools.app.Format;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.IOException;
9+
10+
public class Raise_statement extends ConfiguredTestFormatter {
11+
12+
@BeforeEach
13+
public void setup() {
14+
getFormatter().options.put(getFormatter().idCase, Format.Case.lower);
15+
}
16+
17+
@Test
18+
public void tokenized_raise_exception() throws IOException {
19+
var input = """
20+
begin
21+
raise
22+
my_exception
23+
;
24+
end
25+
;
26+
""";
27+
var actual = formatter.format(input);
28+
var expected = """
29+
begin
30+
raise my_exception;
31+
end;
32+
""";
33+
assertEquals(expected, actual);
34+
}
35+
36+
@Test
37+
public void tokenized_raise() throws IOException {
38+
var input = """
39+
begin
40+
raise
41+
;
42+
end
43+
;
44+
""";
45+
var actual = formatter.format(input);
46+
var expected = """
47+
begin
48+
raise;
49+
end;
50+
""";
51+
assertEquals(expected, actual);
52+
}
53+
}

0 commit comments

Comments
 (0)