8000 Handle the no match case. (#460) · joernalraun/python-editor-next@c037a61 · GitHub
[go: up one dir, main page]

Skip to content

Commit c037a61

Browse files
Handle the no match case. (microbit-foundation#460)
Previously returned truncated first/last/only text extract.
1 parent 582e7ac commit c037a61

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/documentation/extracts.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ describe("contextExtracts", () => {
2525
{ type: "match", extract: "match" },
2626
]);
2727
});
28+
it("no match", () => {
29+
expect(contextExtracts([], "match", 3)).toEqual([]);
30+
});
2831
it("splits text between matches", () => {
2932
expect(
3033
contextExtracts(

src/documentation/extracts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export const contextExtracts = (
6060
text: string,
6161
context: number = 10
6262
): Extract[] => {
63+
if (positions.length === 0) {
64+
return [];
65+
}
6366
const extracts = fullStringExtracts(positions, text);
6467
return extracts.map((e, index) => {
6568
const length = e.extract.length;

0 commit comments

Comments
 (0)
0