@@ -2,13 +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 } )
15+
16+ describe ( 'Texts should be replaced properly with strings containing literals when using the regex option' , ( ) => {
17+ it ( 'replaces tstat_fvars()->curr_setpoint[HEAT_EN] with tstat_set_curr_setpoint($1, $2);' , ( ) => {
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-manualatomio with $1' , ( ) => {
26+ buffer . setText ( 'atom/flight-manualatomio' )
27+ buffer . replace ( / \. ( a t o m ) \. / , '$1' )
28+
29+ expect ( buffer . getText ( ) ) . toBe ( 'atom/flight-manualatomio' )
30+ } )
31+ } )
1432} )
0 commit comments