Skip to content
walter-weinmann edited this page May 12, 2020 · 10 revisions

1. Manual created Eunit tests

All the test cases are also documentation of the current support.

2. Running Test Cases

  • SET SOURCEFILES=<test> and run with rebar3 eunit skip_deps=true one specific <test>.tst file from the test/eunit. folder.

3. Ad-hoc testing with sqlparse_adhoc_test

The sqlparse_adhoc_test module can be used for spontaneous tests during the development process. The SQL statements to be tested must be stored in the sqlparse_adhoc_test.tst file, for example

"select column_1 from table_1".

The LOPTS and TEST_VERSION macros can be used to modify the tests as follows:

I. LOPTS

The formatting options that deviate from the standard can be defined here, for example:

-define(LOPTS, [
    {case_identifier, init_cap},
    {line_break_after, 0}
]).

II. TEST_VERSION

  • bottom_up - uses the method sqlparse_layout:bottom_up/1
  • check - compares the results of using first the method sqlparse_layout:top_down/1 and then the method sqlparse_layout:bottom_up/1
  • flat (default value) - uses the method sqlparse_layout:flat/1
  • full - uses the method sqlparse_test_utils:eunit_test/1
  • pretty - uses the method sqlparse_layout:pretty/2
  • top_down - uses the method sqlparse_layout:top_down/1

TEST_VERSION full includes the following steps:

  1. Create the parse tree and the token list of the given SQL statements.
  2. Create top down the flat version of the SQL statement based the parse tree from step 1 (applying custom fold extension sqlparse_format_flat).
  3. Create the parse tree and the token list from the SQL statement from step 2.
  4. Check that the parse trees from step 1 and step 3 are identical.
  5. Check that the SQL statement from step 2 does not have two or more consecutive blanks at any point.
  6. Create the top down result with custom fold extension sqlparse_check_td_vs_bu.
  7. Create the bottom up result with custom fold extension sqlparse_check_td_vs_bu.
  8. Check that the results from step 6 and step 7 are identical.
  9. Create top down the formatted version of the SQL statement based the parse tree from step 1 (applying custom fold extension sqlparse_format_pretty).
  10. Create the parse tree from the SQL statement from step 9.
  11. Check that the lower-case versions of the parse trees from step 1 and step 10 are identical.

4. Formatting testing with sqlparse_pretty_test

The file sqlparse_pretty_test.hrl contains the test cases for the custom fold extension sqlparse_format_pretty.