@@ -70,7 +70,7 @@ public function test_tokenize_invalid_input(): void {
7070 * @return string[] Terminal names, in input order.
7171 */
7272 private static function token_names ( string $ sql , array $ sql_modes = array () ): array {
73- $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80400 , $ sql_modes ) )->remaining_tokens ();
73+ $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80410 , $ sql_modes ) )->remaining_tokens ();
7474 $ names = array ();
7575 foreach ( $ tokens as $ token ) {
7676 $ names [] = $ token ->get_name ();
@@ -88,28 +88,28 @@ public function test_emits_bison_terminals_with_end_markers(): void {
8888 public function test_ignore_space_preserves_function_name_ranges (): void {
8989 // Without "(", COUNT is an identifier whose range excludes trailing whitespace.
9090 $ sql = 'SELECT COUNT FROM t ' ;
91- $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80400 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
91+ $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80410 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
9292 $ this ->assertSame ( 'IDENT ' , $ tokens [1 ]->get_name (), $ sql );
9393 $ this ->assertSame ( 'COUNT ' , $ tokens [1 ]->get_value (), $ sql );
9494 $ this ->assertSame ( 5 , $ tokens [1 ]->length , $ sql );
9595 $ this ->assertSame ( 13 , $ tokens [2 ]->start , $ sql );
9696
9797 $ sql = "SELECT COUNT \t\n FROM t " ;
98- $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80400 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
98+ $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80410 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
9999 $ this ->assertSame ( 'IDENT ' , $ tokens [1 ]->get_name (), $ sql );
100100 $ this ->assertSame ( 'COUNT ' , $ tokens [1 ]->get_value (), $ sql );
101101 $ this ->assertSame ( 5 , $ tokens [1 ]->length , $ sql );
102102 $ this ->assertSame ( 15 , $ tokens [2 ]->start , $ sql );
103103
104104 // With "(", COUNT is a function whose range still excludes the whitespace.
105- $ tokens = ( new WP_MySQL_Lexer ( 'SELECT COUNT (1) ' , 80400 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
105+ $ tokens = ( new WP_MySQL_Lexer ( 'SELECT COUNT (1) ' , 80410 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
106106 $ this ->assertSame ( 5 , $ tokens [1 ]->length );
107107 $ this ->assertSame ( 'COUNT ' , $ tokens [1 ]->get_name () );
108108 $ this ->assertSame ( 'LEFT_PAREN ' , $ tokens [2 ]->get_name () );
109109 $ this ->assertSame ( 13 , $ tokens [2 ]->start );
110110
111111 $ sql = "SELECT COUNT \t\n" ;
112- $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80400 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
112+ $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80410 , array ( 'IGNORE_SPACE ' ) ) )->remaining_tokens ();
113113 $ this ->assertSame ( 'IDENT ' , $ tokens [1 ]->get_name (), $ sql );
114114 $ this ->assertSame ( 'COUNT ' , $ tokens [1 ]->get_value (), $ sql );
115115 $ this ->assertSame ( 5 , $ tokens [1 ]->length , $ sql );
@@ -190,6 +190,22 @@ public function data_version_comments(): array {
190190 return $ cases ;
191191 }
192192
193+ public function test_mysql_version_defaults_to_mysql_8_4_10 (): void {
194+ $ lexer = new WP_MySQL_Lexer ( 'SELECT /*!080400 1 + */ 2 ' );
195+ $ this ->assertSame ( 80410 , $ lexer ->get_mysql_version () );
196+
197+ // A six-digit MySQL 8.4 version comment is executed by default.
198+ $ this ->assertSame (
199+ array ( 'SELECT ' , 'NUM ' , 'PLUS ' , 'NUM ' , 'END_OF_INPUT ' , 'YYEOF ' ),
200+ array_map (
201+ static function ( WP_MySQL_Token $ token ): string {
202+ return $ token ->get_name ();
203+ },
204+ $ lexer ->remaining_tokens ()
205+ )
206+ );
207+ }
208+
193209 public function test_at_name_splits_into_at_and_ident (): void {
194210 $ tokens = ( new WP_MySQL_Lexer ( 'SELECT @var1 ' ) )->remaining_tokens ();
195211 $ this ->assertSame ( 'AT_SIGN ' , $ tokens [1 ]->get_name () );
@@ -749,7 +765,7 @@ public function test_ansi_quotes_changes_double_quote_tokenization(
749765 array $ sql_modes ,
750766 string $ expected_token_name
751767 ): void {
752- $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80400 , $ sql_modes ) )->remaining_tokens ();
768+ $ tokens = ( new WP_MySQL_Lexer ( $ sql , 80410 , $ sql_modes ) )->remaining_tokens ();
753769 $ this ->assertSame ( $ expected_token_name , $ tokens [0 ]->get_name (), $ sql );
754770 }
755771
@@ -782,17 +798,17 @@ public function data_national_strings(): array {
782798
783799 public function test_composite_ansi_mode_expands_to_lexer_component_modes (): void {
784800 // ANSI_QUOTES: a double-quoted sequence is a quoted identifier.
785- $ lexer = new WP_MySQL_Lexer ( '"foo" ' , 80400 , array ( 'ANSI ' ) );
801+ $ lexer = new WP_MySQL_Lexer ( '"foo" ' , 80410 , array ( 'ANSI ' ) );
786802 $ this ->assertTrue ( $ lexer ->next_token () );
787803 $ this ->assertSame ( WP_MySQL_Lexer::IDENT_QUOTED , $ lexer ->get_token ()->id );
788804
789805 // PIPES_AS_CONCAT: "||" is the string concatenation operator.
790- $ lexer = new WP_MySQL_Lexer ( '|| ' , 80400 , array ( 'ANSI ' ) );
806+ $ lexer = new WP_MySQL_Lexer ( '|| ' , 80410 , array ( 'ANSI ' ) );
791807 $ this ->assertTrue ( $ lexer ->next_token () );
792808 $ this ->assertSame ( WP_MySQL_Lexer::OR_OR_SYM , $ lexer ->get_token ()->id );
793809
794810 // IGNORE_SPACE: whitespace is permitted between a function name and "(".
795- $ lexer = new WP_MySQL_Lexer ( 'COUNT (1) ' , 80400 , array ( 'ANSI ' ) );
811+ $ lexer = new WP_MySQL_Lexer ( 'COUNT (1) ' , 80410 , array ( 'ANSI ' ) );
796812 $ this ->assertTrue ( $ lexer ->next_token () );
797813 $ this ->assertSame ( WP_MySQL_Lexer::KEYWORDS ['COUNT ' ], $ lexer ->get_token ()->id );
798814 }
@@ -808,7 +824,7 @@ public function test_quoted_identifiers_treat_backslash_literally(
808824 int $ expected_token_id ,
809825 string $ expected_value
810826 ): void {
811- $ lexer = new WP_MySQL_Lexer ( $ sql , 80400 , $ sql_modes );
827+ $ lexer = new WP_MySQL_Lexer ( $ sql , 80410 , $ sql_modes );
812828 $ this ->assertTrue ( $ lexer ->next_token () );
813829
814830 $ token = $ lexer ->get_token ();
0 commit comments