Skip to content

fix: trailing open block comment #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tak to muzes rovnou vyhodit aji tu 5.4 a 5.5 ne?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 bohužel 7.0+ nešlape a to teď vůbec nechci řešit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no to bych taky neresil

- hhvm

script: phpunit --coverage-text
4 changes: 4 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

ini_set('display_errors', true);
ini_set('error_reporting', E_ALL);
2 changes: 1 addition & 1 deletion lib/SqlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected static function getNextToken($string, $previous = null)
}

// Comment
if ($string[0] === '#' || (isset($string[1])&&($string[0]==='-'&&$string[1]==='-') || ($string[0]==='/'&&$string[1]==='*'))) {
if ($string[0] === '#' || (isset($string[1])&&($string[0]==='-'&&$string[1]==='-') || ($string[0]==='/'&&isset($string[1])&&$string[1]==='*'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chtěl jsem držet aktuální coding style. kdybychom tu knihovnu adoptovali, tak bych to doladil, ale do tý doby se snažím zdržet coding style změn.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no tak mas tam $string[0] === '#' a hned vedle $string[0]==='-' tak nevim co to je za coding style :) krome random

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jj, ale to jsem neměnil, přidával jsem jen isset($string[1])&& do poslední části podmínky

// Comment until end of line
if ($string[0] === '-' || $string[0] === '#') {
$last = strpos($string, "\n");
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
<phpunit
colors="true"
bootstrap="bootstrap.php">
<testsuites>
<testsuite name="SqlFormatter">
<directory suffix="Test.php">./tests</directory>
Expand Down
77 changes: 42 additions & 35 deletions tests/SqlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SqlFormatterTest extends PHPUnit_Framework_TestCase {
protected $sqlData;

/**
* @dataProvider formatHighlightData
*/
Expand Down Expand Up @@ -54,43 +54,43 @@ function testCliHighlight($sql, $html) {
function testCompress($sql, $html) {
$this->assertEquals(trim($html), trim(SqlFormatter::compress($sql)));
}

function testUsePre() {
SqlFormatter::$use_pre = false;
$actual = SqlFormatter::highlight("test");
$expected = '<span style="color: #333;">test</span>';
$this->assertEquals($actual,$expected);

SqlFormatter::$use_pre = true;
$actual = SqlFormatter::highlight("test");
$expected = '<pre style="color: black; background-color: white;"><span style="color: #333;">test</span></pre>';
$this->assertEquals($actual,$expected);
}

function testSplitQuery() {
$expected = array(
"SELECT 'test' FROM MyTable;",
"SELECT Column2 FROM SomeOther Table WHERE (test = true);"
);

$actual = SqlFormatter::splitQuery(implode(';',$expected));

$this->assertEquals($expected, $actual);
}

function testSplitQueryEmpty() {
$sql = "SELECT 1;SELECT 2;\n-- This is a comment\n;SELECT 3";
$expected = array("SELECT 1;","SELECT 2;","SELECT 3");
$actual = SqlFormatter::splitQuery($sql);

$this->assertEquals($expected, $actual);
}

function testRemoveComments() {
$expected = SqlFormatter::format("SELECT\n * FROM\n MyTable",false);
$sql = "/* this is a comment */SELECT#This is another comment\n * FROM-- One final comment\n MyTable";
$actual = SqlFormatter::removeComments($sql);

$this->assertEquals($expected, $actual);
}

Expand All @@ -100,120 +100,127 @@ function testRemoveOpenComments() {

$this->assertEquals("", $actual);
}


function testTrailingClosingComments() {
$sql = "SELECT 1 */";
$actual = SqlFormatter::removeComments($sql);

$this->assertEquals("SELECT \n 1 */", $actual);
}

function testCacheStats() {
$stats = SqlFormatter::getCacheStats();
$this->assertGreaterThan(1,$stats['hits']);
}

function formatHighlightData() {
$formatHighlightData = explode("\n\n",file_get_contents(__DIR__."/format-highlight.html"));
$sqlData = $this->sqlData();

$return = array();
foreach($formatHighlightData as $i=>$data) {
$return[] = array(
$sqlData[$i],
$data
);
}

return $return;
}

function highlightCliData() {
$clidata = explode("\n\n",file_get_contents(__DIR__."/clihighlight.html"));
$sqlData = $this->sqlData();

$return = array();
foreach($clidata as $i=>$data) {
$return[] = array(
$sqlData[$i],
$data
);
}

return $return;
}

function formatData() {
$formatData = explode("\n\n",file_get_contents(__DIR__."/format.html"));
$sqlData = $this->sqlData();

$return = array();
foreach($formatData as $i=>$data) {
$return[] = array(
$sqlData[$i],
$data
);
}

return $return;
}

function compressData() {
$compressData = explode("\n\n",file_get_contents(__DIR__."/compress.html"));
$sqlData = $this->sqlData();

$return = array();
foreach($compressData as $i=>$data) {
$return[] = array(
$sqlData[$i],
$data
);
}

return $return;
}

function highlightData() {
$highlightData = explode("\n\n",file_get_contents(__DIR__."/highlight.html"));
$sqlData = $this->sqlData();

$return = array();
foreach($highlightData as $i=>$data) {
$return[] = array(
$sqlData[$i],
$data
);
}

return $return;
}



function sqlData() {
if(!$this->sqlData) {
$this->sqlData = explode("\n\n",file_get_contents(__DIR__."/sql.sql"));
}

/**
$formatHighlight = array();
$highlight = array();
$format = array();
$compress = array();
$clihighlight = array();

foreach($this->sqlData as $sql) {
$formatHighlight[] = trim(SqlFormatter::format($sql));
$highlight[] = trim(SqlFormatter::highlight($sql));
$format[] = trim(SqlFormatter::format($sql, false));
$compress[] = trim(SqlFormatter::compress($sql));

SqlFormatter::$cli = true;
$clihighlight[] = trim(SqlFormatter::format($sql));
SqlFormatter::$cli = false;
}

file_put_contents(__DIR__."/format-highlight.html", implode("\n\n",$formatHighlight));
file_put_contents(__DIR__."/highlight.html", implode("\n\n",$highlight));
file_put_contents(__DIR__."/format.html", implode("\n\n",$format));
file_put_contents(__DIR__."/compress.html", implode("\n\n",$compress));
file_put_contents(__DIR__."/clihighlight.html", implode("\n\n",$clihighlight));
/**/

return $this->sqlData;
}

}