@@ -3,10 +3,27 @@ import DbNameValidator from './DbNameValidator';
33const TABLE_PREFIX = 'table_' ;
44const COLUMN_PREFIX = 'column_' ;
55
6- const VALID_TABLE_NAME = '$+@abc-123_ABC' ;
7- const CLEANED_VALID_TABLE_NAME = 'abc_123_ABC' ;
8- const INVALID_TABLE_NAMES = [ '%^&ab-c' , '-a_b c' , '-' ] ;
9- const CLEANED_INVALID_TABLE_NAMES = [ 'ab_c' , '_a_b_c' , '_' ] ;
6+ // $ is not a valid table name in Deephaven, but this behavior is consistent with the Java class
7+ const VALID_TABLE_NAMES = [ '$+@abc-123_ABC' , '$' ] ;
8+ const VARIABLE_NAMES_FROM_VALID = [ '$__abc_123_ABC' , '$' ] ;
9+
10+ const INVALID_TABLE_NAMES = [ '%^&ab-c' , '-a_b c' , '-' , '0' , '%' , '' ] ;
11+ const LEGALIZED_INVALID_TABLE_NAMES = [
12+ 'ab-c' ,
13+ 'table_-a_b_c' ,
14+ 'table_-' ,
15+ 'table_0' ,
16+ 'table_0' ,
17+ 'table_0' ,
18+ ] ;
19+ const VARIABLE_NAMES_FROM_INVALID = [
20+ 'ab_c' ,
21+ 'table__a_b_c' ,
22+ 'table__' ,
23+ 'table_0' ,
24+ 'table_0' ,
25+ 'table_0' ,
26+ ] ;
1027
1128const VALID_COL_NAME = 'abc123_ABC' ;
1229const INVALID_COL_NAME = '@abc123_ABC-123' ;
@@ -17,8 +34,8 @@ const RESERVED_JAVA_WORD = 'return';
1734const RESERVED_DEEPHAVEN_WORD = 'not' ;
1835
1936describe ( 'Table name validation' , ( ) => {
20- it ( 'Returns true on valid table names ' , ( ) => {
21- expect ( DbNameValidator . isValidTableName ( VALID_TABLE_NAME ) ) . toBe ( true ) ;
37+ it . each ( VALID_TABLE_NAMES ) ( 'Returns true on valid table name %s ' , name => {
38+ expect ( DbNameValidator . isValidTableName ( name ) ) . toBe ( true ) ;
2239 } ) ;
2340
2441 it . each ( INVALID_TABLE_NAMES ) (
@@ -50,14 +67,15 @@ describe('Column name validation', () => {
5067} ) ;
5168
5269describe ( 'legalizeTableName' , ( ) => {
53- it ( 'Sanitizes a table name even if it is valid' , ( ) => {
54- expect ( DbNameValidator . legalizeTableName ( VALID_TABLE_NAME ) ) . toBe (
55- CLEANED_VALID_TABLE_NAME
56- ) ;
70+ it . each ( VALID_TABLE_NAMES ) ( 'Does not change a valid table name $s' , name => {
71+ expect ( DbNameValidator . legalizeTableName ( name ) ) . toBe ( name ) ;
5772 } ) ;
5873
5974 it . each (
60- INVALID_TABLE_NAMES . map ( ( name , i ) => [ name , CLEANED_INVALID_TABLE_NAMES [ i ] ] )
75+ INVALID_TABLE_NAMES . map ( ( name , i ) => [
76+ name ,
77+ LEGALIZED_INVALID_TABLE_NAMES [ i ] ,
78+ ] )
6179 ) ( 'Legalize an invalid table name %s > %s' , ( invalid , cleaned ) => {
6280 expect ( DbNameValidator . legalizeTableName ( invalid ) ) . toBe ( cleaned ) ;
6381 } ) ;
@@ -73,6 +91,25 @@ describe('legalizeTableName', () => {
7391 } ) ;
7492} ) ;
7593
94+ describe ( 'makeVariableName' , ( ) => {
95+ it . each (
96+ VALID_TABLE_NAMES . map ( ( name , i ) => [ name , VARIABLE_NAMES_FROM_VALID [ i ] ] )
97+ ) (
98+ 'Makes a variable name for a valid table name %s > %s' ,
99+ ( invalid , variableName ) => {
100+ expect ( DbNameValidator . makeVariableName ( invalid ) ) . toBe ( variableName ) ;
101+ }
102+ ) ;
103+ it . each (
104+ INVALID_TABLE_NAMES . map ( ( name , i ) => [ name , VARIABLE_NAMES_FROM_INVALID [ i ] ] )
105+ ) (
106+ 'Makes a variable name for an invalid table name %s > %s' ,
107+ ( invalid , variableName ) => {
108+ expect ( DbNameValidator . makeVariableName ( invalid ) ) . toBe ( variableName ) ;
109+ }
110+ ) ;
111+ } ) ;
112+
76113describe ( 'legalizeColumnName' , ( ) => {
77114 it ( 'Does not change a valid column name' , ( ) => {
78115 expect ( DbNameValidator . legalizeColumnName ( VALID_COL_NAME ) ) . toBe (
0 commit comments