@@ -42,6 +42,9 @@ describe("fileNameParser", () => {
4242 should ( parser ( "thefile.log.biscuits" ) ) . not . be . ok ( ) ;
4343 should ( parser ( "thefile.log.2019" ) ) . not . be . ok ( ) ;
4444 should ( parser ( "thefile.log.3.2" ) ) . not . be . ok ( ) ;
45+ should ( parser ( "thefile.log.04-18" ) ) . not . be . ok ( ) ;
46+ should ( parser ( "anotherfile.log.2020-04-18" ) ) . not . be . ok ( ) ;
47+ should ( parser ( "2020-05-18" ) ) . not . be . ok ( ) ;
4548 } ) ;
4649 it ( "should take a filename and return the date" , ( ) => {
4750 parser ( "thefile.log.2019-07-17" ) . should . eql ( {
@@ -112,7 +115,7 @@ describe("fileNameParser", () => {
112115 pattern : "mm"
113116 } ) ;
114117 it ( "should take a filename and return the date" , ( ) => {
115- const expectedTimestamp = new Date ( 0 , 0 ) ;
118+ const expectedTimestamp = new Date ( 0 , 0 ) ;
116119 expectedTimestamp . setMinutes ( 34 ) ;
117120 parser ( "thing.log.34" ) . should . eql ( {
118121 filename : "thing.log.34" ,
@@ -123,4 +126,55 @@ describe("fileNameParser", () => {
123126 } ) ;
124127 } ) ;
125128 } )
129+
130+ describe ( "with a four-digit date pattern" , ( ) => {
131+ const parser = require ( "../lib/fileNameParser" ) ( {
132+ file : {
133+ dir : "/path/to/file" ,
134+ base : "stuff.log" ,
135+ ext : ".log" ,
136+ name : "stuff"
137+ } ,
138+ pattern : "mm-ss"
139+ } ) ;
140+ it ( "should return null for files that do not match" , ( ) => {
141+ should ( parser ( "stuff.log.2020-04-18" ) ) . not . be . ok ( ) ;
142+ should ( parser ( "09-18" ) ) . not . be . ok ( ) ;
143+ } ) ;
144+ it ( "should take a filename and return the date" , ( ) => {
145+ const expectedTimestamp = new Date ( 0 , 0 ) ;
146+ expectedTimestamp . setMinutes ( 34 ) ;
147+ expectedTimestamp . setSeconds ( 59 ) ;
148+ parser ( "stuff.log.34-59" ) . should . eql ( {
149+ filename : "stuff.log.34-59" ,
150+ date : "34-59" ,
151+ isCompressed : false ,
152+ index : 0 ,
153+ timestamp : expectedTimestamp . getTime ( )
154+ } ) ;
155+ } ) ;
156+ it ( "should take a filename and return both date and index" , ( ) => {
157+ const expectedTimestamp_1 = new Date ( 0 , 0 ) ;
158+ expectedTimestamp_1 . setMinutes ( 7 ) ;
159+ expectedTimestamp_1 . setSeconds ( 17 ) ;
160+ parser ( "stuff.log.07-17.2" ) . should . eql ( {
161+ filename : "stuff.log.07-17.2" ,
162+ index : 2 ,
163+ date : "07-17" ,
164+ timestamp : expectedTimestamp_1 . getTime ( ) ,
165+ isCompressed : false
166+ } ) ;
167+ const expectedTimestamp_2 = new Date ( 0 , 0 ) ;
168+ expectedTimestamp_2 . setMinutes ( 17 ) ;
169+ expectedTimestamp_2 . setSeconds ( 30 ) ;
170+ parser ( "stuff.log.17-30.3.gz" ) . should . eql ( {
171+ filename : "stuff.log.17-30.3.gz" ,
172+ index : 3 ,
173+ date : "17-30" ,
174+ timestamp : expectedTimestamp_2 . getTime ( ) ,
175+ isCompressed : true
176+ } ) ;
177+ } ) ;
178+ } )
179+
126180} ) ;
0 commit comments