Skip to content

Commit 21ca457

Browse files
committed
fix more lint, use built-in jest test data iteration
1 parent d4d2500 commit 21ca457

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

packages/_example-extractor/src/api.spec.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,39 @@ const EXAMPLE = `%%foo
88
bar
99
`;
1010

11-
const EXPECTED: IExtractedCode = {
12-
foreign_code: 'bar\n',
13-
host_code: EXAMPLE,
14-
range: { end: { column: 0, line: 2 }, start: { column: 0, line: 1 } },
15-
virtual_shift: null
11+
let FIXTURES: { [key: string]: IExtractedCode } = {
12+
'does extract foo': {
13+
foreign_code: 'bar\n',
14+
host_code: EXAMPLE,
15+
range: { end: { column: 0, line: 2 }, start: { column: 0, line: 1 } },
16+
virtual_shift: null
17+
},
18+
'does NOT extract bar': {
19+
foreign_code: null,
20+
host_code: 'baz',
21+
range: null,
22+
virtual_shift: null
23+
},
24+
'does NOT extract foobar': {
25+
foreign_code: null,
26+
host_code: EXAMPLE.replace('foo', 'foobar'),
27+
range: null,
28+
virtual_shift: null
29+
}
1630
};
1731

18-
const NOT_EXPECTED: IExtractedCode = {
19-
foreign_code: null,
20-
host_code: 'baz',
21-
range: null,
22-
virtual_shift: null
32+
FIXTURES['does extract foo -v bar'] = {
33+
...FIXTURES['does extract foo'],
34+
host_code: EXAMPLE.replace('foo', 'foo -v')
2335
};
2436

2537
describe('The foo extractor', () => {
26-
it('extracts %%foo bar', () => {
27-
const extracted = extractor.extract_foreign_code(EXAMPLE);
28-
expect(extracted).to.have.length(1);
29-
expect(extracted[0]).to.deep.equal(EXPECTED);
30-
});
31-
it('does not extract baz', () => {
32-
const extracted = extractor.extract_foreign_code('baz');
33-
expect(extracted).to.have.length(1);
34-
expect(extracted[0]).to.deep.equal(NOT_EXPECTED);
35-
});
38+
test.each(Object.entries(FIXTURES))(
39+
'%s',
40+
(_: string, expected: IExtractedCode) => {
41+
const extracted = extractor.extract_foreign_code(expected.host_code);
42+
expect(extracted).to.have.length(1);
43+
expect(extracted[0]).to.deep.equal(expected);
44+
}
45+
);
3646
});

packages/jupyterlab-lsp/src/extractors/regexp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('getIndexOfCaptureGroup', () => {
3030
it('extracts index of a captured group', () => {
3131
// tests for https://github.com/krassowski/jupyterlab-lsp/issues/559
3232
let result = getIndexOfCaptureGroup(
33-
new RegExp('^%%(python|python2|python3|pypy)( .*?)?\n([^]*)'),
33+
new RegExp('^%%(python|python2|python3|pypy)( .*?)?\\n([^]*)'),
3434
'%%python\nh',
3535
'h'
3636
);
@@ -59,7 +59,7 @@ describe('RegExpForeignCodeExtractor', () => {
5959

6060
let python_cell_extractor = new RegExpForeignCodeExtractor({
6161
language: 'python',
62-
pattern: '^%%(python|python2|python3|pypy)( .*?)?\n([^]*)',
62+
pattern: '^%%(python|python2|python3|pypy)( .*?)?\\n([^]*)',
6363
foreign_capture_groups: [3],
6464
keep_in_host: true,
6565
is_standalone: true,

0 commit comments

Comments
 (0)