Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit e8ef49b

Browse files
committed
updated tests to check for proper replacement of literals
1 parent a783032 commit e8ef49b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

spec/text-buffer-spec.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@ const path = require('path')
22
const TextBuffer = require('../src/text-buffer')
33

44
describe('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(/\bfoo\(\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(/tstat_fvars\(\)->curr_setpoint\[(.+?)\] = (.+?);/, '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(/tstat_fvars\(\)->curr_setpoint\[(.+?)\] = (.+?);/, '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(/\.(atom)\./, '$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

Comments
 (0)