@@ -69,51 +69,77 @@ describe('sketch', () => {
69
69
} ) ;
70
70
} ) ;
71
71
72
+ describe ( 'toValidSketchFolderName' , ( ) => {
73
+ [
74
+ [ '' , Sketch . defaultSketchFolderName ] ,
75
+ [ ' ' , Sketch . defaultFallbackFirstChar ] ,
76
+ [ ' ' , Sketch . defaultFallbackFirstChar + Sketch . defaultFallbackChar ] ,
77
+ [
78
+ '0123456789012345678901234567890123456789012345678901234567890123' ,
79
+ '012345678901234567890123456789012345678901234567890123456789012' ,
80
+ ] ,
81
+ [ 'foo bar' , 'foo_bar' ] ,
82
+ [ 'vAlid' , 'vAlid' ] ,
83
+ ] . map ( ( [ input , expected ] ) =>
84
+ toMapIt ( input , expected , Sketch . toValidSketchFolderName )
85
+ ) ;
86
+ } ) ;
87
+
88
+ describe ( 'toValidSketchFolderName with timestamp suffix' , ( ) => {
89
+ const epoch = new Date ( 0 ) ;
90
+ const epochSuffix = '_copy_19700101010000' ;
91
+ [
92
+ [ '' , Sketch . defaultSketchFolderName + epochSuffix ] ,
93
+ [ ' ' , Sketch . defaultFallbackFirstChar + epochSuffix ] ,
94
+ [
95
+ ' ' ,
96
+ Sketch . defaultFallbackFirstChar +
97
+ Sketch . defaultFallbackChar +
98
+ epochSuffix ,
99
+ ] ,
100
+ [
101
+ '0123456789012345678901234567890123456789012345678901234567890123' ,
102
+ '0123456789012345678901234567890123456789012' + epochSuffix ,
103
+ ] ,
104
+ [ 'foo bar' , 'foo_bar' + epochSuffix ] ,
105
+ [ 'vAlid' , 'vAlid' + epochSuffix ] ,
106
+ ] . map ( ( [ input , expected ] ) =>
107
+ toMapIt ( input , expected , ( input : string ) =>
108
+ Sketch . toValidSketchFolderName ( input , epoch )
109
+ )
110
+ ) ;
111
+ } ) ;
112
+
72
113
describe ( 'toValidCloudSketchFolderName' , ( ) => {
73
- (
114
+ [
115
+ [ 'sketch' , 'sketch' ] ,
116
+ [ 'can-contain-slash-and-dot.ino' , 'can_contain_slash_and_dot_ino' ] ,
117
+ [ 'regex++' , 'regex__' ] ,
118
+ [ 'dots...' , 'dots___' ] ,
119
+ [ 'No Spaces' , 'No_Spaces' ] ,
120
+ [ '_startsWithUnderscore' , '_startsWithUnderscore' ] ,
121
+ [ 'Invalid+Char.ino' , 'Invalid_Char_ino' ] ,
122
+ [ '' , 'sketch' ] ,
123
+ [ '/' , '_' ] ,
124
+ [ '//trash/' , '__trash_' ] ,
74
125
[
75
- [ 'sketch' , 'sketch' ] ,
76
- [ 'can-contain-slash-and-dot.ino' , 'can_contain_slash_and_dot_ino' ] ,
77
- [ 'regex++' ] ,
78
- [ 'dots...' , 'dots___' ] ,
79
- [ 'No Spaces' ] ,
80
- [ '_invalidToStartWithUnderscore' ] ,
81
- [ 'Invalid+Char.ino' ] ,
82
- [ '' ] ,
83
- [ '/' ] ,
84
- [ '//trash/' ] ,
85
- [
86
- '63Length_012345678901234567890123456789012345678901234567890123' ,
87
- '63Length_012345678901234567890123456' ,
88
- ] ,
89
- [ 'TooLong__0123456789012345678901234567890123456789012345678901234' ] ,
90
- ] as [ string , string ?] [ ]
91
- ) . map ( ( [ input , expected ] ) => {
92
- it ( `'${ input } ' should ${ expected ? '' : 'not ' } map the ${
93
- ! expected ? 'invalid ' : ''
94
- } sketch folder name to a valid cloud sketch folder name${
95
- expected ? `: '${ expected } '` : ''
96
- } `, ( ) => {
97
- if ( ! expected ) {
98
- try {
99
- Sketch . toValidCloudSketchFolderName ( input ) ;
100
- throw new Error (
101
- `Expected an error when mapping ${ input } to a valid sketch folder name.`
102
- ) ;
103
- } catch ( err ) {
104
- if ( err instanceof Error ) {
105
- expect ( err . message ) . to . be . equal (
106
- Sketch . invalidSketchFolderNameMessage
107
- ) ;
108
- } else {
109
- throw err ;
110
- }
111
- }
112
- } else {
113
- const actual = Sketch . toValidCloudSketchFolderName ( input ) ;
114
- expect ( actual ) . to . be . equal ( expected ) ;
115
- }
116
- } ) ;
117
- } ) ;
126
+ '63Length_012345678901234567890123456789012345678901234567890123' ,
127
+ '63Length_012345678901234567890123456' ,
128
+ ] ,
129
+ ] . map ( ( [ input , expected ] ) =>
130
+ toMapIt ( input , expected , Sketch . toValidCloudSketchFolderName , true )
131
+ ) ;
118
132
} ) ;
119
133
} ) ;
134
+
135
+ function toMapIt (
136
+ input : string ,
137
+ expected : string ,
138
+ testMe : ( input : string ) => string ,
139
+ cloud = false
140
+ ) : Mocha . Test {
141
+ return it ( `should map the '${ input } ' ${
142
+ cloud ? 'cloud ' : ''
143
+ } sketch folder name to '${ expected } '`, ( ) =>
144
+ expect ( testMe ( input ) ) . to . be . equal ( expected ) ) ;
145
+ }
0 commit comments