@@ -3,9 +3,26 @@ import DbNameValidator from './DbNameValidator';
33const TABLE_PREFIX = 'table_' ;
44const COLUMN_PREFIX = 'column_' ;
55
6- const VALID_TABLE_NAME = '$+@abc-123_ABC' ;
7- const INVALID_TABLE_NAMES = [ '%^&ab-c' , '-abc' , '-' ] ;
8- const CLEANED_INVALID_TABLE_NAMES = [ 'ab-c' , '-abc' , '-' ] ;
6+ const VALID_TABLE_NAMES = [ '$+@abc-123_ABC' , '$' ] ;
7+ const VARIABLE_NAMES_FROM_VALID = [ '___abc_123_ABC' , '_' ] ;
8+
9+ const INVALID_TABLE_NAMES = [ '%^&ab-c' , '-a_b c' , '-' , '0' , '%' , '' ] ;
10+ const LEGALIZED_INVALID_TABLE_NAMES = [
11+ 'ab-c' ,
12+ 'table_-a_b_c' ,
13+ 'table_-' ,
14+ 'table_0' ,
15+ 'table_0' ,
16+ 'table_0' ,
17+ ] ;
18+ const VARIABLE_NAMES_FROM_INVALID = [
19+ 'ab_c' ,
20+ 'table__a_b_c' ,
21+ 'table__' ,
22+ 'table_0' ,
23+ 'table_0' ,
24+ 'table_0' ,
25+ ] ;
926
1027const VALID_COL_NAME = 'abc123_ABC' ;
1128const INVALID_COL_NAME = '@abc123_ABC-123' ;
@@ -16,8 +33,8 @@ const RESERVED_JAVA_WORD = 'return';
1633const RESERVED_DEEPHAVEN_WORD = 'not' ;
1734
1835describe ( 'Table name validation' , ( ) => {
19- it ( 'Returns true on valid table names ' , ( ) => {
20- expect ( DbNameValidator . isValidTableName ( VALID_TABLE_NAME ) ) . toBe ( true ) ;
36+ it . each ( VALID_TABLE_NAMES ) ( 'Returns true on valid table name %s ' , name => {
37+ expect ( DbNameValidator . isValidTableName ( name ) ) . toBe ( true ) ;
2138 } ) ;
2239
2340 it . each ( INVALID_TABLE_NAMES ) (
@@ -49,14 +66,15 @@ describe('Column name validation', () => {
4966} ) ;
5067
5168describe ( 'legalizeTableName' , ( ) => {
52- it ( 'Does not change a valid table name' , ( ) => {
53- expect ( DbNameValidator . legalizeTableName ( VALID_TABLE_NAME ) ) . toBe (
54- VALID_TABLE_NAME
55- ) ;
69+ it . each ( VALID_TABLE_NAMES ) ( 'Does not change a valid table name %s' , name => {
70+ expect ( DbNameValidator . legalizeTableName ( name ) ) . toBe ( name ) ;
5671 } ) ;
5772
5873 it . each (
59- INVALID_TABLE_NAMES . map ( ( name , i ) => [ name , CLEANED_INVALID_TABLE_NAMES [ i ] ] )
74+ INVALID_TABLE_NAMES . map ( ( name , i ) => [
75+ name ,
76+ LEGALIZED_INVALID_TABLE_NAMES [ i ] ,
77+ ] )
6078 ) ( 'Legalize an invalid table name %s > %s' , ( invalid , cleaned ) => {
6179 expect ( DbNameValidator . legalizeTableName ( invalid ) ) . toBe ( cleaned ) ;
6280 } ) ;
@@ -72,6 +90,25 @@ describe('legalizeTableName', () => {
7290 } ) ;
7391} ) ;
7492
93+ describe ( 'makeVariableName' , ( ) => {
94+ it . each (
95+ VALID_TABLE_NAMES . map ( ( name , i ) => [ name , VARIABLE_NAMES_FROM_VALID [ i ] ] )
96+ ) (
97+ 'Makes a variable name for a valid table name %s > %s' ,
98+ ( invalid , variableName ) => {
99+ expect ( DbNameValidator . makeVariableName ( invalid ) ) . toBe ( variableName ) ;
100+ }
101+ ) ;
102+ it . each (
103+ INVALID_TABLE_NAMES . map ( ( name , i ) => [ name , VARIABLE_NAMES_FROM_INVALID [ i ] ] )
104+ ) (
105+ 'Makes a variable name for an invalid table name %s > %s' ,
106+ ( invalid , variableName ) => {
107+ expect ( DbNameValidator . makeVariableName ( invalid ) ) . toBe ( variableName ) ;
108+ }
109+ ) ;
110+ } ) ;
111+
75112describe ( 'legalizeColumnName' , ( ) => {
76113 it ( 'Does not change a valid column name' , ( ) => {
77114 expect ( DbNameValidator . legalizeColumnName ( VALID_COL_NAME ) ) . toBe (
0 commit comments