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

Commit

Permalink
Merge pull request #253 from Trivadis/bugfix/issue-249-format-globals…
Browse files Browse the repository at this point in the history
…-in-package-spec

Align contants and variables in package spec
  • Loading branch information
PhilippSalvisberg authored Apr 23, 2023
2 parents 000820a + b4df3f4 commit 39ca7d9
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 2 deletions.
30 changes: 28 additions & 2 deletions settings/sql_developer/trivadis_custom_format.arbori
Original file line number Diff line number Diff line change
Expand Up @@ -3666,6 +3666,16 @@ o8_declarations:
var datatypes = new HashMap();
}

o8_package_variables:
[scope) pkg_spec
& [name) decl_id
& [parent) basic_d
& name = node-1
& scope < name^
& parent = name^
& [parent = [name
;

o8_variables:
[scope) decl_list
& [name) decl_id
Expand Down Expand Up @@ -3702,7 +3712,8 @@ o8_external_params:
;

o8_find_type_declarations:
o8_variables
o8_package_variables
| o8_variables
| o8_records
| o8_attributes
| o8_external_params
Expand Down Expand Up @@ -3746,6 +3757,20 @@ o4_declarations:
var assignmentsWithValue = new HashMap();
}

o4_package_spec:
[scope) pkg_spec
& [node) default_expr_opt
& scope < node
;

o4_function_in_package_spec:
[scope) pkg_spec
& [func) fml_part
& [node) default_expr_opt
& func < node
& scope < func
;

o4_declare_section:
[scope) decl_list
& [node) default_expr_opt
Expand All @@ -3767,7 +3792,8 @@ o4_function:
;

o4_find_assignments:
(o4_declare_section - o4_function_in_declare_section)
(o4_package_spec - o4_function_in_package_spec)
| (o4_declare_section - o4_function_in_declare_section)
| o4_function
-> {
if (alignAssignments) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.trivadis.plsql.formatter.settings.tests.issues;

import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class Issue_249_globals_in_package_spec extends ConfiguredTestFormatter {
@Test
public void constants_only() throws IOException {
var input = """
create or replace package x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
end;
/
create or replace package body x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
end;
/
""";
var expected = """
create or replace package x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
end;
/
create or replace package body x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
end;
/
""";
var actual = getFormatter().format(input);
assertEquals(expected, actual);
}

@Test
public void variables_only() throws IOException {
var input = """
create or replace package x as
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
create or replace package body x as
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
""";
var expected = """
create or replace package x as
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
create or replace package body x as
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
""";
var actual = getFormatter().format(input);
assertEquals(expected, actual);
}

@Test
public void constants_and_variables() throws IOException {
var input = """
create or replace package x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
create or replace package body x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
""";
var expected = """
create or replace package x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
create or replace package body x as
co_aaaa constant char := 'a';
co_b constant char := 'b';
co_cccccccccc constant char := 'c';
l_aaaa char := 'a';
l_b char := 'b';
l_cccccccccc char := 'c';
end;
/
""";
var actual = getFormatter().format(input);
assertEquals(expected, actual);
}
}

0 comments on commit 39ca7d9

Please sign in to comment.