summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2017-02-20 13:38:56 +0100
committerMichal Čihař <michal@cihar.com>2017-02-20 13:38:56 +0100
commit5c6e8f0e98e33f81e00d6881a4669f84167ad5be (patch)
tree5e7a73abcdf814110baa6fff7c2759c1ae85dcf1
parentd002e8b84122f7a0ab6d12da6f976a597e3a8500 (diff)
downloadsql-parser-5c6e8f0e98e33f81e00d6881a4669f84167ad5be.zip
sql-parser-5c6e8f0e98e33f81e00d6881a4669f84167ad5be.tar.gz
sql-parser-5c6e8f0e98e33f81e00d6881a4669f84167ad5be.tar.bz2
Fix BEGIN/END indentation
Ensure we never have negative indentation Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r--src/Utils/Formatter.php7
-rw-r--r--tests/Utils/FormatterTest.php24
2 files changed, 13 insertions, 18 deletions
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index e07394c..c111bc7 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -378,7 +378,7 @@ class Formatter
if ($tmp = static::isClause($curr)) {
if ($tmp == 2 || $this->options['clause_newline']) {
$lineEnded = true;
- if ($this->options['parts_newline']) {
+ if ($this->options['parts_newline'] && $indent > 0) {
--$indent;
}
}
@@ -442,11 +442,6 @@ class Formatter
// Finishing the line.
if ($lineEnded) {
- if ($indent < 0) {
- // TODO: Make sure this never occurs and delete it.
- $indent = 0;
- }
-
$ret .= $this->options['line_ending']
. str_repeat($this->options['indentation'], $indent);
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index c209d27..12e9912 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -406,26 +406,26 @@ class FormatTest extends TestCase
'text' => 'CREATE' . "\n" .
'PROCEDURE test_procedure()' . "\n" .
'BEGIN' . "\n" .
- 'FROM' . "\n" .
- ' tbl' . "\n" .
- 'SELECT' . "\n" .
- ' *;' . "\n" .
+ ' FROM' . "\n" .
+ ' tbl' . "\n" .
+ ' SELECT' . "\n" .
+ ' *;' . "\n" .
'END',
'cli' => "\x1b[35mCREATE" . "\n" .
"\x1b[35mPROCEDURE \x1b[39mtest_procedure\x1b[39m(\x1b[39m)\n" .
"\x1b[95mBEGIN" . "\n" .
- "\x1b[35mFROM" . "\n" .
- " \x1b[39mtbl" . "\n" .
- "\x1b[35mSELECT" . "\n" .
- " \x1b[39m*\x1b[39m;\n" .
+ " \x1b[35mFROM" . "\n" .
+ " \x1b[39mtbl" . "\n" .
+ " \x1b[35mSELECT" . "\n" .
+ " \x1b[39m*\x1b[39m;\n" .
"\x1b[95mEND" . "\x1b[0m",
'html' => '<span class="sql-reserved">CREATE</span>' . '<br/>' .
'<span class="sql-reserved">PROCEDURE</span> test_procedure()' . '<br/>' .
'<span class="sql-keyword">BEGIN</span>' . '<br/>' .
- '<span class="sql-reserved">FROM</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;tbl' . '<br/>' .
- '<span class="sql-reserved">SELECT</span>' . '<br/>' .
- '&nbsp;&nbsp;&nbsp;&nbsp;*;' . '<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">FROM</span>' . '<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl' . '<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-reserved">SELECT</span>' . '<br/>' .
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*;' . '<br/>' .
'<span class="sql-keyword">END</span>',
),
'insert' => array(