Skip to content

Commit

Permalink
Improve property and method naming and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Nov 11, 2024
1 parent e0dfccd commit 6678856
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 217 deletions.
3 changes: 2 additions & 1 deletion tests/mysql/WP_MySQL_Lexer_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class WP_MySQL_Lexer_Tests extends TestCase {
* @dataProvider data_identifier_or_number
*/
public function test_identifier_or_number( $input, $expected ): void {
$lexer = new WP_MySQL_Lexer( $input );
$actual = array_map(
function ( $token ) {
return $token->get_type();
},
WP_MySQL_Lexer::tokenize( $input )
$lexer->remaining_tokens()
);

// Compare token names to get more readable error messages.
Expand Down
3 changes: 2 additions & 1 deletion tests/mysql/WP_MySQL_Server_Suite_Lexer_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function test_tokenize_mysql_test_suite(): void {
try {
while ( ( $record = fgetcsv( $handle ) ) !== false ) {
$query = $record[0];
$tokens = WP_MySQL_Lexer::tokenize( $query );
$lexer = new WP_MySQL_Lexer( $query );
$tokens = $lexer->remaining_tokens();
$this->assertNotEmpty( $tokens, "Failed to tokenize query: $query" );
}
} finally {
Expand Down
3 changes: 2 additions & 1 deletion tests/mysql/WP_MySQL_Server_Suite_Parser_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function test_parse_mysql_test_suite( array $batch ): void {
foreach ( $batch as $record ) {
$query = $record[0];

$tokens = WP_MySQL_Lexer::tokenize( $query );
$lexer = new WP_MySQL_Lexer( $query );
$tokens = $lexer->remaining_tokens();
$this->assertNotEmpty( $tokens, "Failed to tokenize query: $query" );

$parser = new WP_MySQL_Parser( self::$grammar, $tokens );
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/run-lexer-benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function ( $severity, $message, $file, $line ) {
$start = microtime( true );
for ( $i = 0; $i < count( $records ); $i += 1 ) {
$query = $records[ $i ][0];
$tokens = WP_MySQL_Lexer::tokenize( $query );
$lexer = new WP_MySQL_Lexer( $query );
$tokens = $lexer->remaining_tokens();
if ( count( $tokens ) === 0 ) {
throw new Exception( 'Failed to tokenize query: ' . $query );
}
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/run-parser-benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function getStats( $total, $failures, $exceptions ) {
}

try {
$tokens = WP_MySQL_Lexer::tokenize( $query );
$lexer = new WP_MySQL_Lexer( $query );
$tokens = $lexer->remaining_tokens();
if ( count( $tokens ) === 0 ) {
throw new Exception( 'Failed to tokenize query: ' . $query );
}
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/run-parser-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function ( $severity, $message, $file, $line ) {
$grammar = new WP_Parser_Grammar( $grammar_data );

// Edit the query below to test different inputs:
$tokens = WP_MySQL_Lexer::tokenize( 'SELECT 1' );
$lexer = new WP_MySQL_Lexer( 'SELECT 1' );
$tokens = $lexer->remaining_tokens();

echo "Tokens:\n";
foreach ( $tokens as $token ) {
Expand Down
Loading

0 comments on commit 6678856

Please sign in to comment.