@@ -317,3 +317,41 @@ tape( 'the function returns an empty array if provided an empty string', functio
317
317
t . equal ( out . length , 0 , 'array length is zero' ) ;
318
318
t . end ( ) ;
319
319
} ) ;
320
+
321
+ tape ( 'the function correctly handles punctuation within quotation marks' , function test ( t ) {
322
+ var expected ;
323
+ var actual ;
324
+ var str ;
325
+
326
+ str = 'I said "Look out" right before he banged his head.' ;
327
+ expected = [ 'I said "Look out" right before he banged his head.' ] ;
328
+ actual = sentencize ( str ) ;
329
+ t . deepEqual ( actual , expected , 'keeps sentence with simple quotes together' ) ;
330
+
331
+ str = 'I said "Look out!" right before he banged his head.' ;
332
+ expected = [ 'I said "Look out!" right before he banged his head.' ] ;
333
+ actual = sentencize ( str ) ;
334
+ t . deepEqual ( actual , expected , 'keeps sentence with exclamation in quotes together' ) ;
335
+
336
+ str = 'He asked "What time is it?" before leaving.' ;
337
+ expected = [ 'He asked "What time is it?" before leaving.' ] ;
338
+ actual = sentencize ( str ) ;
339
+ t . deepEqual ( actual , expected , 'keeps sentence with question mark in quotes together' ) ;
340
+
341
+ str = '"Stop!" he yelled. "We need to think about this."' ;
342
+ expected = [ '"Stop!" he yelled.' , '"We need to think about this."' ] ;
343
+ actual = sentencize ( str ) ;
344
+ t . deepEqual ( actual , expected , 'correctly splits multiple quoted sentences' ) ;
345
+
346
+ str = 'She said "This is great!" and smiled.' ;
347
+ expected = [ 'She said "This is great!" and smiled.' ] ;
348
+ actual = sentencize ( str ) ;
349
+ t . deepEqual ( actual , expected , 'keeps sentence with exclamation in middle quotes together' ) ;
350
+
351
+ str = '"Is this correct?" he wondered. "I think so!" she replied.' ;
352
+ expected = [ '"Is this correct?" he wondered.' , '"I think so!" she replied.' ] ;
353
+ actual = sentencize ( str ) ;
354
+ t . deepEqual ( actual , expected , 'correctly handles multiple quoted sentences with different punctuation' ) ;
355
+
356
+ t . end ( ) ;
357
+ } ) ;
0 commit comments