@@ -2,23 +2,31 @@ const path = require('path')
22const TextBuffer = require ( '../src/text-buffer' )
33
44describe ( 'when a buffer is already open' , ( ) => {
5+ const filePath = path . join ( __dirname , 'fixtures' , 'sample.js' )
6+ const buffer = new TextBuffer ( )
7+
58 it ( 'replaces foo( with bar( using /\bfoo\\(\b/gim' , ( ) => {
6- const filePath = path . join ( __dirname , 'fixtures' , 'sample.js' )
7- const buffer = new TextBuffer ( )
89 buffer . setPath ( filePath )
910 buffer . setText ( 'foo(x)' )
1011 buffer . replace ( / \b f o o \( \b / gim, 'bar(' )
1112
1213 expect ( buffer . getText ( ) ) . toBe ( 'bar(x)' )
1314 } )
1415
15- it ( 'replaces tstat_fvars()->curr_setpoint[HEAT_EN] = new_tptr->heat_limit; with tstat_set_curr_setpoint(HEAT_EN, new_tptr->heat_limit);' , ( ) => {
16- const filePath = path . join ( __dirname , 'fixtures' , 'sample.js' )
17- const buffer = new TextBuffer ( )
18- buffer . setPath ( filePath )
19- buffer . setText ( 'if (tstat_fvars()->curr_setpoint[HEAT_EN] > new_tptr->heat_limit) { tstat_fvars()->curr_setpoint[HEAT_EN] = new_tptr->heat_limit; }' )
20- buffer . replace ( / t s t a t _ f v a r s \( \) - > c u r r _ s e t p o i n t \[ ( .+ ?) \] = ( .+ ?) ; / , 'tstat_set_curr_setpoint($1, $2);' )
16+ describe ( 'should properly replace regex literals' , ( ) => {
17+ it ( 'replaces tstat_fvars()->curr_setpoint[HEAT_EN] = new_tptr->heat_limit; with tstat_set_curr_setpoint(HEAT_EN, new_tptr->heat_limit);' , ( ) => {
18+ buffer . setPath ( filePath )
19+ buffer . setText ( 'tstat_fvars()->curr_setpoint[HEAT_EN] = new_tptr->heat_limit;' )
20+ buffer . replace ( / t s t a t _ f v a r s \( \) - > c u r r _ s e t p o i n t \[ ( .+ ?) \] = ( .+ ?) ; / , 'tstat_set_curr_setpoint($1, $2);' )
21+
22+ expect ( buffer . getText ( ) ) . toBe ( 'tstat_set_curr_setpoint(HEAT_EN, new_tptr->heat_limit);' )
23+ } )
24+
25+ it ( 'replaces atom/flight-manual.atom.io with atom/flight-manualatomio' , ( ) => {
26+ buffer . setText ( 'atom/flight-manual.atom.io' )
27+ buffer . replace ( / \. ( a t o m ) \. / , '$1' )
2128
22- expect ( buffer . getText ( ) ) . toBe ( 'if (tstat_fvars()->curr_setpoint[HEAT_EN] > new_tptr->heat_limit) { tstat_set_curr_setpoint(HEAT_EN, new_tptr->heat_limit); }' )
29+ expect ( buffer . getText ( ) ) . toBe ( 'atom/flight-manualatomio' )
30+ } )
2331 } )
2432} )
0 commit comments