@@ -2,13 +2,19 @@ import test from 'ava';
22import trimNewlines from './index.js' ;
33
44test ( 'main' , t => {
5+ t . is ( trimNewlines ( '' ) , '' ) ;
6+ t . is ( trimNewlines ( ' ' ) , ' ' ) ;
7+ t . is ( trimNewlines ( '\n\n\r' ) , '' ) ;
58 t . is ( trimNewlines ( '\nx\n' ) , 'x' ) ;
69 t . is ( trimNewlines ( '\n\n\nx\n\n\n' ) , 'x' ) ;
710 t . is ( trimNewlines ( '\r\nx\r\n' ) , 'x' ) ;
811 t . is ( trimNewlines ( '\n\r\n\nx\n\r\n\n' ) , 'x' ) ;
912} ) ;
1013
1114test ( 'start' , t => {
15+ t . is ( trimNewlines . start ( '' ) , '' ) ;
16+ t . is ( trimNewlines . start ( ' ' ) , ' ' ) ;
17+ t . is ( trimNewlines . start ( '\n\n\r' ) , '' ) ;
1218 t . is ( trimNewlines . start ( '\nx' ) , 'x' ) ;
1319 t . is ( trimNewlines . start ( '\r\nx' ) , 'x' ) ;
1420 t . is ( trimNewlines . start ( '\n\n\n\nx' ) , 'x' ) ;
@@ -17,9 +23,42 @@ test('start', t => {
1723} ) ;
1824
1925test ( 'end' , t => {
26+ t . is ( trimNewlines . end ( '' ) , '' ) ;
27+ t . is ( trimNewlines . end ( ' ' ) , ' ' ) ;
28+ t . is ( trimNewlines . end ( '\n\n\r' ) , '' ) ;
2029 t . is ( trimNewlines . end ( 'x\n' ) , 'x' ) ;
2130 t . is ( trimNewlines . end ( 'x\r\n' ) , 'x' ) ;
2231 t . is ( trimNewlines . end ( 'x\n\n\n\n' ) , 'x' ) ;
2332 t . is ( trimNewlines . end ( 'x\n\n\r\n\n' ) , 'x' ) ;
2433 t . is ( trimNewlines . end ( '\n\n\r\n\nx' ) , '\n\n\r\n\nx' ) ;
2534} ) ;
35+
36+ test ( 'main - does not have exponential performance' , t => {
37+ for ( let index = 0 ; index < 45000 ; index += 1000 ) {
38+ const string = String ( Array . from ( { length : index } ) . fill ( '\n' ) . join ( '' ) ) + 'a' + String ( Array . from ( { length : index } ) . fill ( '\n' ) . join ( '' ) ) ;
39+ const start = Date . now ( ) ;
40+ trimNewlines ( string ) ;
41+ const difference = Date . now ( ) - start ;
42+ t . true ( difference < 10 , `Execution time: ${ difference } ` ) ;
43+ }
44+ } ) ;
45+
46+ test ( 'start - does not have exponential performance' , t => {
47+ for ( let index = 0 ; index < 45000 ; index += 1000 ) {
48+ const string = String ( Array . from ( { length : index } ) . fill ( '\n' ) . join ( '' ) ) + 'a' ;
49+ const start = Date . now ( ) ;
50+ trimNewlines . start ( string ) ;
51+ const difference = Date . now ( ) - start ;
52+ t . true ( difference < 10 , `Execution time: ${ difference } ` ) ;
53+ }
54+ } ) ;
55+
56+ test ( 'end - does not have exponential performance' , t => {
57+ for ( let index = 0 ; index < 45000 ; index += 1000 ) {
58+ const string = 'a' + String ( Array . from ( { length : index } ) . fill ( '\n' ) . join ( '' ) ) ;
59+ const start = Date . now ( ) ;
60+ trimNewlines . end ( string ) ;
61+ const difference = Date . now ( ) - start ;
62+ t . true ( difference < 10 , `Execution time: ${ difference } ` ) ;
63+ }
64+ } ) ;
0 commit comments