├── .gitattributes ├── .gitignore ├── LICENSE.txt ├── README.md ├── hook ├── README.md └── pre-commit ├── images ├── advanced_format.png ├── change_line_breaks_on_comma.png └── custom_format.png ├── settings ├── datagrip │ └── trivadis.xml ├── plsql_developer │ └── trivadis_beautifier.br ├── sql_developer │ ├── trivadis_advanced_format.xml │ └── trivadis_custom_format.arbori └── toad │ └── trivadis_fmtplus.opt ├── sqlcl ├── README.md └── format.js └── standalone ├── README.md ├── install_sqlcl_libs.sh ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── trivadis │ │ └── plsql │ │ └── formatter │ │ ├── RuntimeReflectionRegistrationFeature.java │ │ ├── ScriptRunnerContext.java │ │ ├── TvdFormat.java │ │ └── sandbox │ │ ├── SandboxedFormatter.java │ │ └── SandboxedFormatterTask.java └── resources │ ├── META-INF │ └── native-image │ │ └── com.trivadis.plsql.formatter │ │ └── tvdformat │ │ ├── jni-config.json │ │ ├── predefined-classes-config.json │ │ ├── proxy-config-manual.json │ │ ├── proxy-config.json │ │ ├── reflect-config-manual.json │ │ ├── reflect-config.json │ │ ├── resource-config.json │ │ └── serialization-config.json │ └── format.js └── test ├── java └── com │ └── trivadis │ └── plsql │ └── formatter │ ├── settings │ ├── ConfiguredTestFormatter.java │ ├── examples │ │ ├── AllroundAutomations.java │ │ ├── Oracle.java │ │ ├── Strange.java │ │ └── Trivadis.java │ └── tests │ │ ├── grammar │ │ ├── Comment.java │ │ ├── Json_functions.java │ │ ├── Paren_expr_list.java │ │ ├── Select_list.java │ │ ├── Xml_functions.java │ │ ├── plsql │ │ │ ├── Accessible_by_clause.java │ │ │ ├── Aggregate_clause.java │ │ │ ├── Assignment_statement.java │ │ │ ├── Autonamous_transaction_pragma.java │ │ │ ├── Basic_loop_statement.java │ │ │ ├── Block.java │ │ │ ├── Call_specification.java │ │ │ ├── Case_statement.java │ │ │ ├── Close_statement.java │ │ │ ├── Collection_method_invokation.java │ │ │ ├── Collection_variable_declaration.java │ │ │ ├── Comment.java │ │ │ ├── Compile_clause.java │ │ │ ├── Constant_declaration.java │ │ │ ├── Continue_Statement.java │ │ │ ├── Coverage_pragma.java │ │ │ ├── Cursor_for_loop_statement.java │ │ │ ├── Cursor_variable_declaration.java │ │ │ ├── Datatype_attribute.java │ │ │ ├── Default_collation_clause.java │ │ │ ├── Delete_statement_extension.java │ │ │ ├── Deprecate_pragma.java │ │ │ ├── Deterministic_clause.java │ │ │ ├── Element_specification.java │ │ │ ├── Exception_declaration.java │ │ │ ├── Exception_handler.java │ │ │ ├── Exception_init_pragma.java │ │ │ ├── Execute_immediate_statement.java │ │ │ ├── Exit_statement.java │ │ │ ├── Explicit_Cursor.java │ │ │ ├── Expression.java │ │ │ ├── Fetch_statement.java │ │ │ ├── For_loop_statement.java │ │ │ ├── Forall_statement.java │ │ │ ├── Formal_parameter_declaration.java │ │ │ ├── Function_declaration_and_definition.java │ │ │ ├── Goto_statement.java │ │ │ ├── If_statement.java │ │ │ ├── Implicit_cursor_attribute.java │ │ │ ├── Inline_pragma.java │ │ │ ├── Insert_statement_extension.java │ │ │ ├── Invokers_rights_and_definers_rights_clause.java │ │ │ ├── Iterator.java │ │ │ ├── Named_cursor_attribute.java │ │ │ ├── Null_statement.java │ │ │ ├── Open_for_statement.java │ │ │ ├── Open_statement.java │ │ │ ├── Parallel_enable_clause.java │ │ │ ├── Pipe_row_statement.java │ │ │ ├── Pipelined_clause.java │ │ │ ├── Procedure_declaration_and_definition.java │ │ │ ├── Qualified_expression.java │ │ │ ├── Raise_statement.java │ │ │ ├── Record_variable_declaration.java │ │ │ ├── Restrict_references_pragma.java │ │ │ ├── Result_cache_clause.java │ │ │ ├── Return_statement.java │ │ │ ├── Returning_into_clause.java │ │ │ ├── Rowtype_attribute.java │ │ │ ├── Scalar_variable_declaration.java │ │ │ ├── Select_into_statement.java │ │ │ ├── Serially_reusable_pragma.java │ │ │ ├── Sharing_clause.java │ │ │ ├── Sql_macro_clause.java │ │ │ ├── Sqlcode_function.java │ │ │ ├── Sqlerrm_function.java │ │ │ ├── Suppresses_warning_6009_pragma.java │ │ │ ├── Type_attribute.java │ │ │ ├── Udf_pragma.java │ │ │ ├── Update_statement_extensions.java │ │ │ └── While_loop_statement.java │ │ └── sql │ │ │ └── Create_materialized_view.java │ │ ├── issues │ │ ├── Issue_114_honor_no_space_after_commas_config.java │ │ ├── Issue_126_create_view_column_list.java │ │ ├── Issue_129_in_out_parameter.java │ │ ├── Issue_133_wrong_ws_removal.java │ │ ├── Issue_139_xmltable.java │ │ ├── Issue_13_do_not_right_align_set.java │ │ ├── Issue_149_spool.java │ │ ├── Issue_150_define.java │ │ ├── Issue_152_extract.java │ │ ├── Issue_158_indent_collection_item.java │ │ ├── Issue_167_leading_commas_and_comments.java │ │ ├── Issue_186_with_clause.java │ │ ├── Issue_188_remove_line_break_after_update.java │ │ ├── Issue_189_indent_private_plsql_unit_in_type.java │ │ ├── Issue_198_indent_return.java │ │ ├── Issue_1_json_case_sensitive.java │ │ ├── Issue_204_lost_line_break_after_label.java │ │ ├── Issue_205_lost_space_after_equal_sign.java │ │ ├── Issue_210_indent_insert_select.java │ │ ├── Issue_214_lost_line_breaks_in_values_clause.java │ │ ├── Issue_216_case_expr_create_table.java │ │ ├── Issue_218_indent_column_aliases_with_clause.java │ │ ├── Issue_21_line_open_cursor_for.java │ │ ├── Issue_220_indent_comment_before_case.java │ │ ├── Issue_249_globals_in_package_spec.java │ │ ├── Issue_256_linebreak_in_string.java │ │ ├── Issue_264_exit_in_whenever_oserror.java │ │ ├── Issue_265_wrong_indent_in_insert.java │ │ ├── Issue_266_line_break_on_conversion_error.java │ │ ├── Issue_267_spaces_in_grant.java │ │ ├── Issue_26_create_tablespace.java │ │ ├── Issue_29_not_in.java │ │ ├── Issue_30_into_clause.java │ │ ├── Issue_33_split_arguments.java │ │ ├── Issue_36_conditional_compilation.java │ │ ├── Issue_53_comma_before_without_ws.java │ │ ├── Issue_54_align_table_alias.java │ │ ├── Issue_57_xmltable.java │ │ ├── Issue_5_type_members.java │ │ ├── Issue_62_xmlquery.java │ │ ├── Issue_64_update.java │ │ ├── Issue_68_merge.java │ │ ├── Issue_6_max_one_empty_line.java │ │ ├── Issue_78_correlated_subquery.java │ │ ├── Issue_81_boolean_conditions_and_parenthesis.java │ │ ├── Issue_82_outer_apply.java │ │ ├── Issue_83_nested_function_calls.java │ │ └── Issue_84_long_assignments.java │ │ └── rules │ │ ├── A10_align_parameter_modes.java │ │ ├── A11_align_parameter_names.java │ │ ├── A12_line_breaks_before_then.java │ │ ├── A13_keep_short_nodes_on_same_line.java │ │ ├── A14_line_break_after_node.java │ │ ├── A15_line_break_before_node.java │ │ ├── A16_line_break_for_multiline_parents.java │ │ ├── A17_whitespace_around_node.java │ │ ├── A18_indent_comment.java │ │ ├── A19_restore_indent_in_conditional_branch.java │ │ ├── A1_tabs.java │ │ ├── A20_align_json_table_columns.java │ │ ├── A21_remove_non_ws_indent.java │ │ ├── A22_no_space_between_sign_and_digits.java │ │ ├── A23_enforce_line_break_after_single_line_comment.java │ │ ├── A24_indent_case_expression.java │ │ ├── A2_trailing_spaces.java │ │ ├── A3_formatter_off_on.java │ │ ├── A4_line_overflow.java │ │ ├── A5_no_space_before_node.java │ │ ├── A6_no_space_after_node.java │ │ ├── A7_one_space_before_node.java │ │ ├── A8_one_space_after_node.java │ │ ├── A9_align_xmltable_columns.java │ │ ├── I10_determine_and_normalize_line_separator.java │ │ ├── I11_enforce_nonquoted_identifiers.java │ │ ├── O10_line_break_on_ansi_joins.java │ │ ├── O11_line_break_on_subqueries.java │ │ ├── O12_line_breaks_on_flowcontrol.java │ │ ├── O1_line_breaks_on_concatenation.java │ │ ├── O2_whitespace_around_operators.java │ │ ├── O3_whitespace_around_parenthesis.java │ │ ├── O4_align_assignment_operator.java │ │ ├── O5_align_column_and_table_aliases.java │ │ ├── O6_line_breaks_after_select.java │ │ ├── O7_align_equality_predicate.java │ │ ├── O8_align_datatypes.java │ │ ├── O9_line_breaks_on_boolean_connectors.java │ │ ├── R2_indentation.java │ │ ├── R3_one_command_per_line.java │ │ ├── R5_commas.java │ │ ├── R6_align_parameters.java │ │ └── R7_right_align_keywords.java │ ├── sqlcl │ └── tests │ │ ├── AbstractFormatTest.java │ │ ├── AbstractSqlclTest.java │ │ ├── CharsetTest.java │ │ ├── FormatHelpTest.java │ │ ├── FormatTest.java │ │ ├── FormatVersionTest.java │ │ ├── FormatWrongArgumentTest.java │ │ ├── RunType.java │ │ ├── TvdFormatHelpTest.java │ │ ├── TvdFormatIgnoreTest.java │ │ ├── TvdFormatIssue232Test.java │ │ ├── TvdFormatPathWithSpaceTest.java │ │ ├── TvdFormatRegisterTest.java │ │ ├── TvdFormatTest.java │ │ ├── TvdFormatVersionTest.java │ │ └── TvdFormatWrongArgumentTest.java │ └── standalone │ └── tests │ ├── AbstractTvdFormatTest.java │ └── TvdFormatTest.java └── resources ├── advanced_format.xml ├── charset ├── utf8.sql └── windows-1252.sql ├── logging.conf ├── trivadis_advanced_format.xml ├── trivadis_custom_format.arbori └── unformatted ├── dont_format.txt ├── markdown.md ├── package_body.pkb ├── query.sql ├── sql.txt └── syntax_error.sql /.gitattributes: -------------------------------------------------------------------------------- 1 | # Test file encoded in windows-1252 2 | windows-1252.sql encoding=cp1252 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # Package Files 8 | *.jar 9 | *.war 10 | *.nar 11 | *.ear 12 | *.zip 13 | *.tar.gz 14 | *.rar 15 | 16 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 17 | hs_err_pid* 18 | 19 | # SonarQube 20 | **/.sonar 21 | **/.scannerwork 22 | 23 | # Eclipse / Visual Studio Code 24 | .project 25 | .classpath 26 | .settings 27 | .vscode 28 | 29 | # IntelliJ 30 | .idea 31 | *.iml 32 | 33 | # macOS 34 | *.DS_Store 35 | 36 | # Windows 37 | Thumbs.db 38 | 39 | # Targets 40 | **/target 41 | **/bin 42 | 43 | # maven-shade-plugin 44 | dependency-reduced-pom.xml 45 | -------------------------------------------------------------------------------- /images/advanced_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trivadis/plsql-formatter-settings/f60dd0ba2c141483a878dbb6be2c4e00ebd35421/images/advanced_format.png -------------------------------------------------------------------------------- /images/change_line_breaks_on_comma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trivadis/plsql-formatter-settings/f60dd0ba2c141483a878dbb6be2c4e00ebd35421/images/change_line_breaks_on_comma.png -------------------------------------------------------------------------------- /images/custom_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trivadis/plsql-formatter-settings/f60dd0ba2c141483a878dbb6be2c4e00ebd35421/images/custom_format.png -------------------------------------------------------------------------------- /settings/datagrip/trivadis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 34 | 35 | 42 | -------------------------------------------------------------------------------- /settings/plsql_developer/trivadis_beautifier.br: -------------------------------------------------------------------------------- 1 | Version=1 2 | RightMargin=120 3 | Indent=3 4 | UseTabCharacter=FALSE 5 | TabCharacterSize=3 6 | AlignDeclarationGroups=TRUE 7 | AlignAssignmentGroups=TRUE 8 | KeywordCase=2 9 | IdentifierCase=0 10 | UseSpecialCase=TRUE 11 | ItemList.Format=1 12 | ItemList.Align=TRUE 13 | ItemList.CommaAfter=TRUE 14 | ItemList.AtLeftMargin=FALSE 15 | EmptyLines=1 16 | ThenOnNewLine=FALSE 17 | LoopOnNewLine=TRUE 18 | DML.LeftAlignKeywords=FALSE 19 | DML.LeftAlignItems=FALSE 20 | DML.OnOneLineIfPossible=FALSE 21 | DML.WhereSplitAndOr=TRUE 22 | DML.WhereAndOrAfterExpression=FALSE 23 | DML.WhereAndOrUnderWhere=FALSE 24 | DML.JoinSplitBeforeOn=TRUE 25 | DML.InsertItemList.Format=1 26 | DML.InsertItemList.Align=FALSE 27 | DML.InsertItemList.CommaAfter=TRUE 28 | DML.InsertItemList.AtLeftMargin=FALSE 29 | DML.SelectItemList.Format=1 30 | DML.SelectItemList.Align=TRUE 31 | DML.SelectItemList.CommaAfter=TRUE 32 | DML.SelectItemList.AtLeftMargin=FALSE 33 | DML.UpdateItemList.Format=1 34 | DML.UpdateItemList.Align=TRUE 35 | DML.UpdateItemList.CommaAfter=TRUE 36 | DML.UpdateItemList.AtLeftMargin=FALSE 37 | ParameterDeclarationList.Format=1 38 | ParameterDeclarationList.Align=TRUE 39 | ParameterDeclarationList.CommaAfter=TRUE 40 | ParameterDeclarationList.AtLeftMargin=FALSE 41 | RecordFieldList.Format=1 42 | RecordFieldList.Align=TRUE 43 | RecordFieldList.CommaAfter=TRUE 44 | RecordFieldList.AtLeftMargin=FALSE 45 | SplitAndOr=FALSE 46 | AndOrAfterExpression=FALSE 47 | [SpecialCase] 48 | -------------------------------------------------------------------------------- /settings/sql_developer/trivadis_advanced_format.xml: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | true 5 | false 6 | oracle.dbtools.app.Format.InlineComments.CommentsUnchanged 7 | true 8 | 120 9 | true 10 | true 11 | true 12 | oracle.dbtools.app.Format.Breaks.After 13 | oracle.dbtools.app.Format.Breaks.Before 14 | true 15 | 1 16 | true 17 | false 18 | oracle.dbtools.app.Format.Case.NoCaseChange 19 | oracle.dbtools.app.Format.BreaksX2.Keep 20 | oracle.dbtools.app.Format.Breaks.Before 21 | oracle.dbtools.app.Format.Space.Default 22 | oracle.dbtools.app.Format.FlowControl.IndentedActions 23 | 1 24 | false 25 | true 26 | true 27 | 3 28 | false 29 | true 30 | oracle.dbtools.app.Format.Case.lower 31 | false 32 | false 33 | 34 | -------------------------------------------------------------------------------- /settings/toad/trivadis_fmtplus.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trivadis/plsql-formatter-settings/f60dd0ba2c141483a878dbb6be2c4e00ebd35421/settings/toad/trivadis_fmtplus.opt -------------------------------------------------------------------------------- /standalone/install_sqlcl_libs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # set the directory where SQLcl libraries are stored 4 | if [[ "$1" = "" ]]; then 5 | SQLCL_LIBDIR="/usr/local/bin/sqlcl/lib" 6 | else 7 | SQLCL_LIBDIR="$1" 8 | fi 9 | 10 | # check SQLcl library directory 11 | if ! test -f "${SQLCL_LIBDIR}/dbtools-common.jar"; then 12 | echo "Error: ${SQLCL_LIBDIR} is not a valid path to the lib directory of SQLcl." 13 | echo " Please pass a valid path to this script." 14 | exit 1 15 | fi 16 | 17 | # define common Maven properties 18 | SQLCL_VERSION="23.4.0" 19 | 20 | # install JAR files in local Maven repository, these libs are not available in public Maven repositories 21 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/dbtools-common.jar -DgeneratePom=true \ 22 | -DgroupId=oracle.dbtools -DartifactId=dbtools-common -Dversion=$SQLCL_VERSION -Dpackaging=jar 23 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/dbtools-sqlcl.jar -DgeneratePom=true \ 24 | -DgroupId=oracle.dbtools -DartifactId=dbtools-sqlcl -Dversion=$SQLCL_VERSION -Dpackaging=jar 25 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/xmlparserv2_sans_jaxp_services.jar -DgeneratePom=true \ 26 | -DgroupId=oracle.xml -DartifactId=xmlparserv2-sans-jaxp-services -Dversion=$SQLCL_VERSION -Dpackaging=jar 27 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/orai18n.jar -DgeneratePom=true \ 28 | -DgroupId=oracle.i18n -DartifactId=orai18n -Dversion=$SQLCL_VERSION -Dpackaging=jar 29 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/orai18n-mapping.jar -DgeneratePom=true \ 30 | -DgroupId=oracle.i18n -DartifactId=orai18n-mapping -Dversion=$SQLCL_VERSION -Dpackaging=jar 31 | mvn install:install-file -Dfile=$SQLCL_LIBDIR/orajsoda.jar -DgeneratePom=true \ 32 | -DgroupId=oracle.soda -DartifactId=orajsoda -Dversion=$SQLCL_VERSION -Dpackaging=jar 33 | -------------------------------------------------------------------------------- /standalone/src/main/java/com/trivadis/plsql/formatter/ScriptRunnerContext.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter; 2 | 3 | import java.io.*; 4 | import java.nio.charset.StandardCharsets; 5 | import java.nio.file.Paths; 6 | 7 | public class ScriptRunnerContext { 8 | private OutputStream outputStream; 9 | 10 | ScriptRunnerContext() { 11 | super(); 12 | } 13 | 14 | @SuppressWarnings("unused") 15 | public Object getProperty(String name) { 16 | if (name.equals("script.runner.cd_command")) { 17 | return Paths.get("").toAbsolutePath().toString(); 18 | } 19 | return null; 20 | } 21 | 22 | public void setOutputStream(OutputStream outputStream) { 23 | this.outputStream = outputStream; 24 | } 25 | 26 | public OutputStream getOutputStream() { 27 | return outputStream; 28 | } 29 | 30 | @SuppressWarnings("unused") 31 | public void write(String string) throws IOException { 32 | outputStream.write(string.getBytes(StandardCharsets.UTF_8)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /standalone/src/main/java/com/trivadis/plsql/formatter/TvdFormat.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter; 2 | 3 | import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; 4 | import org.graalvm.polyglot.Context; 5 | import org.graalvm.polyglot.HostAccess; 6 | 7 | import javax.script.ScriptContext; 8 | import javax.script.ScriptEngine; 9 | import javax.script.ScriptException; 10 | import java.io.IOException; 11 | import java.io.InputStreamReader; 12 | import java.net.URL; 13 | import java.util.logging.LogManager; 14 | 15 | public class TvdFormat { 16 | private final ScriptEngine scriptEngine; 17 | private final ScriptRunnerContext ctx; 18 | 19 | TvdFormat() { 20 | scriptEngine = GraalJSScriptEngine.create(null, 21 | Context.newBuilder("js") 22 | .allowHostAccess(HostAccess.ALL) 23 | .allowHostClassLookup(s -> true)); 24 | ctx = new ScriptRunnerContext(); 25 | ctx.setOutputStream(System.out); 26 | scriptEngine.getContext().setAttribute("ctx", ctx, ScriptContext.ENGINE_SCOPE); 27 | } 28 | 29 | public void run(String[] arguments) throws IOException, ScriptException { 30 | URL script = Thread.currentThread().getContextClassLoader().getResource("format.js"); 31 | String[] args = new String[arguments.length + 1]; 32 | args[0] = "format.js"; 33 | System.arraycopy(arguments, 0, args, 1, arguments.length); 34 | scriptEngine.getContext().setAttribute("args", args, ScriptContext.ENGINE_SCOPE); 35 | assert script != null; 36 | scriptEngine.eval(new InputStreamReader(script.openStream()), scriptEngine.getContext()); 37 | ctx.getOutputStream().flush(); 38 | } 39 | 40 | public static void main(String[] args) throws IOException, ScriptException { 41 | // disable logging by default as in SQLcl 42 | LogManager.getLogManager().reset(); 43 | // amend usage help in format.js for standalone tvdformat 44 | System.setProperty("tvdformat.standalone", "true"); 45 | // format.js is compiled at runtime with a GraalVM JDK but interpreted with other JDKs 46 | System.setProperty("polyglot.engine.WarnInterpreterOnly", "false"); 47 | // run formatter with command line parameters 48 | TvdFormat formatter = new TvdFormat(); 49 | formatter.run(args); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /standalone/src/main/java/com/trivadis/plsql/formatter/sandbox/SandboxedFormatter.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sandbox; 2 | 3 | import oracle.dbtools.app.Format; 4 | 5 | import java.util.concurrent.ExecutionException; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.Future; 9 | import java.util.concurrent.TimeUnit; 10 | import java.util.concurrent.TimeoutException; 11 | 12 | public class SandboxedFormatter { 13 | public static Format copy(Format original) { 14 | Format formatter = new Format(); 15 | formatter.options.putAll(original.options); 16 | return formatter; 17 | } 18 | 19 | public static String format(Format formatter, String original, Integer timeout) { 20 | ExecutorService executor = Executors.newSingleThreadExecutor(); 21 | Format newFormatter = formatter; 22 | if (formatter.options.containsKey("timeout")) { 23 | // it is costly to create a new formatter, so we do that only when needed. 24 | formatter.options.remove("timeout"); 25 | newFormatter = copy(formatter); 26 | } 27 | Future future = executor.submit(new SandboxedFormatterTask(newFormatter, original)); 28 | String result; 29 | try { 30 | result = future.get(timeout, TimeUnit.SECONDS); 31 | } catch (TimeoutException | InterruptedException | ExecutionException e) { 32 | future.cancel(true); 33 | System.out.print("timeout... "); 34 | formatter.options.put("timeout", true); 35 | result = original; 36 | } 37 | executor.shutdown(); 38 | return result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /standalone/src/main/java/com/trivadis/plsql/formatter/sandbox/SandboxedFormatterTask.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sandbox; 2 | 3 | import oracle.dbtools.app.Format; 4 | 5 | import java.util.concurrent.Callable; 6 | 7 | public class SandboxedFormatterTask implements Callable { 8 | final Format formatter; 9 | final String original; 10 | 11 | public SandboxedFormatterTask(Format formatter, String original) { 12 | this.formatter = formatter; 13 | this.original = original; 14 | } 15 | 16 | @Override 17 | public String call() throws Exception { 18 | return formatter.format(original); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /standalone/src/main/resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/predefined-classes-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type":"agent-extracted", 4 | "classes":[ 5 | ] 6 | } 7 | ] 8 | 9 | -------------------------------------------------------------------------------- /standalone/src/main/resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/proxy-config-manual.json: -------------------------------------------------------------------------------- 1 | [ 2 | [], 3 | ["java.util.function.Predicate"] 4 | ] -------------------------------------------------------------------------------- /standalone/src/main/resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/proxy-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | ] 3 | -------------------------------------------------------------------------------- /standalone/src/main/resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources":{ 3 | "includes":[ 4 | { 5 | "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.TruffleLanguage$Provider\\E" 6 | }, 7 | { 8 | "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.instrumentation.TruffleInstrument$Provider\\E" 9 | }, 10 | { 11 | "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.library.DefaultExportProvider\\E" 12 | }, 13 | { 14 | "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.object.LayoutFactory\\E" 15 | }, 16 | { 17 | "pattern":"\\QMETA-INF/services/com.oracle.truffle.js.runtime.Evaluator\\E" 18 | }, 19 | { 20 | "pattern":"\\QMETA-INF/services/java.nio.file.spi.FileSystemProvider\\E" 21 | }, 22 | { 23 | "pattern":"\\QMETA-INF/services/javax.script.ScriptEngineFactory\\E" 24 | }, 25 | { 26 | "pattern":"\\Qcom/oracle/truffle/nfi/backend/libffi/LibFFILanguage.class\\E" 27 | }, 28 | { 29 | "pattern":"\\Qformat.js\\E" 30 | }, 31 | { 32 | "pattern":"\\Qoracle/dbtools/app/format.prg\\E" 33 | }, 34 | { 35 | "pattern":"\\Qoracle/dbtools/app/persist2xml.prg\\E" 36 | }, 37 | { 38 | "pattern":"\\Qoracle/dbtools/arbori/arbori.grammar\\E" 39 | }, 40 | { 41 | "pattern":"\\Qoracle/dbtools/arbori/std.arbori\\E" 42 | }, 43 | { 44 | "pattern":"\\Qoracle/dbtools/parser/js/js.grammar\\E" 45 | }, 46 | { 47 | "pattern":"\\Qoracle/dbtools/parser/plsql/allRules.txt\\E" 48 | }, 49 | { 50 | "pattern":"\\Qoracle/dbtools/parser/xml.grammar\\E" 51 | } 52 | ]}, 53 | "bundles":[ 54 | { 55 | "name":"com.apple.laf.resources.aqua", 56 | "classNames":["com.apple.laf.resources.aqua"] 57 | }, 58 | { 59 | "name":"com.sun.swing.internal.plaf.basic.resources.basic", 60 | "classNames":["com.sun.swing.internal.plaf.basic.resources.basic"] 61 | }, 62 | { 63 | "name":"oracle.dbtools.util.Messages", 64 | "locales":[""] 65 | }, 66 | { 67 | "name":"sun.awt.resources.awt", 68 | "classNames":["sun.awt.resources.awt"] 69 | }, 70 | { 71 | "name":"sun.awt.resources.awtosx", 72 | "classNames":["sun.awt.resources.awtosx"] 73 | } 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /standalone/src/main/resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/serialization-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "types":[ 3 | ], 4 | "lambdaCapturingTypes":[ 5 | ], 6 | "proxies":[ 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /standalone/src/main/resources/format.js: -------------------------------------------------------------------------------- 1 | ../../../../sqlcl/format.js -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/examples/Trivadis.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.examples; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Trivadis extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void set_salary() { 12 | var sql = """ 13 | create or replace procedure set_salary( 14 | in_employee_id in employees.employee_id%type 15 | ) is 16 | cursor c_employees( 17 | p_employee_id in employees.employee_id%type 18 | ) is 19 | select last_name, 20 | first_name, 21 | salary 22 | from employees 23 | where employee_id = p_employee_id 24 | order by last_name, 25 | first_name; 26 | r_employee c_employees%rowtype; 27 | l_new_salary employees.salary%type; 28 | begin 29 | open c_employees(p_employee_id => in_employee_id); 30 | fetch c_employees into r_employee; 31 | close c_employees; 32 | new_salary( 33 | in_employee_id => in_employee_id, 34 | out_salary => l_new_salary 35 | ); 36 | -- check whether salary has changed 37 | if r_employee.salary <> l_new_salary then 38 | update employees 39 | set salary = l_new_salary 40 | where employee_id = in_employee_id; 41 | end if; 42 | end set_salary; 43 | / 44 | """; 45 | formatAndAssert(sql); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/Comment.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Comment extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void one_single_line_with_additional_break() { 12 | var sql = """ 13 | -- Single line comment 14 | 15 | commit; 16 | """; 17 | formatAndAssert(sql); 18 | } 19 | 20 | @Test 21 | public void two_single_lines_with_additional_break() { 22 | var sql = """ 23 | -- 24 | -- Single line comment 25 | 26 | commit; 27 | """; 28 | formatAndAssert(sql); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/Paren_expr_list.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Paren_expr_list extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void unnamed_parameters() { 12 | var sql = """ 13 | select func(a, b, c, 100), 14 | func( 15 | a123456789, 16 | b123456789, 17 | c123456789, 18 | d123456789, 19 | e123456789, 20 | f123456789, 21 | 100, 22 | 200, 23 | 300, 24 | 400, 25 | 500 26 | ) 27 | from dual; 28 | """; 29 | formatAndAssert(sql); 30 | } 31 | 32 | @Test 33 | public void named_parameters() { 34 | var sql = """ 35 | select func( 36 | p1 => a, 37 | p2 => b, 38 | p300 => c, 39 | p40000 => 100, 40 | p50 => 200, 41 | p6 => 300, 42 | p7 => 400, 43 | p88888888888888 => 500 44 | ) 45 | from dual; 46 | """; 47 | formatAndAssert(sql); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/Select_list.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Select_list extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void select_list_comma_after() { 13 | var sql = """ 14 | select case a 15 | when 1 then 16 | 'one' 17 | when 2 then 18 | 'two' 19 | else 20 | 'else' 21 | end a2, 22 | b, 23 | c, 24 | to_char(d, 'yyyy-mm') as d2, 25 | case 26 | when a = 1 then 27 | 'one' 28 | when a = 2 then 29 | 'two' 30 | else 31 | 'else' 32 | end a3 33 | from t2; 34 | """; 35 | formatAndAssert(sql); 36 | } 37 | 38 | @Test 39 | public void select_list_comma_before() { 40 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 41 | var sql = """ 42 | select case a 43 | when 1 then 44 | 'one' 45 | when 2 then 46 | 'two' 47 | else 48 | 'else' 49 | end a2 50 | , b 51 | , c 52 | , to_char(d, 'yyyy-mm') as d2 53 | , case 54 | when a = 1 then 55 | 'one' 56 | when a = 2 then 57 | 'two' 58 | else 59 | 'else' 60 | end a3 61 | from t2; 62 | """; 63 | formatAndAssert(sql, true); 64 | setOption(getFormatter().breaksComma, Format.Breaks.After); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Accessible_by_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Accessible_by_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void one() throws IOException { 14 | var input = """ 15 | create package pkg as 16 | procedure p1 accessible 17 | by (procedure p2); 18 | end; 19 | """; 20 | var actual = getFormatter().format(input); 21 | var expected = """ 22 | create package pkg as 23 | procedure p1 24 | accessible by (procedure p2); 25 | end; 26 | """; 27 | assertEquals(expected, actual); 28 | } 29 | 30 | @Test 31 | public void multiple_single_line() { 32 | var sql = """ 33 | create package pkg as 34 | procedure p1 35 | accessible by (function f1, procedure p2, package pkg2, trigger trg1, type type); 36 | end; 37 | """; 38 | formatAndAssert(sql); 39 | } 40 | 41 | @Test 42 | public void multiple_multi_line() { 43 | var sql = """ 44 | create package pkg as 45 | procedure p1 46 | accessible by ( 47 | function f1, 48 | procedure p2, 49 | package pkg2, 50 | trigger trg1, 51 | type type 52 | ); 53 | end; 54 | """; 55 | formatAndAssert(sql); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Aggregate_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Aggregate_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void standalone_single_line() { 14 | var sql = """ 15 | create function spatialunion(x geometry) return geometry aggregate using spatialunionroutines; 16 | """; 17 | formatAndAssert(sql); 18 | } 19 | 20 | @Test 21 | public void standalone_multi_line() throws IOException { 22 | var input = """ 23 | create function spatialunion( 24 | x geometry 25 | ) return geometry 26 | aggregate 27 | using 28 | spatialunionroutines; 29 | """; 30 | var expected = """ 31 | create function spatialunion( 32 | x geometry 33 | ) return geometry 34 | aggregate using spatialunionroutines; 35 | """; 36 | var actual = getFormatter().format(input); 37 | assertEquals(expected, actual); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Autonamous_transaction_pragma.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Autonamous_transaction_pragma extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void package_procedure() throws IOException { 14 | var input = """ 15 | create package body pkg is 16 | procedure p is 17 | pragma 18 | autonomous_transaction 19 | ; 20 | begin 21 | commit; 22 | end p; 23 | end pkg; 24 | / 25 | """; 26 | var actual = getFormatter().format(input); 27 | var expected = """ 28 | create package body pkg is 29 | procedure p is 30 | pragma autonomous_transaction; 31 | begin 32 | commit; 33 | end p; 34 | end pkg; 35 | / 36 | """; 37 | assertEquals(expected, actual); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Basic_loop_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Basic_loop_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized() throws IOException { 14 | var input = """ 15 | begin 16 | < 17 | < 18 | infinite_loop 19 | > 20 | > 21 | loop 22 | null 23 | ; 24 | end 25 | loop 26 | infinite_loop 27 | ; 28 | end; 29 | """; 30 | var actual = getFormatter().format(input); 31 | var expected = """ 32 | begin 33 | <> 34 | loop 35 | null; 36 | end loop infinite_loop; 37 | end; 38 | """; 39 | assertEquals(expected, actual); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Block.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Block extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void labelled_body() { 12 | var sql = """ 13 | <> 14 | begin 15 | <> null; 16 | end empty; 17 | """; 18 | formatAndAssert(sql); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Call_specification.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Call_specification extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void c_declaration() { 12 | var sql = """ 13 | create procedure utl_xml_parse_query( 14 | in_current_userid in number, 15 | in_schema_name in varchar2, 16 | in_query in clob, 17 | in_result in out nocopy clob 18 | ) is 19 | language c 20 | library sys.utl_xml_lib 21 | name KUXPARSEQUERY 22 | with context parameters ( 23 | context, 24 | in_current_userid ocinumber, 25 | in_current_userid indicator, 26 | in_schema_name ocistring, 27 | in_schema_name indicator, 28 | in_query ociloblocator, 29 | in_query indicator, 30 | in_result ociloblocator, 31 | in_result indicator 32 | ); 33 | """; 34 | formatAndAssert(sql); 35 | } 36 | 37 | @Test 38 | public void java_declaration() { 39 | var sql = """ 40 | create or replace package base64helper is 41 | procedure encode(p_source in blob, 42 | p_target in out clob) is 43 | language java 44 | name 'Base64Helper.encode(oracle.sql.BLOB,oracle.sql.CLOB[])'; 45 | 46 | procedure decode(p_source in clob, 47 | p_target in out blob) is 48 | language java 49 | name 'Base64Helper.decode(oracle.sql.CLOB,oracle.sql.BLOB[])'; 50 | end base64helper; 51 | / 52 | """; 53 | formatAndAssert(sql); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Close_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Close_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void close() throws IOException { 14 | var input = """ 15 | begin 16 | close 17 | c_cursor 18 | ; 19 | end; 20 | / 21 | """; 22 | var actual = getFormatter().format(input); 23 | var expected = """ 24 | begin 25 | close c_cursor; 26 | end; 27 | / 28 | """; 29 | assertEquals(expected, actual); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Compile_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Compile_clause extends ConfiguredTestFormatter { 11 | 12 | /* Alter statements are out of scope. 13 | * Code ist mostly kept as is. 14 | * In this case only some line breaks are eliminated. */ 15 | 16 | @Test 17 | public void alter_function() throws IOException { 18 | var input = """ 19 | alter 20 | function 21 | f 22 | compile 23 | reuse 24 | settings 25 | ; 26 | """; 27 | var actual = getFormatter().format(input); 28 | var expected = """ 29 | alter 30 | function 31 | f 32 | compile 33 | reuse 34 | settings; 35 | """; 36 | assertEquals(expected, actual); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Constant_declaration.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Constant_declaration extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized() throws IOException { 14 | var input = """ 15 | declare 16 | co_true 17 | integer 18 | not 19 | null 20 | : 21 | = 22 | 1 23 | ; 24 | begin 25 | null 26 | ; 27 | end 28 | ; 29 | / 30 | """; 31 | var actual = getFormatter().format(input); 32 | var expected = """ 33 | declare 34 | co_true integer not null := 35 | 1; 36 | begin 37 | null; 38 | end; 39 | / 40 | """; 41 | assertEquals(expected, actual); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Coverage_pragma.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Coverage_pragma extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_13_7() throws IOException { 14 | var input = """ 15 | begin 16 | if (x > 0) then 17 | y := 2; 18 | else 19 | pragma 20 | coverage 21 | ( 22 | 'NOT_FEASIBLE' 23 | ) 24 | ; -- 1 25 | z := 3; 26 | end if; 27 | if (y > 0) then 28 | z := 2; 29 | else 30 | pragma 31 | coverage 32 | ( 33 | 'NOT_FEASIBLE' 34 | ) 35 | ; -- 2 36 | z := 3; 37 | end if; 38 | end; 39 | """; 40 | var actual = getFormatter().format(input); 41 | var expected = """ 42 | begin 43 | if (x > 0) then 44 | y := 2; 45 | else 46 | pragma coverage ('NOT_FEASIBLE'); -- 1 47 | z := 3; 48 | end if; 49 | if (y > 0) then 50 | z := 2; 51 | else 52 | pragma coverage ('NOT_FEASIBLE'); -- 2 53 | z := 3; 54 | end if; 55 | end; 56 | """; 57 | assertEquals(expected, actual); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Cursor_variable_declaration.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Cursor_variable_declaration extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void ref_cursor() throws IOException { 14 | var input = """ 15 | declare 16 | type 17 | cur_type 18 | is 19 | ref 20 | cursor 21 | return 22 | myschema 23 | . 24 | mytable 25 | % 26 | rowtype 27 | ; 28 | c_cur 29 | is 30 | cur_type 31 | ; 32 | begin 33 | null; 34 | end; 35 | """; 36 | var actual = getFormatter().format(input); 37 | var expected = """ 38 | declare 39 | type cur_type is 40 | ref cursor return myschema.mytable%rowtype; 41 | c_cur is cur_type; 42 | begin 43 | null; 44 | end; 45 | """; 46 | assertEquals(expected, actual); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Default_collation_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Default_collation_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void procedure() throws IOException { 14 | var input = """ 15 | create 16 | or 17 | replace 18 | procedure 19 | p 20 | default 21 | collation 22 | using_nls_comp 23 | is 24 | begin 25 | null; 26 | end; 27 | / 28 | """; 29 | var actual = getFormatter().format(input); 30 | var expected = """ 31 | create or replace procedure p 32 | default collation using_nls_comp 33 | is 34 | begin 35 | null; 36 | end; 37 | / 38 | """; 39 | assertEquals(expected, actual); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Deprecate_pragma.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Deprecate_pragma extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_13_12() throws IOException { 14 | var input = """ 15 | create package pack1 as 16 | pragma 17 | deprecate 18 | ( 19 | pack1 20 | ) 21 | ; 22 | procedure foo; 23 | procedure bar; 24 | end pack1; 25 | """; 26 | var actual = getFormatter().format(input); 27 | var expected = """ 28 | create package pack1 as 29 | pragma deprecate (pack1); 30 | procedure foo; 31 | procedure bar; 32 | end pack1; 33 | """; 34 | assertEquals(expected, actual); 35 | } 36 | 37 | @Test 38 | public void example_13_13() throws IOException { 39 | var input = """ 40 | create package pack5 authid definer as 41 | pragma 42 | deprecate 43 | ( 44 | pack5 45 | , 46 | 'package pack5 has been deprecated, use new_pack5 instead.' 47 | ) 48 | ; 49 | procedure foo; 50 | procedure bar; 51 | end pack5; 52 | """; 53 | var actual = getFormatter().format(input); 54 | var expected = """ 55 | create package pack5 authid definer as 56 | pragma deprecate ( 57 | pack5, 58 | 'package pack5 has been deprecated, use new_pack5 instead.' 59 | ); 60 | procedure foo; 61 | procedure bar; 62 | end pack5; 63 | """; 64 | assertEquals(expected, actual); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Deterministic_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Deterministic_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_14_16() throws IOException { 14 | var input = """ 15 | create or replace function text_length(a clob) 16 | return number deterministic is 17 | begin 18 | return dbms_lob.getlength(a); 19 | end; 20 | """; 21 | var actual = getFormatter().format(input); 22 | var expected = """ 23 | create or replace function text_length(a clob) 24 | return number 25 | deterministic 26 | is 27 | begin 28 | return dbms_lob.getlength(a); 29 | end; 30 | """; 31 | assertEquals(expected, actual); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Element_specification.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Element_specification extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_14_30() throws IOException { 14 | var input = """ 15 | create 16 | type 17 | demo_typ2 18 | as 19 | object 20 | ( 21 | a1 22 | number 23 | , 24 | member 25 | function 26 | get_square 27 | return 28 | number 29 | ); 30 | """; 31 | var actual = getFormatter().format(input); 32 | var expected = """ 33 | create type demo_typ2 34 | as 35 | object 36 | ( 37 | a1 number, 38 | member function get_square return number 39 | ); 40 | """; 41 | assertEquals(expected, actual); 42 | } 43 | 44 | @Test 45 | public void attributes_aligned() { 46 | var sql = """ 47 | create type demo_typ as object ( 48 | aaa number, 49 | bbbb varchar2(20), 50 | cccccccc date, 51 | member function xyz return varchar2 52 | ); 53 | """; 54 | formatAndAssert(sql); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Exception_declaration.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Exception_declaration extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void simple() throws IOException { 14 | var input = """ 15 | declare 16 | e_invalid_operation 17 | exception; 18 | begin 19 | null; 20 | end; 21 | / 22 | """; 23 | var actual = getFormatter().format(input); 24 | var expected = """ 25 | declare 26 | e_invalid_operation exception; 27 | begin 28 | null; 29 | end; 30 | / 31 | """; 32 | assertEquals(expected, actual); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Exception_handler.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Exception_handler extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void combined() throws IOException { 14 | var input = """ 15 | begin 16 | p(1); 17 | exception 18 | when 19 | no_data_found 20 | or 21 | too_many_rows 22 | then 23 | null; 24 | when 25 | others 26 | then 27 | null; 28 | end; 29 | / 30 | """; 31 | var actual = getFormatter().format(input); 32 | var expected = """ 33 | begin 34 | p(1); 35 | exception 36 | when no_data_found or too_many_rows then 37 | null; 38 | when others then 39 | null; 40 | end; 41 | / 42 | """; 43 | assertEquals(expected, actual); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Exception_init_pragma.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Exception_init_pragma extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_11_5() throws IOException { 14 | var input = """ 15 | declare 16 | deadlock_detected 17 | exception; 18 | pragma 19 | exception_init 20 | ( 21 | deadlock_detected 22 | , 23 | - 24 | 60 25 | ) 26 | ; 27 | begin 28 | null; 29 | exception 30 | when deadlock_detected then 31 | null; 32 | end; 33 | / 34 | """; 35 | var actual = getFormatter().format(input); 36 | var expected = """ 37 | declare 38 | deadlock_detected exception; 39 | pragma exception_init(deadlock_detected, -60); 40 | begin 41 | null; 42 | exception 43 | when deadlock_detected then 44 | null; 45 | end; 46 | / 47 | """; 48 | assertEquals(expected, actual); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Execute_immediate_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Execute_immediate_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void dynamic_returning_clause() throws IOException { 14 | var input = """ 15 | begin 16 | execute immediate '...' 17 | returning into r1; 18 | end; 19 | """; 20 | var actual = getFormatter().format(input); 21 | var expected = """ 22 | begin 23 | execute immediate '...' 24 | returning into r1; 25 | end; 26 | """; 27 | assertEquals(expected, actual); 28 | } 29 | 30 | @Test 31 | public void using_clause() throws IOException { 32 | var input = """ 33 | begin 34 | execute immediate '...' 35 | using in d, e, f; 36 | end; 37 | """; 38 | var actual = getFormatter().format(input); 39 | var expected = """ 40 | begin 41 | execute immediate '...' 42 | using in d, e, f; 43 | end; 44 | """; 45 | assertEquals(expected, actual); 46 | } 47 | 48 | @Test 49 | public void into_clause() throws IOException { 50 | var input = """ 51 | begin 52 | execute immediate '...' 53 | into a, b, c 54 | using in d, e, f; 55 | end; 56 | """; 57 | var actual = getFormatter().format(input); 58 | var expected = """ 59 | begin 60 | execute immediate '...' 61 | into a, b, c 62 | using in d, e, f; 63 | end; 64 | """; 65 | assertEquals(expected, actual); 66 | } 67 | 68 | @Test 69 | public void bulk_collect_into_clause() throws IOException { 70 | var input = """ 71 | begin 72 | execute immediate '...' 73 | bulk collect into a, b, c; 74 | end; 75 | """; 76 | var actual = getFormatter().format(input); 77 | var expected = """ 78 | begin 79 | execute immediate '...' 80 | bulk collect into a, b, c; 81 | end; 82 | """; 83 | assertEquals(expected, actual); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Exit_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Exit_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized() throws IOException { 14 | var input = """ 15 | begin 16 | loop 17 | exit 18 | when 19 | 1 20 | = 21 | 1 22 | ; 23 | end 24 | loop; 25 | end; 26 | """; 27 | var actual = getFormatter().format(input); 28 | var expected = """ 29 | begin 30 | loop 31 | exit when 1 = 1; 32 | end loop; 33 | end; 34 | """; 35 | assertEquals(expected, actual); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Expression.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Expression extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_2_32_improving_readablity_with_parentheses() throws IOException { 14 | var input = """ 15 | declare 16 | a integer := 2**2*3**2; 17 | b integer := (2**2)*(3**2); 18 | begin 19 | dbms_output.put_line('a = ' || to_char(a)); 20 | dbms_output.put_line('b = ' || to_char(b)); 21 | end; 22 | / 23 | """; 24 | var actual = getFormatter().format(input); 25 | var expected = """ 26 | declare 27 | a integer := 2 ** 2 * 3 ** 2; 28 | b integer := (2 ** 2) * (3 ** 2); 29 | begin 30 | dbms_output.put_line('a = ' || to_char(a)); 31 | dbms_output.put_line('b = ' || to_char(b)); 32 | end; 33 | / 34 | """; 35 | assertEquals(expected, actual); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Fetch_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Fetch_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_6_6_fetch_inside_loop() throws IOException { 14 | var input = """ 15 | begin 16 | open c1; 17 | loop 18 | fetch 19 | c1 20 | into 21 | v_lastname 22 | , 23 | v_jobid 24 | ; 25 | exit when c1%notfound; 26 | end loop; 27 | close c1; 28 | end; 29 | """; 30 | var actual = getFormatter().format(input); 31 | var expected = """ 32 | begin 33 | open c1; 34 | loop 35 | fetch c1 36 | into v_lastname, 37 | v_jobid; 38 | exit when c1%notfound; 39 | end loop; 40 | close c1; 41 | end; 42 | """; 43 | assertEquals(expected, actual); 44 | } 45 | 46 | @Test 47 | public void bulk_collect() throws IOException { 48 | var input = """ 49 | begin 50 | open c1; 51 | fetch 52 | c1 53 | bulk 54 | collect into 55 | a 56 | , 57 | b 58 | , 59 | c 60 | limit 10 61 | ; 62 | close c1; 63 | end; 64 | """; 65 | var actual = getFormatter().format(input); 66 | var expected = """ 67 | begin 68 | open c1; 69 | fetch c1 70 | bulk collect into a, 71 | b, 72 | c 73 | limit 10; 74 | close c1; 75 | end; 76 | """; 77 | assertEquals(expected, actual); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/For_loop_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class For_loop_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized() throws IOException { 14 | var input = """ 15 | begin 16 | < 17 | < 18 | example 19 | > 20 | > 21 | for 22 | i 23 | in 24 | reverse 25 | 1 26 | . 27 | . 28 | 10 29 | loop 30 | null 31 | ; 32 | end 33 | loop 34 | example; 35 | end; 36 | """; 37 | var actual = getFormatter().format(input); 38 | var expected = """ 39 | begin 40 | <> 41 | for i in reverse 1..10 42 | loop 43 | null; 44 | end loop example; 45 | end; 46 | """; 47 | assertEquals(expected, actual); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Forall_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Forall_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_12_8() throws IOException { 14 | var input = """ 15 | begin 16 | forall i in depts.first..depts.last 17 | delete from employees_temp 18 | where department_id = depts(i); 19 | end; 20 | """; 21 | var actual = getFormatter().format(input); 22 | var expected = """ 23 | begin 24 | forall i in depts.first..depts.last 25 | delete from employees_temp 26 | where department_id = depts(i); 27 | end; 28 | """; 29 | assertEquals(expected, actual); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Formal_parameter_declaration.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Formal_parameter_declaration extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void all_grammar_variants() throws IOException { 14 | var input = """ 15 | create procedure p ( 16 | p1 integer, 17 | p2 in integer, 18 | p3 in number := 3, 19 | p4 in integer default 4, 20 | p555 out clob, 21 | p6 out nocopy clob, 22 | p7 in out nocopy clob 23 | ) is 24 | begin 25 | null; 26 | end; 27 | / 28 | """; 29 | var actual = getFormatter().format(input); 30 | var expected = """ 31 | create procedure p( 32 | p1 integer, 33 | p2 in integer, 34 | p3 in number := 3, 35 | p4 in integer default 4, 36 | p555 out clob, 37 | p6 out nocopy clob, 38 | p7 in out nocopy clob 39 | ) is 40 | begin 41 | null; 42 | end; 43 | / 44 | """; 45 | assertEquals(expected, actual); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/If_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class If_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_5_4() throws IOException { 14 | var input = """ 15 | DECLARE 16 | PROCEDURE p (sales NUMBER) 17 | IS 18 | bonus NUMBER := 0; 19 | BEGIN 20 | IF sales > 50000 THEN 21 | bonus := 1500; 22 | ELSIF sales > 35000 THEN 23 | bonus := 500; 24 | ELSE 25 | bonus := 100; 26 | END IF; 27 | 28 | DBMS_OUTPUT.PUT_LINE ( 29 | 'Sales = ' || sales || ', bonus = ' || bonus || '.' 30 | ); 31 | END p; 32 | BEGIN 33 | p(55000); 34 | p(40000); 35 | p(30000); 36 | END; 37 | / 38 | """; 39 | var actual = getFormatter().format(input); 40 | var expected = """ 41 | declare 42 | procedure p(sales number) 43 | is 44 | bonus number := 0; 45 | begin 46 | if sales > 50000 then 47 | bonus := 1500; 48 | elsif sales > 35000 then 49 | bonus := 500; 50 | else 51 | bonus := 100; 52 | end if; 53 | 54 | DBMS_OUTPUT.PUT_LINE( 55 | 'Sales = ' 56 | || sales 57 | || ', bonus = ' 58 | || bonus 59 | || '.' 60 | ); 61 | end p; 62 | begin 63 | p(55000); 64 | p(40000); 65 | p(30000); 66 | end; 67 | / 68 | """; 69 | assertEquals(expected, actual); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Inline_pragma.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Inline_pragma extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_13_4() throws IOException { 14 | var input = """ 15 | create procedure p1(x pls_integer) is 16 | pragma 17 | inline 18 | ( 19 | p1 20 | , 21 | 'YES' 22 | ) 23 | ; 24 | pragma inline(p1,'NO'); 25 | pragma inline ( p1 , 'YES' ) ; 26 | begin 27 | x := p1(1) + p1(2) + 17; -- These 2 invocations to p1 are not inlined 28 | end; 29 | / 30 | """; 31 | var actual = getFormatter().format(input); 32 | var expected = """ 33 | create procedure p1(x pls_integer) is 34 | pragma inline (p1, 'YES'); 35 | pragma inline(p1, 'NO'); 36 | pragma inline (p1, 'YES'); 37 | begin 38 | x := p1(1) + p1(2) + 17; -- These 2 invocations to p1 are not inlined 39 | end; 40 | / 41 | """; 42 | assertEquals(expected, actual); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Invokers_rights_and_definers_rights_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Invokers_rights_and_definers_rights_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void invoker() throws IOException { 14 | var input = """ 15 | create function f 16 | return integer 17 | authid 18 | current_user 19 | is 20 | begin 21 | null; 22 | end; 23 | / 24 | """; 25 | var actual = getFormatter().format(input); 26 | var expected = """ 27 | create function f 28 | return integer 29 | authid current_user 30 | is 31 | begin 32 | null; 33 | end; 34 | / 35 | """; 36 | assertEquals(expected, actual); 37 | } 38 | 39 | @Test 40 | public void definer() throws IOException { 41 | var input = """ 42 | create function f 43 | return integer 44 | authid 45 | definer 46 | is 47 | begin 48 | null; 49 | end; 50 | / 51 | """; 52 | var actual = getFormatter().format(input); 53 | var expected = """ 54 | create function f 55 | return integer 56 | authid definer 57 | is 58 | begin 59 | null; 60 | end; 61 | / 62 | """; 63 | assertEquals(expected, actual); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Named_cursor_attribute.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.TestInstance; 7 | import org.junit.jupiter.params.ParameterizedTest; 8 | import org.junit.jupiter.params.provider.ValueSource; 9 | 10 | import java.io.IOException; 11 | 12 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 13 | public class Named_cursor_attribute extends ConfiguredTestFormatter { 14 | 15 | @BeforeAll 16 | public void setup() { 17 | setOption(getFormatter().idCase, Format.Case.lower); 18 | } 19 | 20 | @ParameterizedTest 21 | @ValueSource(strings = {"isopen", "found", "notfound", "rowcount"}) 22 | public void tokenized_attr(String attr) throws IOException { 23 | var input = """ 24 | begin 25 | if 26 | not 27 | c1 28 | % 29 | #ATTR# 30 | then 31 | null; 32 | end 33 | if 34 | ; 35 | end 36 | ; 37 | """.replace("#ATTR#", attr); 38 | var actual = getFormatter().format(input); 39 | var expected = """ 40 | begin 41 | if not c1%#ATTR# then 42 | null; 43 | end if; 44 | end; 45 | """.replace("#ATTR#", attr); 46 | assertEquals(expected, actual); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Null_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Null_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized_upper_null() throws IOException { 14 | var input = """ 15 | begin 16 | NULL 17 | ; 18 | end 19 | ; 20 | """; 21 | var actual = getFormatter().format(input); 22 | var expected = """ 23 | begin 24 | null; 25 | end; 26 | """; 27 | assertEquals(expected, actual); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Open_for_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Open_for_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized_for_select_statement() throws IOException { 14 | var input = """ 15 | begin 16 | open 17 | c1 18 | for 19 | select 20 | * 21 | from 22 | emp 23 | ; 24 | end 25 | ; 26 | """; 27 | var actual = getFormatter().format(input); 28 | var expected = """ 29 | begin 30 | open c1 for 31 | select * 32 | from emp; 33 | end; 34 | """; 35 | assertEquals(expected, actual); 36 | } 37 | 38 | @Test 39 | public void tokenized_for_dynamic_select_statement_using() throws IOException { 40 | var input = """ 41 | begin 42 | open 43 | c1 44 | for 45 | 'select * from emp where deptno =:deptno and sal > :sal' 46 | using 47 | in 48 | p1 49 | , 50 | p2 51 | ; 52 | end 53 | ; 54 | """; 55 | var actual = getFormatter().format(input); 56 | var expected = """ 57 | begin 58 | open c1 for 59 | 'select * from emp where deptno =:deptno and sal > :sal' 60 | using in p1, p2; 61 | end; 62 | """; 63 | assertEquals(expected, actual); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Parallel_enable_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Parallel_enable_clause extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized_parallel_enable() throws IOException { 14 | var input = """ 15 | create 16 | function 17 | f 18 | ( 19 | in_cursor 20 | in 21 | sys_refcursor 22 | ) 23 | return 24 | some_collection_type 25 | pipelined 26 | parallel_enable 27 | is 28 | begin 29 | return; 30 | end; 31 | """; 32 | var actual = getFormatter().format(input); 33 | var expected = """ 34 | create function f( 35 | in_cursor in sys_refcursor 36 | ) 37 | return some_collection_type 38 | pipelined 39 | parallel_enable 40 | is 41 | begin 42 | return; 43 | end; 44 | """; 45 | assertEquals(expected, actual); 46 | } 47 | 48 | @Test 49 | public void tokenized_parallel_enable_partition_by_any() throws IOException { 50 | var input = """ 51 | create 52 | function 53 | f 54 | ( 55 | in_cursor 56 | in 57 | sys_refcursor 58 | ) 59 | return 60 | some_collection_type 61 | pipelined 62 | parallel_enable 63 | ( 64 | partition 65 | in_cursor 66 | by 67 | any 68 | ) 69 | is 70 | begin 71 | return; 72 | end; 73 | """; 74 | var actual = getFormatter().format(input); 75 | var expected = """ 76 | create function f( 77 | in_cursor in sys_refcursor 78 | ) 79 | return some_collection_type 80 | pipelined 81 | parallel_enable (partition in_cursor by any) 82 | is 83 | begin 84 | return; 85 | end; 86 | """; 87 | assertEquals(expected, actual); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Pipe_row_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Pipe_row_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void tokenized_pipe_row() throws IOException { 14 | var input = """ 15 | begin 16 | pipe 17 | row 18 | ( 19 | some_row 20 | ) 21 | ; 22 | end 23 | ; 24 | """; 25 | var actual = getFormatter().format(input); 26 | var expected = """ 27 | begin 28 | pipe row (some_row); 29 | end; 30 | """; 31 | assertEquals(expected, actual); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Procedure_declaration_and_definition.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Procedure_declaration_and_definition extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized_procedure_declaration() throws IOException { 21 | var input = """ 22 | create 23 | package 24 | pkg 25 | is 26 | procedure 27 | p 28 | ( 29 | a in integer 30 | ); 31 | end; 32 | """; 33 | var actual = getFormatter().format(input); 34 | var expected = """ 35 | create package pkg 36 | is 37 | procedure p( 38 | a in integer 39 | ); 40 | end; 41 | """; 42 | assertEquals(expected, actual); 43 | } 44 | 45 | @Test 46 | public void tokenized_procedure_definition() throws IOException { 47 | var input = """ 48 | create 49 | package 50 | body 51 | pkg 52 | is 53 | procedure 54 | p 55 | ( 56 | a in integer 57 | ) 58 | is 59 | begin 60 | null; 61 | end; 62 | end; 63 | """; 64 | var actual = getFormatter().format(input); 65 | var expected = """ 66 | create package body pkg 67 | is 68 | procedure p( 69 | a in integer 70 | ) 71 | is 72 | begin 73 | null; 74 | end; 75 | end; 76 | """; 77 | assertEquals(expected, actual); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Raise_statement.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Raise_statement extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized_raise_exception() throws IOException { 21 | var input = """ 22 | begin 23 | raise 24 | my_exception 25 | ; 26 | end 27 | ; 28 | """; 29 | var actual = getFormatter().format(input); 30 | var expected = """ 31 | begin 32 | raise my_exception; 33 | end; 34 | """; 35 | assertEquals(expected, actual); 36 | } 37 | 38 | @Test 39 | public void tokenized_raise() throws IOException { 40 | var input = """ 41 | begin 42 | raise 43 | ; 44 | end 45 | ; 46 | """; 47 | var actual = getFormatter().format(input); 48 | var expected = """ 49 | begin 50 | raise; 51 | end; 52 | """; 53 | assertEquals(expected, actual); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Restrict_references_pragma.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Restrict_references_pragma extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_14_11() throws IOException { 21 | var input = """ 22 | CREATE OR REPLACE PACKAGE finance AS 23 | FUNCTION compound_ ( 24 | years IN NUMBER, 25 | amount IN NUMBER, 26 | rate IN NUMBER 27 | ) RETURN NUMBER; 28 | PRAGMA RESTRICT_REFERENCES (compound_, WNDS, WNPS, RNDS, RNPS); 29 | END finance; 30 | / 31 | """; 32 | var actual = getFormatter().format(input); 33 | var expected = """ 34 | create or replace package finance as 35 | function compound_( 36 | years in number, 37 | amount in number, 38 | rate in number 39 | ) return number; 40 | pragma restrict_references(compound_, wnds, wnps, rnds, rnps); 41 | end finance; 42 | / 43 | """; 44 | assertEquals(expected, actual); 45 | } 46 | 47 | @Test 48 | public void tokenized() throws IOException { 49 | var input = """ 50 | create 51 | package 52 | pkg 53 | is 54 | pragma 55 | restrict_references 56 | ( 57 | default 58 | , 59 | rnds 60 | , 61 | wnds 62 | , 63 | rnps 64 | , 65 | wnps 66 | , 67 | trust 68 | ) 69 | ; 70 | end 71 | ; 72 | """; 73 | var actual = getFormatter().format(input); 74 | var expected = """ 75 | create package pkg 76 | is 77 | pragma restrict_references(default, rnds, wnds, rnps, wnps, trust); 78 | end; 79 | """; 80 | assertEquals(expected, actual); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Return_statement.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Return_statement extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized_return_expression() throws IOException { 21 | var input = """ 22 | begin 23 | return 24 | a 25 | * 26 | b 27 | / 28 | c 29 | ; 30 | end 31 | ; 32 | """; 33 | var actual = getFormatter().format(input); 34 | var expected = """ 35 | begin 36 | return a * b / c; 37 | end; 38 | """; 39 | assertEquals(expected, actual); 40 | } 41 | 42 | @Test 43 | public void tokenized_return() throws IOException { 44 | var input = """ 45 | begin 46 | return 47 | ; 48 | end 49 | ; 50 | """; 51 | var actual = getFormatter().format(input); 52 | var expected = """ 53 | begin 54 | return; 55 | end; 56 | """; 57 | assertEquals(expected, actual); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Rowtype_attribute.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Rowtype_attribute extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_6_41_simplified_tokenized() throws IOException { 21 | var input = """ 22 | DECLARE 23 | dept_rec 24 | departments 25 | % 26 | ROWTYPE 27 | ; 28 | BEGIN 29 | null; 30 | END; 31 | """; 32 | var actual = getFormatter().format(input); 33 | var expected = """ 34 | declare 35 | dept_rec departments%rowtype; 36 | begin 37 | null; 38 | end; 39 | """; 40 | assertEquals(expected, actual); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Select_into_statement.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Select_into_statement extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_3_25() throws IOException { 21 | var input = """ 22 | BEGIN 23 | SELECT salary * 0.10 INTO bonus 24 | FROM employees 25 | WHERE employee_id = 100; 26 | END; 27 | """; 28 | var actual = getFormatter().format(input); 29 | var expected = """ 30 | begin 31 | select salary * 0.10 into bonus 32 | from employees 33 | where employee_id = 100; 34 | end; 35 | """; 36 | assertEquals(expected, actual); 37 | } 38 | 39 | @Test 40 | public void example_3_16_tokenized() throws IOException { 41 | var input = """ 42 | BEGIN 43 | SELECT 44 | employee_id 45 | , 46 | last_name 47 | BULK 48 | COLLECT 49 | INTO 50 | enums 51 | , 52 | names 53 | FROM 54 | employees 55 | ORDER 56 | BY 57 | employee_id 58 | ; 59 | END; 60 | """; 61 | var actual = getFormatter().format(input); 62 | var expected = """ 63 | begin 64 | select employee_id, 65 | last_name 66 | bulk collect 67 | into enums, 68 | names 69 | from employees 70 | order by employee_id; 71 | end; 72 | """; 73 | assertEquals(expected, actual); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Serially_reusable_pragma.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Serially_reusable_pragma extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_11_4_tokenized() throws IOException { 21 | var input = """ 22 | CREATE OR REPLACE PACKAGE bodiless_pkg AUTHID DEFINER IS 23 | PRAGMA 24 | SERIALLY_REUSABLE 25 | ; 26 | n NUMBER := 5; 27 | END; 28 | / 29 | """; 30 | var actual = getFormatter().format(input); 31 | var expected = """ 32 | create or replace package bodiless_pkg authid definer is 33 | pragma serially_reusable; 34 | n number := 5; 35 | end; 36 | / 37 | """; 38 | assertEquals(expected, actual); 39 | } 40 | 41 | @Test 42 | public void tokenized() throws IOException { 43 | var input = """ 44 | create 45 | package 46 | pkg 47 | is 48 | pragma 49 | restrict_references 50 | ( 51 | default 52 | , 53 | rnds 54 | , 55 | wnds 56 | , 57 | rnps 58 | , 59 | wnps 60 | , 61 | trust 62 | ) 63 | ; 64 | end 65 | ; 66 | """; 67 | var actual = getFormatter().format(input); 68 | var expected = """ 69 | create package pkg 70 | is 71 | pragma restrict_references(default, rnds, wnds, rnps, wnps, trust); 72 | end; 73 | """; 74 | assertEquals(expected, actual); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Sharing_clause.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Sharing_clause extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized_metadata() throws IOException { 21 | var input = """ 22 | CREATE 23 | VIEW v 24 | SHARING 25 | = 26 | METADATA 27 | AS 28 | SELECT 29 | * 30 | FROM 31 | t 32 | ; 33 | """; 34 | var actual = getFormatter().format(input); 35 | var expected = """ 36 | create view v 37 | sharing = metadata 38 | as 39 | select * 40 | from t; 41 | """; 42 | assertEquals(expected, actual); 43 | } 44 | 45 | @Test 46 | public void tokenized_none() throws IOException { 47 | var input = """ 48 | CREATE 49 | VIEW v 50 | SHARING 51 | = 52 | NONE 53 | AS 54 | SELECT 55 | * 56 | FROM 57 | t 58 | ; 59 | """; 60 | var actual = getFormatter().format(input); 61 | var expected = """ 62 | create view v 63 | sharing = none 64 | as 65 | select * 66 | from t; 67 | """; 68 | assertEquals(expected, actual); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Sqlerrm_function.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Sqlerrm_function extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized() throws IOException { 21 | var input = """ 22 | BEGIN 23 | DBMS_OUTPUT.PUT_LINE('SQLERRM(-6511): ' || TO_CHAR( 24 | SQLERRM 25 | ( 26 | -6511 27 | ) 28 | )); 29 | END; 30 | / 31 | """; 32 | var actual = getFormatter().format(input); 33 | var expected = """ 34 | begin 35 | dbms_output.put_line('SQLERRM(-6511): ' || to_char(sqlerrm(-6511))); 36 | end; 37 | / 38 | """; 39 | assertEquals(expected, actual); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Suppresses_warning_6009_pragma.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Suppresses_warning_6009_pragma extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized() throws IOException { 21 | var input = """ 22 | CREATE PROCEDURE p1 23 | AUTHID DEFINER 24 | IS 25 | PRAGMA 26 | SUPPRESSES_WARNING_6009 27 | ( 28 | p1 29 | ) 30 | ; 31 | BEGIN 32 | RAISE_APPLICATION_ERROR(-20000, 'Unexpected error raised'); 33 | END; 34 | / 35 | """; 36 | var actual = getFormatter().format(input); 37 | var expected = """ 38 | create procedure p1 39 | authid definer 40 | is 41 | pragma suppresses_warning_6009 (p1); 42 | begin 43 | raise_application_error(-20000, 'Unexpected error raised'); 44 | end; 45 | / 46 | """; 47 | assertEquals(expected, actual); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Type_attribute.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Type_attribute extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_3_15_tokenized() throws IOException { 21 | var input = """ 22 | DECLARE 23 | surname 24 | employees 25 | . 26 | last_name 27 | % 28 | TYPE 29 | ; 30 | BEGIN 31 | DBMS_OUTPUT.PUT_LINE('surname=' || surname); 32 | END; 33 | / 34 | """; 35 | var actual = getFormatter().format(input); 36 | var expected = """ 37 | declare 38 | surname employees.last_name%type; 39 | begin 40 | dbms_output.put_line('surname=' || surname); 41 | end; 42 | / 43 | """; 44 | assertEquals(expected, actual); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Udf_pragma.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Udf_pragma extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void tokenized() throws IOException { 21 | var input = """ 22 | create function f(in_str in varchar2) return varchar2 23 | as 24 | pragma 25 | udf 26 | ; 27 | begin 28 | return upper(in_str); 29 | end; 30 | / 31 | """; 32 | var actual = getFormatter().format(input); 33 | var expected = """ 34 | create function f(in_str in varchar2) return varchar2 35 | as 36 | pragma udf; 37 | begin 38 | return upper(in_str); 39 | end; 40 | / 41 | """; 42 | assertEquals(expected, actual); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/Update_statement_extensions.java: -------------------------------------------------------------------------------- 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.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Update_statement_extensions extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void example_6_61_tokenized() throws IOException { 21 | var input = """ 22 | DECLARE 23 | default_week schedule%ROWTYPE; 24 | BEGIN 25 | default_week.Mon := 'Day Off'; 26 | default_week.Tue := '0900-1800'; 27 | default_week.Wed := '0900-1800'; 28 | default_week.Thu := '0900-1800'; 29 | default_week.Fri := '0900-1800'; 30 | default_week.Sat := '0900-1800'; 31 | default_week.Sun := 'Day Off'; 32 | 33 | FOR i IN 1..3 LOOP 34 | default_week.week := i; 35 | 36 | UPDATE schedule 37 | SET 38 | ROW 39 | = 40 | default_week 41 | WHERE week = i; 42 | END LOOP; 43 | END; 44 | / 45 | """; 46 | var actual = getFormatter().format(input); 47 | var expected = """ 48 | declare 49 | default_week schedule%rowtype; 50 | begin 51 | default_week.mon := 'Day Off'; 52 | default_week.tue := '0900-1800'; 53 | default_week.wed := '0900-1800'; 54 | default_week.thu := '0900-1800'; 55 | default_week.fri := '0900-1800'; 56 | default_week.sat := '0900-1800'; 57 | default_week.sun := 'Day Off'; 58 | 59 | for i in 1..3 60 | loop 61 | default_week.week := i; 62 | 63 | update schedule 64 | set row = default_week 65 | where week = i; 66 | end loop; 67 | end; 68 | / 69 | """; 70 | assertEquals(expected, actual); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/grammar/plsql/While_loop_statement.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.grammar.plsql; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class While_loop_statement extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void example_14_47_tokenized() throws IOException { 14 | var input = """ 15 | DECLARE 16 | done BOOLEAN := FALSE; 17 | BEGIN 18 | WHILE 19 | done 20 | LOOP 21 | DBMS_OUTPUT 22 | . 23 | PUT_LINE 24 | ( 25 | 'This line does not print.' 26 | ) 27 | ; 28 | done 29 | : 30 | = 31 | TRUE; -- This assignment is not made. 32 | END 33 | LOOP 34 | ; 35 | 36 | WHILE 37 | NOT 38 | done 39 | LOOP 40 | DBMS_OUTPUT 41 | . 42 | PUT_LINE 43 | ( 44 | 'Hello, world!' 45 | ) 46 | ; 47 | done 48 | : 49 | = 50 | TRUE; 51 | END 52 | LOOP 53 | ; 54 | END; 55 | / 56 | """; 57 | var actual = getFormatter().format(input); 58 | var expected = """ 59 | declare 60 | done boolean := false; 61 | begin 62 | while done 63 | loop 64 | DBMS_OUTPUT.PUT_LINE('This line does not print.'); 65 | done := 66 | true; -- This assignment is not made. 67 | end loop; 68 | 69 | while not done 70 | loop 71 | DBMS_OUTPUT.PUT_LINE('Hello, world!'); 72 | done := 73 | true; 74 | end loop; 75 | end; 76 | / 77 | """; 78 | assertEquals(expected, actual); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_114_honor_no_space_after_commas_config.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | import java.io.IOException; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Issue_114_honor_no_space_after_commas_config extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 17 | } 18 | 19 | @Test 20 | public void no_space_after_comma() throws IOException { 21 | setOption(getFormatter().spaceAfterCommas, false); 22 | var input = """ 23 | select empno 24 | , nvl(mgr, 0) as mgr 25 | , ename 26 | from emp e; 27 | """; 28 | var expected = """ 29 | select empno 30 | ,nvl(mgr,0) as mgr 31 | ,ename 32 | from emp e; 33 | """; 34 | var actual = getFormatter().format(input); 35 | assertEquals(expected, actual); 36 | } 37 | 38 | @Test 39 | public void space_after_comma() throws IOException { 40 | setOption(getFormatter().spaceAfterCommas, true); 41 | var input = """ 42 | select empno 43 | ,nvl(mgr,0) as mgr 44 | ,ename 45 | from emp e; 46 | """; 47 | var expected = """ 48 | select empno 49 | , nvl(mgr, 0) as mgr 50 | , ename 51 | from emp e; 52 | """; 53 | var actual = getFormatter().format(input); 54 | assertEquals(expected, actual); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_129_in_out_parameter.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_129_in_out_parameter extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void keep_in_out_mode_on_same_line() throws IOException { 14 | var input = """ 15 | create or replace procedure dummy( 16 | a in 17 | out varchar2, 18 | b in 19 | out number 20 | ) is 21 | --BEFORE EACH ROW 22 | begin 23 | null; 24 | end; 25 | """; 26 | var expected = """ 27 | create or replace procedure dummy( 28 | a in out varchar2, 29 | b in out number 30 | ) is 31 | --BEFORE EACH ROW 32 | begin 33 | null; 34 | end; 35 | """; 36 | var actual = getFormatter().format(input); 37 | assertEquals(expected, actual); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_13_do_not_right_align_set.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.BeforeAll; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_13_do_not_right_align_set extends ConfiguredTestFormatter { 10 | 11 | @BeforeAll 12 | public void setup() { 13 | setOption(getFormatter().identSpaces, 4); 14 | } 15 | 16 | @Test 17 | public void original_case_with_unnecessary_semicolon_for_set() { 18 | var sql = """ 19 | set echo off; 20 | 21 | create or replace package body emp_mgmt as 22 | 23 | function hire( 24 | last_name in varchar2, 25 | job_id in varchar2, 26 | manager_id in number, 27 | salary in number, 28 | department_id in number 29 | ) return number is 30 | new_empno number(16, 0); 31 | begin 32 | --some code 33 | return (new_empno); 34 | end; 35 | 36 | end emp_mgmt; 37 | / 38 | 39 | set echo on 40 | """; 41 | formatAndAssert(sql); 42 | } 43 | 44 | @Test 45 | public void simplified_case() { 46 | var sql = """ 47 | set echo off 48 | 49 | select * 50 | from dual; 51 | 52 | set echo on 53 | """; 54 | formatAndAssert(sql); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_150_define.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import oracle.dbtools.parser.plsql.SyntaxError; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.TestInstance; 10 | 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | public class Issue_150_define extends ConfiguredTestFormatter { 13 | 14 | @BeforeAll 15 | public void setup_non_trivadis_default_settings() { 16 | setOption(getFormatter().idCase, Format.Case.lower); 17 | } 18 | 19 | @Test 20 | public void set_define_after_at_command() { 21 | // in SQLDev 21.2.1 SET is part of the @ command 22 | // As a result DEFINE becomes a command, and it starts on a new line 23 | // Same behavior with START as with @. 24 | // Fixed in SQLDev 21.4.0. 25 | // Syntax error in SQLcl 23.1.0 26 | // Fixed in SQLcl 24.0.0 27 | var sql = """ 28 | define table_folder = 'table' 29 | set define on 30 | @./demo/&&table_folder/drop_demo_tables.sql 31 | set define off 32 | """; 33 | formatAndAssert(sql); 34 | } 35 | 36 | @Test 37 | public void commit_after_at_command() { 38 | // workaround for SQLcl 22.2.1 up to 22.4.0 does not work anymore 39 | // Syntax error in SQLcl 23.1.0 40 | // new workaround is to use start instead of @ and no "./" 41 | var sql = """ 42 | define table_folder = 'table' 43 | set define on 44 | start demo/&&table_folder/drop_demo_tables.sql 45 | set define off 46 | """; 47 | formatAndAssert(sql); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_152_extract.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_152_extract extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void extract_from() { 12 | var sql = """ 13 | select e.last_name, e.first_name, d.department_name 14 | from employees e 15 | join departments d 16 | on e.department_id = d.department_id 17 | where extract(month from e.hire_date) = extract(month from sysdate); 18 | """; 19 | formatAndAssert(sql); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_167_leading_commas_and_comments.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.*; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_METHOD) 8 | public class Issue_167_leading_commas_and_comments extends ConfiguredTestFormatter { 9 | 10 | @BeforeEach 11 | public void setup() { 12 | setOption(getFormatter().idCase, Format.Case.lower); 13 | } 14 | 15 | @AfterEach 16 | public void teardown() { 17 | resetOptions(); 18 | } 19 | 20 | @Test 21 | public void leading_commas() { 22 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 23 | var sql = """ 24 | create or replace package test_pkg authid definer as 25 | 26 | procedure proc( 27 | p_segment1 in varchar2 28 | -- comment 1 29 | , p_segment2 in varchar2 30 | , p_segment3 in varchar2 31 | /* comment 2 */ 32 | , x_status out nocopy varchar2 33 | ); 34 | 35 | end test_pkg; 36 | """; 37 | formatAndAssert(sql); 38 | } 39 | 40 | @Test 41 | public void trailing_commas() { 42 | setOption(getFormatter().breaksComma, Format.Breaks.After); 43 | var sql = """ 44 | create or replace package test_pkg authid definer as 45 | 46 | procedure proc( 47 | p_segment1 in varchar2, 48 | -- comment 1 49 | p_segment2 in varchar2, 50 | p_segment3 in varchar2, 51 | /* comment 2 */ 52 | x_status out nocopy varchar2 53 | ); 54 | 55 | end test_pkg; 56 | """; 57 | formatAndAssert(sql); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_188_remove_line_break_after_update.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_188_remove_line_break_after_update extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void update_tokenized() throws IOException { 14 | var input = """ 15 | update 16 | emp 17 | set 18 | sal 19 | = 20 | sal 21 | + 22 | 10 23 | where 24 | sal 25 | < 3000 26 | ; 27 | """; 28 | var expected = """ 29 | update emp 30 | set sal = sal + 10 31 | where sal < 3000; 32 | """; 33 | var actual = getFormatter().format(input); 34 | assertEquals(expected, actual); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_189_indent_private_plsql_unit_in_type.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_189_indent_private_plsql_unit_in_type extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void plsql_unit_in_constructor() throws IOException { 14 | var input = """ 15 | create or replace type body my_ot as 16 | constructor function my_ot( 17 | self in out nocopy guess_ot, 18 | in_p1 in integer 19 | ) return self as result is 20 | procedure private_stuff is 21 | begin 22 | null; 23 | end private_stuff; 24 | begin 25 | private_stuff; 26 | return; 27 | end my_ot; 28 | end; 29 | / 30 | """; 31 | var expected = """ 32 | create or replace type body my_ot as 33 | constructor function my_ot( 34 | self in out nocopy guess_ot, 35 | in_p1 in integer 36 | ) return self as result is 37 | procedure private_stuff is 38 | begin 39 | null; 40 | end private_stuff; 41 | begin 42 | private_stuff; 43 | return; 44 | end my_ot; 45 | end; 46 | / 47 | """; 48 | var actual = getFormatter().format(input); 49 | assertEquals(expected, actual); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_1_json_case_sensitive.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_1_json_case_sensitive extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void json_dot_notation() { 12 | var sql = """ 13 | create table t ( 14 | c clob check (c is json) 15 | ); 16 | 17 | insert into t values ('{accountNumber:123, accountName:"Name", accountType:"A"}'); 18 | 19 | column accountNumber format a15 20 | column accountName format a15 21 | column accountType format a10 22 | 23 | select j.c.accountNumber, 24 | j.c.accountName, 25 | j.c.accountType 26 | from t j 27 | where j.c.accountType = 'A'; 28 | 29 | drop table t purge; 30 | """; 31 | formatAndAssert(sql); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_204_lost_line_break_after_label.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_204_lost_line_break_after_label extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void line_break_after_label() { 12 | var sql = """ 13 | create or replace package body pkg is 14 | procedure p is 15 | co_errno constant simple_integer := -20501; 16 | begin 17 | <> 18 | null; 19 | end; 20 | end; 21 | """; 22 | formatAndAssert(sql); 23 | } 24 | 25 | @Test 26 | public void space_after_label() { 27 | var sql = """ 28 | create or replace package body pkg is 29 | procedure p is 30 | co_errno constant simple_integer := -20501; 31 | begin 32 | <> null; 33 | end; 34 | end; 35 | """; 36 | formatAndAssert(sql); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_205_lost_space_after_equal_sign.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_205_lost_space_after_equal_sign extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void line_break_after_label() { 12 | var sql = """ 13 | declare 14 | co_no_data_found constant integer := -1; 15 | begin 16 | my_package.some_processing(); -- some code which raises an exception 17 | exception 18 | when too_many_rows then 19 | my_package.some_further_processing(); 20 | when others then 21 | if sqlcode = co_no_data_found then 22 | null; 23 | end if; 24 | end; 25 | / 26 | """; 27 | formatAndAssert(sql); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_210_indent_insert_select.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_210_indent_insert_select extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void single_table_insert() { 12 | var sql = """ 13 | insert into deptsal (dept_no, dept_name, salary) 14 | select d.deptno, d.dname, sum(e.sal + nvl(e.comm, 0)) as sal 15 | from dept d 16 | left join ( 17 | select * 18 | from emp 19 | where hiredate > date '1980-01-01' 20 | ) e 21 | on e.deptno = d.deptno 22 | group by d.deptno, d.dname; 23 | """; 24 | formatAndAssert(sql); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_214_lost_line_breaks_in_values_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.TestInstance; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_214_lost_line_breaks_in_values_clause extends ConfiguredTestFormatter { 11 | 12 | @BeforeAll 13 | public void setup_non_trivadis_default_settings() { 14 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 15 | setOption(getFormatter().spaceAfterCommas, false); 16 | } 17 | 18 | @Test 19 | public void insert() { 20 | var sql = """ 21 | insert into departments_log ( 22 | department_id 23 | ,department_name 24 | ,modification_date) 25 | values (:old.department_id 26 | ,:old.department_name 27 | ,sysdate); 28 | """; 29 | formatAndAssert(sql); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_216_case_expr_create_table.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_216_case_expr_create_table extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void create_table() { 12 | var sql = """ 13 | create table letters ( 14 | letter varchar2(1 char) not null constraint letters_pk primary key, 15 | occurrences integer not null, 16 | is_vowel integer generated always as ( 17 | case 18 | when letter in ('a', 'e', 'i', 'o', 'u') then 19 | 1 20 | else 21 | 0 22 | end 23 | ) virtual 24 | ); 25 | """; 26 | formatAndAssert(sql); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_218_indent_column_aliases_with_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_218_indent_column_aliases_with_clause extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void with_clause() { 12 | var sql = """ 13 | with 14 | employees ( 15 | id, 16 | name, 17 | salary 18 | ) as ( 19 | select empno, 20 | ename, 21 | sal 22 | from emp 23 | ) 24 | select * 25 | from employees; 26 | """; 27 | formatAndAssert(sql); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_21_line_open_cursor_for.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_21_line_open_cursor_for extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void cursor_for() { 12 | var sql = """ 13 | begin 14 | open c1 for 15 | select * 16 | from same_tab; 17 | end; 18 | / 19 | """; 20 | formatAndAssert(sql); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_220_indent_comment_before_case.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_220_indent_comment_before_case extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void comment_before_first_when() { 12 | var sql = """ 13 | select case 14 | -- single line comment 15 | when dummy = 'X' then 16 | 'YES' 17 | else 18 | 'NO' 19 | end as new_dummy 20 | from dummy; 21 | """; 22 | formatAndAssert(sql); 23 | } 24 | 25 | @Test 26 | public void comment_before_second_when() { 27 | var sql = """ 28 | select case 29 | when dummy = 'X' then 30 | 'YES' 31 | -- single line comment 32 | when dummy = 'X' then 33 | 'YES' 34 | else 35 | 'NO' 36 | end as new_dummy 37 | from dummy; 38 | """; 39 | formatAndAssert(sql); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_256_linebreak_in_string.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | import java.io.IOException; 9 | 10 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 11 | @Disabled("Bug in SQLDev 23.1.1.345, SQLcl 23.3.0, SQLcl 23.4.0") 12 | public class Issue_256_linebreak_in_string extends ConfiguredTestFormatter { 13 | @Test 14 | public void escaped_entity_in_string() throws IOException { 15 | var input = """ 16 | begin 17 | dbms_output.put_line('</'); 18 | end; 19 | / 20 | """; 21 | var expected = """ 22 | begin 23 | dbms_output.put_line('</'); 24 | end; 25 | / 26 | """; 27 | var actual = getFormatter().format(input); 28 | assertEquals(expected, actual); 29 | } 30 | 31 | @Test 32 | public void semi_slash_in_string() throws IOException { 33 | var input = """ 34 | begin 35 | dbms_output.put_line(';/'); 36 | end; 37 | / 38 | """; 39 | var expected = """ 40 | begin 41 | dbms_output.put_line(';/'); 42 | end; 43 | / 44 | """; 45 | var actual = getFormatter().format(input); 46 | assertEquals(expected, actual); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_264_exit_in_whenever_oserror.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_264_exit_in_whenever_oserror extends ConfiguredTestFormatter { 9 | @Test 10 | public void exit_in_whenever_os_error() { 11 | var input = """ 12 | whenever sqlerror exit failure 13 | whenever oserror exit failure 14 | select * from dual; 15 | """; 16 | formatAndAssert(input); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_266_line_break_on_conversion_error.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_266_line_break_on_conversion_error extends ConfiguredTestFormatter { 9 | @Test 10 | public void subquery_with_on_conversion_error() { 11 | var input = """ 12 | select * 13 | from ( 14 | select to_number( 15 | sys_context('userenv', 'current_schemaid') default null on conversion error, 16 | '99999990', 17 | q'[nls_numeric_characters='.,']' 18 | ) as model_id 19 | from dual 20 | ); 21 | """; 22 | formatAndAssert(input); 23 | } 24 | 25 | @Test 26 | public void subquery_with_on_conversion_error_with_line_breaks() { 27 | var input = """ 28 | select * 29 | from ( 30 | select to_number( 31 | sys_context('userenv', 'current_schemaid') 32 | default 33 | null 34 | on 35 | conversion 36 | error, 37 | '99999990', 38 | q'[nls_numeric_characters='.,']' 39 | ) as model_id 40 | from dual 41 | ); 42 | """; 43 | formatAndAssert(input); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_267_spaces_in_grant.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_267_spaces_in_grant extends ConfiguredTestFormatter { 9 | @Test 10 | public void keep_spaces_in_grant_statements() { 11 | var input = """ 12 | grant debug connect session to scott; 13 | grant debug any procedure to scott; 14 | grant execute on dbms_debug_jdwp to scott; 15 | """; 16 | formatAndAssert(input); 17 | } 18 | 19 | @Test 20 | public void keep_spaces_in_grant_statements_one_token_per_line() { 21 | var input = """ 22 | grant 23 | debug 24 | connect 25 | session 26 | to 27 | scott; 28 | 29 | grant 30 | debug 31 | any 32 | procedure 33 | to 34 | scott; 35 | 36 | grant 37 | execute 38 | on 39 | dbms_debug_jdwp 40 | to 41 | scott; 42 | """; 43 | formatAndAssert(input); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_26_create_tablespace.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_26_create_tablespace extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void create_smallfile_tablespace_one_datafile() { 12 | var sql = """ 13 | create tablespace my_table_space 14 | datafile 'my_tablespace_file.dbf' size 50m 15 | autoextend on next 10m maxsize unlimited 16 | extent management local autoallocate; 17 | """; 18 | formatAndAssert(sql); 19 | } 20 | 21 | @Test 22 | public void create_smallfile_tablespace_three_datafiles() { 23 | var sql = """ 24 | create smallfile tablespace demo 25 | datafile '/u01/app/oracle/oradata/ODB/demo1.dbf' size 5m, 26 | '/u01/app/oracle/oradata/ODB/demp2.dbf' size 5m, 27 | '/u01/app/oracle/oradata/ODB/demp3.dbf' size 5m 28 | autoextend on next 10m maxsize unlimited 29 | extent management local autoallocate; 30 | """; 31 | formatAndAssert(sql); 32 | } 33 | 34 | @Test 35 | public void drop_tablepace() { 36 | var sql = """ 37 | drop tablespace demo including contents; 38 | """; 39 | formatAndAssert(sql); 40 | } 41 | 42 | @Test 43 | public void create_oracle_managed_tablepsace() { 44 | var sql = """ 45 | create tablespace demo 46 | datafile 47 | autoextend off; 48 | """; 49 | formatAndAssert(sql); 50 | } 51 | 52 | @Test 53 | public void create_bigfile_tablespace() { 54 | var sql = """ 55 | create bigfile tablespace bigtbs_01 56 | datafile 'bigtbs_f1.dbf' size 20m 57 | autoextend on; 58 | """; 59 | formatAndAssert(sql); 60 | } 61 | 62 | @Test 63 | public void create_undo_tablespace() { 64 | var sql = """ 65 | create undo tablespace undots1 66 | datafile 'undotbs_1a.dbf' size 10m 67 | autoextend on 68 | retention guarantee; 69 | """; 70 | formatAndAssert(sql); 71 | } 72 | 73 | @Test 74 | public void create_temp_tablespace() { 75 | var sql = """ 76 | create temporary tablespace tbs_temp_02 77 | tempfile 'temp02.dbf' size 5m 78 | autoextend on 79 | tablespace group tbs_grp_01; 80 | """; 81 | formatAndAssert(sql); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_29_not_in.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_29_not_in extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void commas_after() { 13 | var sql = """ 14 | select * 15 | from dba_tables 16 | where table_name in ( 17 | select queue_table 18 | from dba_queue_tables 19 | ) 20 | and (owner, table_name) not in ( 21 | select owner, 22 | name 23 | from dba_snapshots 24 | ) 25 | and temporary = 'N' 26 | order by blocks desc; 27 | """; 28 | formatAndAssert(sql); 29 | } 30 | 31 | @Test 32 | public void commas_before() { 33 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 34 | var sql = """ 35 | select * 36 | from dba_tables 37 | where table_name in ( 38 | select queue_table 39 | from dba_queue_tables 40 | ) 41 | and (owner, table_name) not in ( 42 | select owner 43 | , name 44 | from dba_snapshots 45 | ) 46 | and temporary = 'N' 47 | order by blocks desc; 48 | """; 49 | formatAndAssert(sql); 50 | setOption(getFormatter().breaksComma, Format.Breaks.After); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_30_into_clause.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_30_into_clause extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void into_clause_commas_after() { 13 | var sql = """ 14 | select namespace, 15 | key, 16 | scope 17 | into l_namespace, 18 | l_key, 19 | l_scope 20 | from configuration 21 | where id = p_id; 22 | """; 23 | formatAndAssert(sql); 24 | } 25 | 26 | @Test 27 | public void into_clause_commas_before() { 28 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 29 | var sql = """ 30 | select namespace 31 | , key 32 | , scope 33 | into l_namespace 34 | , l_key 35 | , l_scope 36 | from configuration 37 | where id = p_id; 38 | """; 39 | formatAndAssert(sql); 40 | setOption(getFormatter().breaksComma, Format.Breaks.After); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_53_comma_before_without_ws.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_53_comma_before_without_ws extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void commas_before_no_ws() { 13 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 14 | setOption(getFormatter().spaceAfterCommas, false); 15 | var sql = """ 16 | begin 17 | for rec in ( 18 | select r.country_region as region 19 | ,p.prod_category 20 | ,sum(s.amount_sold) as amount_sold 21 | from sales s 22 | join products p 23 | on p.prod_id = s.prod_id 24 | join customers cust 25 | on cust.cust_id = s.cust_id 26 | join times t 27 | on t.time_id = s.time_id 28 | join countries r 29 | on r.country_id = cust.country_id 30 | where calendar_year = 2000 31 | group by r.country_region 32 | ,p.prod_category 33 | order by r.country_region 34 | ,p.prod_category 35 | ) 36 | loop 37 | if rec.region = 'Asia' then 38 | if rec.prod_category = 'Hardware' then 39 | /* print only one line for demo purposes */ 40 | sys.dbms_output.put_line('Amount: ' || rec.amount_sold); 41 | end if; 42 | end if; 43 | end loop; 44 | end; 45 | / 46 | """; 47 | formatAndAssert(sql); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_54_align_table_alias.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_54_align_table_alias extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void align_table_alias() { 12 | setOption(getFormatter().alignTabColAliases, true); 13 | var sql = """ 14 | begin 15 | for rec in ( 16 | select r.country_region as region, 17 | p.prod_category, 18 | sum(s.amount_sold) as amount_sold 19 | from sales s 20 | join products p 21 | on p.prod_id = s.prod_id 22 | join customers cust 23 | on cust.cust_id = s.cust_id 24 | join times t 25 | on t.time_id = s.time_id 26 | join countries r 27 | on r.country_id = cust.country_id 28 | where calendar_year = 2000 29 | group by r.country_region, 30 | p.prod_category 31 | order by r.country_region, 32 | p.prod_category 33 | ) 34 | loop 35 | if rec.region = 'Asia' then 36 | if rec.prod_category = 'Hardware' then 37 | /* print only one line for demo purposes */ 38 | sys.dbms_output.put_line('Amount: ' || rec.amount_sold); 39 | end if; 40 | end if; 41 | end loop; 42 | end; 43 | / 44 | """; 45 | formatAndAssert(sql); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_57_xmltable.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_57_xmltable extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void xmltable_commas_after() { 13 | var sql = """ 14 | select stg.payload_type, 15 | xt_hdr.* 16 | from stg, 17 | xmltable( 18 | '/XML/Header' 19 | passing xmltype.createxml(stg.xml_payload) 20 | columns source varchar2(50) path 'Source', 21 | action_type varchar2(50) path 'Action_Type', 22 | message_type varchar2(40) path 'Message_Type', 23 | company_id number path 'Company_ID' 24 | ) hdr; 25 | """; 26 | formatAndAssert(sql); 27 | } 28 | 29 | @Test 30 | public void xmltable_commas_before() { 31 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 32 | var sql = """ 33 | select stg.payload_type 34 | , xt_hdr.* 35 | from stg 36 | , xmltable( 37 | '/XML/Header' 38 | passing xmltype.createxml(stg.xml_payload) 39 | columns source varchar2(50) path 'Source' 40 | , action_type varchar2(50) path 'Action_Type' 41 | , message_type varchar2(40) path 'Message_Type' 42 | , company_id number path 'Company_ID' 43 | ) hdr; 44 | """; 45 | formatAndAssert(sql); 46 | setOption(getFormatter().breaksComma, Format.Breaks.After); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_62_xmlquery.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_62_xmlquery extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void xquery_commas_after() { 13 | var sql = """ 14 | create or replace function get_dep_cols( 15 | in_parse_tree in xmltype, 16 | in_column_pos in integer 17 | ) return xmltype is 18 | l_result xmltype; 19 | begin 20 | select xmlquery(q'{ 21 | ... 22 | }' 23 | passing in_parse_tree, in_column_pos as "columnPos" 24 | returning content 25 | ) 26 | into l_result 27 | from dual; 28 | return l_result; 29 | end; 30 | / 31 | """; 32 | formatAndAssert(sql); 33 | } 34 | 35 | @Test 36 | public void xquery_commas_before() { 37 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 38 | var sql = """ 39 | create or replace function get_dep_cols( 40 | in_parse_tree in xmltype 41 | , in_column_pos in integer 42 | ) return xmltype is 43 | l_result xmltype; 44 | begin 45 | select xmlquery(q'{ 46 | ... 47 | }' 48 | passing in_parse_tree, in_column_pos as "columnPos" 49 | returning content 50 | ) 51 | into l_result 52 | from dual; 53 | return l_result; 54 | end; 55 | / 56 | """; 57 | formatAndAssert(sql); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_64_update.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class Issue_64_update extends ConfiguredTestFormatter { 10 | 11 | @Test 12 | public void update_commas_after() { 13 | var sql = """ 14 | update my_table 15 | set n01 = 1, 16 | n02 = 2, 17 | n03 = 3, 18 | n04 = my_function(1, 2, 3) 19 | where n01 = 1 20 | and n02 = 2 21 | and n03 = my_function(1, 2, 3); 22 | """; 23 | formatAndAssert(sql); 24 | } 25 | 26 | @Test 27 | public void update_commas_before() { 28 | setOption(getFormatter().breaksComma, Format.Breaks.Before); 29 | var sql = """ 30 | update my_table 31 | set n01 = 1 32 | , n02 = 2 33 | , n03 = 3 34 | , n04 = my_function(1, 2, 3) 35 | where n01 = 1 36 | and n02 = 2 37 | and n03 = my_function(1, 2, 3); 38 | """; 39 | formatAndAssert(sql); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_6_max_one_empty_line.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import oracle.dbtools.app.Format; 5 | import org.junit.jupiter.api.*; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_6_max_one_empty_line extends ConfiguredTestFormatter { 11 | 12 | @BeforeAll 13 | public void setup() { 14 | setOption(getFormatter().kwCase, Format.Case.NoCaseChange); 15 | } 16 | 17 | @Test 18 | public void pkg() throws IOException { 19 | var input = """ 20 | /* 21 | * comment before pkg 22 | */ 23 | create or replace package pkg is 24 | 25 | 26 | /* 27 | * pkg 28 | */ 29 | 30 | 31 | 32 | /* 33 | * p1 34 | */ 35 | procedure p1; 36 | procedure p2; 37 | 38 | 39 | procedure p3; 40 | 41 | 42 | -- p4 (1) 43 | 44 | 45 | 46 | -- p4 (2) 47 | 48 | 49 | 50 | procedure p4; 51 | 52 | 53 | -- p5 54 | procedure p5; 55 | 56 | end pkg; 57 | / 58 | """; 59 | var expected = """ 60 | /* 61 | * comment before pkg 62 | */ 63 | create or replace package pkg is 64 | 65 | /* 66 | * pkg 67 | */ 68 | 69 | /* 70 | * p1 71 | */ 72 | procedure p1; 73 | procedure p2; 74 | 75 | procedure p3; 76 | 77 | -- p4 (1) 78 | 79 | -- p4 (2) 80 | 81 | procedure p4; 82 | 83 | -- p5 84 | procedure p5; 85 | 86 | end pkg; 87 | / 88 | """.trim(); 89 | var actual = getFormatter().format(input); 90 | Assertions.assertEquals(expected, actual); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_81_boolean_conditions_and_parenthesis.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class Issue_81_boolean_conditions_and_parenthesis extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void sql_condition_single_line() throws IOException { 14 | var input = """ 15 | select * from dba_tables where (owner = 'SYSTEM' and (table_name = 'REDO_DB' or table_name = 'REDO_LOG')) or (owner = 'SYS' and (table_name = 'ALERT_QT' or table_name = 'ALL_UNIFIED_AUDIT_ACTIONS')); 16 | """; 17 | var expected = """ 18 | select * 19 | from dba_tables 20 | where (owner = 'SYSTEM' and (table_name = 'REDO_DB' or table_name = 'REDO_LOG')) 21 | or (owner = 'SYS' and (table_name = 'ALERT_QT' or table_name = 'ALL_UNIFIED_AUDIT_ACTIONS')); 22 | """; 23 | var actual = getFormatter().format(input); 24 | assertEquals(expected, actual); 25 | } 26 | 27 | @Test 28 | public void plsql_expr_single_line() throws IOException { 29 | var input = """ 30 | begin if((1=2)or((2=2 and 3=3)or(4=5)))then dbms_output.put_line('Yes');end if;end; 31 | """; 32 | var expected = """ 33 | begin 34 | if ((1 = 2) or ((2 = 2 and 3 = 3) or (4 = 5))) then 35 | dbms_output.put_line('Yes'); 36 | end if; 37 | end; 38 | """; 39 | var actual = getFormatter().format(input); 40 | assertEquals(expected, actual); 41 | } 42 | 43 | @Test 44 | public void plsql_expr_multiline() throws IOException { 45 | var input = """ 46 | begin 47 | if ( ( variable1 = variable2 ) or ( ( 48 | variable2 = variable2 and variable3 = variable3 49 | ) or ( variable4 = variable5 ) ) ) then 50 | dbms_output.put_line('Yes'); 51 | end if; 52 | end; 53 | """; 54 | var expected = """ 55 | begin 56 | if ((variable1 = variable2) or (( 57 | variable2 = variable2 and variable3 = variable3 58 | ) or (variable4 = variable5))) 59 | then 60 | dbms_output.put_line('Yes'); 61 | end if; 62 | end; 63 | """; 64 | var actual = getFormatter().format(input); 65 | assertEquals(expected, actual); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_82_outer_apply.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_82_outer_apply extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void bulk_collect_outer_apply() { 12 | var sql = """ 13 | declare 14 | l_array my_array_tab; 15 | begin 16 | select t.a, 17 | t.b, 18 | t.c, 19 | n.stuff 20 | bulk collect 21 | into l_array 22 | from some_table s 23 | outer apply (s.nested_tab) n; 24 | end; 25 | / 26 | """; 27 | formatAndAssert(sql); 28 | } 29 | 30 | @Test 31 | public void bulk_collect_cross_apply() { 32 | var sql = """ 33 | declare 34 | l_array my_array_tab; 35 | begin 36 | select t.a, 37 | t.b, 38 | t.c, 39 | n.stuff 40 | bulk collect 41 | into l_array 42 | from some_table s 43 | cross apply (s.nested_tab) n; 44 | end; 45 | / 46 | """; 47 | formatAndAssert(sql); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_83_nested_function_calls.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_83_nested_function_calls extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void select_single_column_with_hint() { 12 | var sql = """ 13 | select /*+ parallel(t, 2) */ 14 | a 15 | from t; 16 | """; 17 | formatAndAssert(sql); 18 | } 19 | 20 | @Test 21 | public void select_two_columns_with_hint() { 22 | var sql = """ 23 | select /*+ parallel(t, 2) */ 24 | a, 25 | b 26 | from t; 27 | """; 28 | formatAndAssert(sql); 29 | } 30 | 31 | @Test 32 | public void two_selects_with_hints() { 33 | var sql = """ 34 | select /*+ parallel(t, 2) */ 35 | a 36 | from t; 37 | 38 | select /*+ parallel(t, 2) */ 39 | a 40 | from t; 41 | """; 42 | formatAndAssert(sql); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/issues/Issue_84_long_assignments.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.issues; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class Issue_84_long_assignments extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void assignment_with_long_dotted_expression() { 12 | var sql = """ 13 | begin 14 | l_some_long_named_variable_rec.some_primary_item_id := 15 | p_input_obj.items(i).some_nested_element_array(j).some_value.some_other_value.some_primary_item_id; 16 | end; 17 | / 18 | """; 19 | formatAndAssert(sql); 20 | } 21 | 22 | @Test 23 | public void assignment_with_ultra_long_dotted_expression() { 24 | var sql = """ 25 | begin 26 | l_some_long_named_variable_rec.some_primary_item_id := 27 | p_input_obj.items(i).some_nested_element_array(j).some_value.some_other_value.some_primary_item_id1.some_primary_item_id2. 28 | some_primary_item_id3.some_primary_item_id4.some_primary_item_id5.some_primary_item_id.some_primary_item_id6.some_primary_item_id7; 29 | end; 30 | / 31 | """; 32 | formatAndAssert(sql); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A10_align_parameter_modes.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | import java.io.IOException; 9 | 10 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 11 | public class A10_align_parameter_modes extends ConfiguredTestFormatter { 12 | 13 | @BeforeEach 14 | public void setup() { 15 | setOption(getFormatter().alignTypeDecl, true); 16 | setOption(getFormatter().alignAssignments, true); 17 | } 18 | 19 | 20 | @Test 21 | public void procedure() throws IOException { 22 | var input = """ 23 | create procedure p ( 24 | p1 in integer, 25 | p22222 out integer, 26 | p333 in out integer, 27 | p4 integer 28 | ) is 29 | begin 30 | null; 31 | end; 32 | / 33 | """; 34 | var actual = getFormatter().format(input); 35 | var expected = """ 36 | create procedure p( 37 | p1 in integer, 38 | p22222 out integer, 39 | p333 in out integer, 40 | p4 integer 41 | ) is 42 | begin 43 | null; 44 | end; 45 | / 46 | """; 47 | assertEquals(expected, actual); 48 | } 49 | 50 | @Test 51 | public void procedure_single_line() throws IOException { 52 | var input = """ 53 | create procedure p (p1 in integer, p22222 out integer, p333 in out integer, p4 integer) is 54 | begin 55 | null; 56 | end; 57 | / 58 | """; 59 | var actual = getFormatter().format(input); 60 | var expected = """ 61 | create procedure p(p1 in integer, 62 | p22222 out integer, 63 | p333 in out integer, 64 | p4 integer) is 65 | begin 66 | null; 67 | end; 68 | / 69 | """; 70 | assertEquals(expected, actual); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A14_line_break_after_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A14_line_break_after_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void as_create_view() throws IOException { 14 | var input = """ 15 | create or replace view v as select * from t; 16 | """; 17 | var actual = getFormatter().format(input); 18 | var expected = """ 19 | create or replace view v as 20 | select * from t; 21 | """; 22 | assertEquals(expected, actual); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A15_line_break_before_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A15_line_break_before_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void into_in_multi_table_insert() throws IOException { 14 | var input = """ 15 | insert all into t (c1) (select 1 as c1 from dual where 1 = 10); 16 | """; 17 | var actual = getFormatter().format(input); 18 | var expected = """ 19 | insert all 20 | into t (c1) 21 | (select 1 as c1 from dual where 1 = 10); 22 | """; 23 | assertEquals(expected, actual); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A17_whitespace_around_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A17_whitespace_around_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void and_or_add_spaces() throws IOException { 14 | var input = """ 15 | select 1 from dual where ((1=1)and(2=2)or(3=3)); 16 | """; 17 | var actual = getFormatter().format(input); 18 | var expected = """ 19 | select 1 from dual where ((1 = 1) and (2 = 2) or (3 = 3)); 20 | """; 21 | assertEquals(expected, actual); 22 | } 23 | 24 | @Test 25 | public void and_or_keep_nl() throws IOException { 26 | var input = """ 27 | select 1 from dual where ((1=1) 28 | and 29 | (2=2) 30 | or 31 | (3=3)); 32 | """; 33 | var actual = getFormatter().format(input); 34 | var expected = """ 35 | select 1 36 | from dual 37 | where ((1 = 1) 38 | and 39 | (2 = 2) 40 | or 41 | (3 = 3)); 42 | """; 43 | assertEquals(expected, actual); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A19_restore_indent_in_conditional_branch.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A19_restore_indent_in_conditional_branch extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void in_package_body() throws IOException { 14 | // 4 space indentation 15 | var input = """ 16 | create or replace package body pkg is 17 | $IF TRUE $THEN 18 | PROCEDURE P1 IS 19 | BEGIN 20 | NULL; 21 | END; 22 | $END 23 | 24 | procedure p2 is 25 | begin 26 | null; 27 | end; 28 | end; 29 | / 30 | """; 31 | var actual = getFormatter().format(input); 32 | // 3 space indentation, applied only for p2 33 | // keywords are changed to lowercase in conditional compilation block 34 | var expected = """ 35 | create or replace package body pkg is 36 | $IF TRUE $THEN 37 | procedure P1 is 38 | begin 39 | null; 40 | end; 41 | $END 42 | 43 | procedure p2 is 44 | begin 45 | null; 46 | end; 47 | end; 48 | / 49 | """; 50 | assertEquals(expected, actual); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A1_tabs.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A1_tabs extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void replace_tabs_with_3_spaces() throws IOException { 14 | var input = """ 15 | begin 16 | \tnull; 17 | end; 18 | / 19 | """; 20 | var actual = getFormatter().format(input); 21 | var expected = """ 22 | begin 23 | null; 24 | end; 25 | / 26 | """; 27 | assertEquals(expected, actual); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A21_remove_non_ws_indent.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class A21_remove_non_ws_indent extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void not_applicable() { 12 | // don't know how to write a test case for this Arbori section 13 | // tested manually by faking original indent to see if the replacement works. 14 | // e.g. var indent = getIndent(pos) + "aaa bbb\tccc\nddd"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A22_no_space_between_sign_and_digits.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class A22_no_space_between_sign_and_digits extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void insert_negative_number() { 12 | var sql = """ 13 | insert into dept (deptno, dname, loc) 14 | values (-1, 'Testing', 'Winterthur'); 15 | """; 16 | formatAndAssert(sql); 17 | } 18 | 19 | @Test 20 | public void insert_positive_number() { 21 | var sql = """ 22 | insert into dept (deptno, dname, loc) 23 | values (+1, 'Testing', 'Winterthur'); 24 | """; 25 | formatAndAssert(sql); 26 | } 27 | 28 | @Test 29 | public void insert_expression_with_negative_number() { 30 | var sql = """ 31 | insert into dept (deptno, dname, loc) 32 | values ((a + b / 2) + -1, 'Testing', 'Winterthur'); 33 | """; 34 | formatAndAssert(sql); 35 | } 36 | 37 | @Test 38 | public void assignment_with_negative_number() { 39 | var sql = """ 40 | begin 41 | a := b - 1; 42 | end; 43 | """; 44 | formatAndAssert(sql); 45 | } 46 | 47 | @Test 48 | public void assignment_with_positive_number() { 49 | var sql = """ 50 | begin 51 | x := p1(1) + p1(2) + 17; 52 | end; 53 | """; 54 | formatAndAssert(sql); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A23_enforce_line_break_after_single_line_comment.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Nested; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 9 | public class A23_enforce_line_break_after_single_line_comment extends ConfiguredTestFormatter { 10 | 11 | @Nested 12 | class case_expression { 13 | 14 | @Test 15 | public void comment_before_then() { 16 | var sql = """ 17 | select empno, 18 | ename, 19 | case 20 | when 'JOB' = 'SALESMAN' -- make gender-neutral 21 | then 22 | 'SALESPERSON' 23 | else 24 | job 25 | end as job, 26 | sal 27 | from emp; 28 | """; 29 | formatAndAssert(sql); 30 | } 31 | 32 | @Test 33 | public void comment_after_every_token() { 34 | var sql = """ 35 | select empno, 36 | ename, 37 | case 38 | when -- comment 1 39 | 'JOB' -- comment 2 40 | = -- comment 3 41 | 'SALESMAN' -- comment 4 42 | then -- comment 5 43 | 'SALESPERSON' -- comment 6 44 | else -- comment 7 45 | job -- comment 8 46 | end -- comment 9 47 | as -- comment 10 48 | job, 49 | sal 50 | from emp; 51 | """; 52 | formatAndAssert(sql); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A24_indent_case_expression.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 8 | public class A24_indent_case_expression extends ConfiguredTestFormatter { 9 | 10 | @Test 11 | public void order_by_case_expr() { 12 | var sql = """ 13 | select o.owner, 14 | o.object_type, 15 | o.object_name 16 | from dba_objects o 17 | where o.owner = coalesce(in_obj.owner, in_parse_user, 'PUBLIC') 18 | and o.object_name = in_obj.object_name 19 | order by case o.owner 20 | when in_obj.owner then 21 | 1 22 | when in_parse_user then 23 | 2 24 | else 25 | 3 26 | end, 27 | case o.object_type 28 | when in_obj.object_type then 29 | 1 30 | when 'SYNONYM' then 31 | 3 32 | else 33 | 2 34 | end; 35 | """; 36 | formatAndAssert(sql); 37 | } 38 | 39 | @Test 40 | public void order_by_case_expr_in_parenthesis() { 41 | var sql = """ 42 | select o.owner, 43 | o.object_type, 44 | o.object_name 45 | from dba_objects o 46 | where o.owner = coalesce(in_obj.owner, in_parse_user, 'PUBLIC') 47 | and o.object_name = in_obj.object_name 48 | order by ( 49 | case o.owner 50 | when in_obj.owner then 51 | 1 52 | when in_parse_user then 53 | 2 54 | else 55 | 3 56 | end), 57 | case o.object_type 58 | when in_obj.object_type then 59 | 1 60 | when 'SYNONYM' then 61 | 3 62 | else 63 | 2 64 | end; 65 | """; 66 | formatAndAssert(sql); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A2_trailing_spaces.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A2_trailing_spaces extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void remove_trailing_spaces() throws IOException { 14 | var input = """ 15 | begin\s\s\s 16 | null;\s\s\s\t 17 | end;\s\s\s 18 | /\s\s\s 19 | """; 20 | var actual = getFormatter().format(input); 21 | var expected = """ 22 | begin 23 | null; 24 | end; 25 | / 26 | """; 27 | assertEquals(expected, actual); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A5_no_space_before_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A5_no_space_before_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void concat() throws IOException { 14 | var input = """ 15 | select 'a' | | 'b' from t; 16 | """; 17 | var actual = getFormatter().format(input); 18 | var expected = """ 19 | select 'a' || 'b' from t; 20 | """; 21 | assertEquals(expected, actual); 22 | } 23 | 24 | @Test 25 | public void dot_single_line() throws IOException { 26 | var input = """ 27 | select t . column from t; 28 | """; 29 | var actual = getFormatter().format(input); 30 | var expected = """ 31 | select t.column from t; 32 | """; 33 | assertEquals(expected, actual); 34 | } 35 | 36 | @Test 37 | public void dot_multi_line() throws IOException { 38 | var input = """ 39 | select t 40 | . column from t; 41 | """; 42 | var actual = getFormatter().format(input); 43 | var expected = """ 44 | select t.column from t; 45 | """; 46 | assertEquals(expected, actual); 47 | } 48 | 49 | @Test 50 | public void plsql_slash() throws IOException { 51 | var input = """ 52 | begin null; end; / 53 | """; 54 | var actual = getFormatter().format(input); 55 | var expected = """ 56 | begin 57 | null; 58 | end; 59 | / 60 | """; 61 | assertEquals(expected, actual); 62 | } 63 | 64 | @Test 65 | public void expr_slash() throws IOException { 66 | var input = """ 67 | select 5 / 2 68 | from dual; 69 | """; 70 | var actual = getFormatter().format(input); 71 | var expected = """ 72 | select 5 / 2 73 | from dual; 74 | """; 75 | assertEquals(expected, actual); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A6_no_space_after_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A6_no_space_after_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void label() throws IOException { 14 | var input = """ 15 | begin 16 | < < my_label > > 17 | null; 18 | end; 19 | / 20 | """; 21 | var actual = getFormatter().format(input); 22 | var expected = """ 23 | begin 24 | <> 25 | null; 26 | end; 27 | / 28 | """; 29 | assertEquals(expected, actual); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A7_one_space_before_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A7_one_space_before_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void column_alias() throws IOException { 14 | var input = """ 15 | select a as my_col from t; 16 | """; 17 | var actual = getFormatter().format(input); 18 | var expected = """ 19 | select a as my_col from t; 20 | """; 21 | assertEquals(expected, actual); 22 | } 23 | 24 | @Test 25 | public void table_alias() throws IOException { 26 | var input = """ 27 | select a my_col from t my_alias; 28 | """; 29 | var actual = getFormatter().format(input); 30 | var expected = """ 31 | select a my_col from t my_alias; 32 | """; 33 | assertEquals(expected, actual); 34 | } 35 | 36 | @Test 37 | public void function() throws IOException { 38 | var input = """ 39 | create package pkg is 40 | function f ( p1 in number ) return integer; 41 | end pkg; 42 | / 43 | """; 44 | var actual = getFormatter().format(input); 45 | var expected = """ 46 | create package pkg is 47 | function f(p1 in number) return integer; 48 | end pkg; 49 | / 50 | """; 51 | assertEquals(expected, actual); 52 | } 53 | 54 | @Test 55 | public void assignment() throws IOException { 56 | var input = """ 57 | begin 58 | a 59 | := 60 | 1; 61 | end; 62 | / 63 | """; 64 | var actual = getFormatter().format(input); 65 | var expected = """ 66 | begin 67 | a := 68 | 1; 69 | end; 70 | / 71 | """; 72 | assertEquals(expected, actual); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/A8_one_space_after_node.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.TestInstance; 6 | 7 | import java.io.IOException; 8 | 9 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 10 | public class A8_one_space_after_node extends ConfiguredTestFormatter { 11 | 12 | @Test 13 | public void create_or_replace() throws IOException { 14 | var input = """ 15 | create 16 | or 17 | replace 18 | package 19 | pkg is 20 | g_variable integer; 21 | end pkg; 22 | / 23 | """; 24 | var actual = getFormatter().format(input); 25 | var expected = """ 26 | create or replace package pkg is 27 | g_variable integer; 28 | end pkg; 29 | / 30 | """; 31 | assertEquals(expected, actual); 32 | } 33 | 34 | @Test 35 | public void from() throws IOException { 36 | var input = """ 37 | select * from t; 38 | """; 39 | var actual = getFormatter().format(input); 40 | var expected = """ 41 | select * from t; 42 | """; 43 | assertEquals(expected, actual); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/I10_determine_and_normalize_line_separator.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.TestInstance; 7 | 8 | import java.io.IOException; 9 | 10 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 11 | public class I10_determine_and_normalize_line_separator extends ConfiguredTestFormatter { 12 | 13 | @Test 14 | public void mixed_to_crlf() throws IOException { 15 | var input = "select\n*\r\nfrom emp where deptno = 20\norder by sal;"; 16 | var expected = "select *\r\n from emp\r\n where deptno = 20\r\n order by sal;"; 17 | var actual = getFormatter().format(input); 18 | Assertions.assertEquals(expected, actual); 19 | } 20 | 21 | @Test 22 | public void lf_only() throws IOException { 23 | var input = "select\n*\nfrom emp where deptno = 20\norder by sal;"; 24 | var expected = "select *\n from emp\n where deptno = 20\n order by sal;"; 25 | var actual = getFormatter().format(input); 26 | Assertions.assertEquals(expected, actual); 27 | } 28 | 29 | @Test 30 | public void crlf_only() throws IOException { 31 | var input = "select\r\n*\r\nfrom emp where deptno = 20\r\norder by sal;"; 32 | var expected = "select *\r\n from emp\r\n where deptno = 20\r\n order by sal;"; 33 | var actual = getFormatter().format(input); 34 | Assertions.assertEquals(expected, actual); 35 | } 36 | 37 | @Test 38 | public void system_default() throws IOException { 39 | var input = "begin null; end;"; 40 | var expected = "begin" + System.lineSeparator() + " null;" + System.lineSeparator() + "end;"; 41 | var actual = getFormatter().format(input); 42 | Assertions.assertEquals(expected, actual); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/settings/tests/rules/O11_line_break_on_subqueries.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.settings.tests.rules; 2 | 3 | import com.trivadis.plsql.formatter.settings.ConfiguredTestFormatter; 4 | import org.junit.jupiter.api.*; 5 | 6 | import java.io.IOException; 7 | 8 | public class O11_line_break_on_subqueries extends ConfiguredTestFormatter { 9 | 10 | @Nested 11 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 12 | class True { 13 | 14 | @BeforeAll 15 | public void setup() { 16 | setOption(getFormatter().breakOnSubqueries, true); 17 | } 18 | 19 | @Test 20 | public void correlated_subquery_single_line() throws IOException { 21 | var input = """ 22 | select d.dname, 23 | (select count(*) from emp e where e.deptno = d.deptno) as emp_count 24 | from dept d; 25 | """; 26 | var actual = getFormatter().format(input); 27 | var expected = """ 28 | select d.dname, 29 | (select count(*) from emp e where e.deptno = d.deptno) as emp_count 30 | from dept d; 31 | """; 32 | assertEquals(expected, actual); 33 | } 34 | 35 | @Test 36 | public void correlated_subquery_multiline() throws IOException { 37 | var input = """ 38 | select d.dname, 39 | (select count(*) 40 | from emp e 41 | where e.deptno = d.deptno) as emp_count 42 | from dept d; 43 | """; 44 | var actual = getFormatter().format(input); 45 | var expected = """ 46 | select d.dname, 47 | ( 48 | select count(*) 49 | from emp e 50 | where e.deptno = d.deptno 51 | ) as emp_count 52 | from dept d; 53 | """; 54 | assertEquals(expected, actual); 55 | } 56 | } 57 | 58 | @Nested 59 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) 60 | class False { 61 | 62 | @BeforeAll 63 | public void setup() { 64 | setOption(getFormatter().breakOnSubqueries, false); 65 | } 66 | 67 | @Test 68 | public void join() { 69 | var sql = """ 70 | select d.dname, 71 | (select count(*) 72 | from emp e 73 | where e.deptno = d.deptno) as emp_count 74 | from dept d; 75 | """; 76 | formatAndAssert(sql); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/FormatTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.io.IOException; 6 | 7 | public class FormatTest extends AbstractFormatTest { 8 | 9 | @Test 10 | public void process_dir() { 11 | process_dir(RunType.FormatJS); 12 | } 13 | 14 | @Test 15 | public void process_pkb_only() { 16 | process_pkb_only(RunType.FormatJS); 17 | } 18 | 19 | @Test 20 | public void process_with_default_arbori() { 21 | process_with_default_arbori(RunType.FormatJS); 22 | } 23 | 24 | @Test 25 | public void process_with_xml() { 26 | process_with_xml(RunType.FormatJS); 27 | } 28 | 29 | @Test 30 | public void process_with_default_xml_default_arbori() { 31 | process_with_default_xml_default_arbori(RunType.FormatJS); 32 | } 33 | 34 | @Test 35 | public void process_with_embedded_xml_default_arbori() { 36 | process_with_embedded_xml_default_arbori(RunType.FormatJS); 37 | } 38 | 39 | @Test 40 | public void process_markdown_only() { 41 | process_markdown_only(RunType.FormatJS); 42 | } 43 | 44 | @Test 45 | public void process_config_file_array() throws IOException { 46 | process_config_file_array(RunType.FormatJS); 47 | } 48 | 49 | @Test 50 | public void process_config_file_object() throws IOException { 51 | process_config_file_object(RunType.FormatJS); 52 | } 53 | 54 | @Test 55 | public void process_config_file_object_and_param() throws IOException { 56 | process_config_file_object_and_param(RunType.FormatJS); 57 | } 58 | 59 | @Test 60 | public void process_config_dir_array() throws IOException { 61 | process_config_dir_array(RunType.FormatJS); 62 | } 63 | 64 | @Test 65 | public void process_sql_txt_default() { 66 | process_sql_txt_default(RunType.FormatJS); 67 | } 68 | 69 | @Test 70 | public void process_sql_txt_force() { 71 | process_sql_txt_force(RunType.FormatJS); 72 | } 73 | 74 | @Test 75 | public void process_dir_all_errors() { 76 | process_dir_all_errors(RunType.FormatJS); 77 | } 78 | 79 | @Test 80 | public void process_dir_mext_errors() { 81 | process_dir_mext_errors(RunType.FormatJS); 82 | } 83 | 84 | @Test 85 | public void process_dir_ext_errors() { 86 | process_dir_ext_errors(RunType.FormatJS); 87 | } 88 | 89 | @Test 90 | public void process_dir_no_errors() { 91 | process_dir_no_errors(RunType.FormatJS); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/FormatVersionTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class FormatVersionTest extends AbstractSqlclTest { 7 | final String expected = """ 8 | 9 | Trivadis PL/SQL & SQL Formatter (format.js), version XYZ 10 | 11 | """; 12 | @Test 13 | public void longArgument() { 14 | var actual = runScript("--version"); 15 | Assertions.assertEquals(expected, actual.replaceAll(", version [^\\s]+", ", version XYZ")); 16 | } 17 | 18 | @Test 19 | public void shortArgument() { 20 | var actual = runScript("-v"); 21 | Assertions.assertEquals(expected, actual.replaceAll(", version [^\\s]+", ", version XYZ")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/RunType.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | public enum RunType { 4 | FormatJS, 5 | TvdFormatCommand 6 | } 7 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/TvdFormatPathWithSpaceTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.IOException; 8 | import java.nio.file.Files; 9 | 10 | public class TvdFormatPathWithSpaceTest extends AbstractSqlclTest { 11 | 12 | @BeforeEach 13 | public void registerCommandBeforeTest() { 14 | runScript("--register"); 15 | byteArrayOutputStream.reset(); 16 | } 17 | 18 | @Test 19 | public void path_with_spaces() throws IOException { 20 | var myFilesDir = Files.createTempDirectory("my files"); 21 | var actual = runCommand("tvdformat \"" + myFilesDir.toAbsolutePath() + "\""); 22 | // directory is empty, no files processed 23 | Assertions.assertTrue(actual.trim().isEmpty()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/TvdFormatRegisterTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class TvdFormatRegisterTest extends AbstractSqlclTest { 7 | 8 | @Test 9 | public void not_registered_feeback() { 10 | reset(); 11 | var expected = """ 12 | Error starting at line : 1 in command - 13 | tvdformat 14 | Error report - 15 | Unknown Command 16 | """.trim(); 17 | var actual = runCommand("tvdformat").trim(); 18 | Assertions.assertEquals(expected, actual); 19 | } 20 | 21 | @Test 22 | public void register_feedback() { 23 | var expected = """ 24 | tvdformat registered as SQLcl command. 25 | """; 26 | var actual = runScript("--register"); 27 | Assertions.assertEquals(expected, actual); 28 | byteArrayOutputStream.reset(); 29 | var actual2 = runScript("-r"); 30 | Assertions.assertEquals(expected, actual2); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/TvdFormatVersionTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.sqlcl.tests; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class TvdFormatVersionTest extends AbstractSqlclTest { 8 | final String expected = """ 9 | 10 | Trivadis PL/SQL & SQL Formatter (tvdformat), version XYZ 11 | 12 | """; 13 | 14 | @BeforeEach 15 | public void registerCommandBeforeTest() { 16 | runScript("--register"); 17 | byteArrayOutputStream.reset(); 18 | } 19 | 20 | @Test 21 | public void longArgument() { 22 | var actual = runCommand("tvdformat --version"); 23 | Assertions.assertEquals(expected, actual.replaceAll(", version [^\\s]+", ", version XYZ")); 24 | } 25 | 26 | @Test 27 | public void shortArgument() { 28 | var actual = runCommand("tvdformat -v"); 29 | Assertions.assertEquals(expected, actual.replaceAll(", version [^\\s]+", ", version XYZ")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /standalone/src/test/java/com/trivadis/plsql/formatter/standalone/tests/AbstractTvdFormatTest.java: -------------------------------------------------------------------------------- 1 | package com.trivadis.plsql.formatter.standalone.tests; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.BeforeEach; 5 | 6 | import java.io.*; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | 11 | public abstract class AbstractTvdFormatTest { 12 | static final String[] TEST_FILES = new String[] 13 | {"unformatted/dont_format.txt", "unformatted/markdown.md", "unformatted/package_body.pkb", 14 | "unformatted/query.sql", "unformatted/sql.txt", "unformatted/syntax_error.sql", 15 | "trivadis_advanced_format.xml", "trivadis_custom_format.arbori"}; 16 | static final PrintStream originalPrintStream = System.out; 17 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 18 | PrintStream printStream = new PrintStream(outputStream); 19 | private Path tempDir; 20 | 21 | public String getTempDir() { 22 | return tempDir.toString().replace("\\", "/"); 23 | } 24 | 25 | public Path getTempDirPath() { 26 | return tempDir; 27 | } 28 | 29 | @BeforeEach 30 | public void setup() throws IOException { 31 | tempDir = Files.createTempDirectory("tvdformat-test-"); 32 | for (String fileName : TEST_FILES) { 33 | var url = Thread.currentThread().getContextClassLoader().getResource(fileName); 34 | assert url != null; 35 | var target = Paths.get(tempDir.toString() + File.separator + new File(url.getFile()).toPath().getFileName()); 36 | Files.copy(url.openStream(), target); 37 | } 38 | System.setOut(printStream); 39 | outputStream.reset(); 40 | } 41 | 42 | @AfterEach 43 | public void teardown() { 44 | System.clearProperty("tvdformat.standalone"); 45 | System.clearProperty("polyglot.engine.WarnInterpreterOnly"); 46 | System.setOut(originalPrintStream); 47 | } 48 | 49 | private String getFileContent(Path file) throws IOException { 50 | return new String(Files.readAllBytes(file)); 51 | } 52 | 53 | public String getFormattedContent(String fileName) throws IOException { 54 | var file = Paths.get(tempDir.toString() + File.separator + fileName); 55 | return getFileContent(file); 56 | } 57 | 58 | public String getConsoleOutput() { 59 | return outputStream.toString(); 60 | } 61 | 62 | public String getXML() { 63 | return getTempDir() + "/trivadis_advanced_format.xml"; 64 | } 65 | 66 | public String getArbori() { 67 | return getTempDir() + "/trivadis_custom_format.arbori"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /standalone/src/test/resources/advanced_format.xml: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | true 5 | false 6 | oracle.dbtools.app.Format.InlineComments.CommentsUnchanged 7 | true 8 | 120 9 | true 10 | true 11 | true 12 | oracle.dbtools.app.Format.Breaks.Before 13 | oracle.dbtools.app.Format.Breaks.Before 14 | true 15 | default 16 | 1 17 | true 18 | false 19 | oracle.dbtools.app.Format.Case.NoCaseChange 20 | oracle.dbtools.app.Format.BreaksX2.X1 21 | oracle.dbtools.app.Format.Breaks.Before 22 | oracle.dbtools.app.Format.Space.Default 23 | oracle.dbtools.app.Format.FlowControl.IndentedActions 24 | 1 25 | false 26 | true 27 | true 28 | 3 29 | false 30 | true 31 | oracle.dbtools.app.Format.Case.UPPER 32 | 33 | -------------------------------------------------------------------------------- /standalone/src/test/resources/charset/utf8.sql: -------------------------------------------------------------------------------- 1 | begin 2 | dbms_output.put_line('Ää-Öö-Üü-Éé-Èè'); 3 | dbms_output.put_line('£100'); 4 | dbms_output.put_line('€200'); 5 | end; 6 | / 7 | -------------------------------------------------------------------------------- /standalone/src/test/resources/charset/windows-1252.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trivadis/plsql-formatter-settings/f60dd0ba2c141483a878dbb6be2c4e00ebd35421/standalone/src/test/resources/charset/windows-1252.sql -------------------------------------------------------------------------------- /standalone/src/test/resources/logging.conf: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | 3 | # Default global logging level. 4 | .level=OFF 5 | 6 | # Loggers 7 | oracle.dbtools.app.Format.level=ALL 8 | 9 | # --- ConsoleHandler --- 10 | # ALL, FINEST, FINER, FINE, INFO, WARNING, SEVERE, OFF 11 | java.util.logging.ConsoleHandler.level=ALL 12 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 13 | java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s: %5$s%n 14 | -------------------------------------------------------------------------------- /standalone/src/test/resources/trivadis_advanced_format.xml: -------------------------------------------------------------------------------- 1 | ../../../../settings/sql_developer/trivadis_advanced_format.xml -------------------------------------------------------------------------------- /standalone/src/test/resources/trivadis_custom_format.arbori: -------------------------------------------------------------------------------- 1 | ../../../../settings/sql_developer/trivadis_custom_format.arbori -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/dont_format.txt: -------------------------------------------------------------------------------- 1 | This file must not be formatted. 2 | -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/markdown.md: -------------------------------------------------------------------------------- 1 | # Titel 2 | 3 | ## Introduction 4 | 5 | This is a Markdown file with some `code blocks`. 6 | 7 | ## Package Body 8 | 9 | Here's the content of package_body.pkb 10 | 11 | ```sql 12 | create or replace package body the_api.math as function to_int_table(in_integers 13 | in varchar2,in_pattern in varchar2 default '[0-9]+')return sys.ora_mining_number_nt deterministic accessible 14 | by(package the_api.math,package the_api.test_math)is l_result sys 15 | .ora_mining_number_nt:=sys.ora_mining_number_nt();l_pos integer:= 1;l_int integer; 16 | begin<>loop l_int:=to_number(regexp_substr(in_integers,in_pattern,1,l_pos)); 17 | exit integer_tokens when l_int is null;l_result.extend;l_result(l_pos):= l_int;l_pos:=l_pos+1; 18 | end loop integer_tokens;return l_result;end to_int_table;end math; 19 | / 20 | ``` 21 | 22 | ## Syntax Error 23 | 24 | Here's the content of syntax_error.sql 25 | 26 | ``` sql 27 | declare 28 | l_var1 integer; 29 | l_var2 varchar2(20); 30 | begin 31 | for r in /*(*/ select x.* from x join y on y.a = x.a) 32 | loop 33 | p(r.a, r.b, r.c); 34 | end loop; 35 | end; 36 | / 37 | ``` 38 | 39 | ## Query (to be ignored) 40 | 41 | Here's the content of query.sql, but the code block must not be formatted: 42 | 43 | ``` 44 | Select d.department_name,v. employee_id 45 | ,v 46 | . last_name frOm departments d CROSS APPLY(select*from employees e 47 | wHERE e.department_id=d.department_id) v WHeRE 48 | d.department_name in ('Marketing' 49 | ,'Operations', 50 | 'Public Relations') Order By d. 51 | department_name,v.employee_id; 52 | ``` 53 | 54 | ## Query (to be formatted) 55 | 56 | Here's the content of query.sql: 57 | 58 | ``` sql 59 | Select d.department_name,v. employee_id 60 | ,v 61 | . last_name frOm departments d CROSS APPLY(select*from employees e 62 | wHERE e.department_id=d.department_id) v WHeRE 63 | d.department_name in ('Marketing' 64 | ,'Operations', 65 | 'Public Relations') Order By d. 66 | department_name,v.employee_id; 67 | ``` 68 | 69 | ## JavaScript code 70 | 71 | Here's another code which must not be formatted 72 | 73 | ``` js 74 | var foo = function (bar) { 75 | return bar++; 76 | }; 77 | ``` 78 | -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/package_body.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body the_api.math as function to_int_table(in_integers 2 | in varchar2,in_pattern in varchar2 default '[0-9]+')return sys.ora_mining_number_nt deterministic accessible 3 | by(package the_api.math,package the_api.test_math)is l_result sys 4 | .ora_mining_number_nt:=sys.ora_mining_number_nt();l_pos integer:= 1;l_int integer; 5 | begin<>loop l_int:=to_number(regexp_substr(in_integers,in_pattern,1,l_pos)); 6 | exit integer_tokens when l_int is null;l_result.extend;l_result(l_pos):= l_int;l_pos:=l_pos+1; 7 | end loop integer_tokens;return l_result;end to_int_table;end math; 8 | / -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/query.sql: -------------------------------------------------------------------------------- 1 | Select d.department_name,v. employee_id 2 | ,v 3 | . last_name frOm departments d CROSS APPLY(select*from employees e 4 | wHERE e.department_id=d.department_id) v WHeRE 5 | d.department_name in ('Marketing' 6 | ,'Operations', 7 | 'Public Relations') Order By d. 8 | department_name,v.employee_id; -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/sql.txt: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | dual 5 | ; 6 | -------------------------------------------------------------------------------- /standalone/src/test/resources/unformatted/syntax_error.sql: -------------------------------------------------------------------------------- 1 | declare 2 | l_var1 integer; 3 | l_var2 varchar2(20); 4 | begin 5 | for r in /*(*/ select x.* from x join y on y.a = x.a) 6 | loop 7 | p(r.a, r.b, r.c); 8 | end loop; 9 | end; 10 | / --------------------------------------------------------------------------------