Skip to content

Commit b871342

Browse files
committed
getCodeBlocks()がタイトル行の行IDのfilterに対応
1 parent ee8566b commit b871342

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

rest/__snapshots__/getCodeBlocks.test.ts.snap

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,46 @@ snapshot[`getCodeBlocks() > language name filter 1`] = `
335335
},
336336
]
337337
`;
338+
339+
snapshot[`getCodeBlocks() > title line ID filter 1`] = `
340+
[
341+
{
342+
bodyLines: [
343+
{
344+
created: 1672982822,
345+
id: "63b7b1261280f00000c9bc35",
346+
text: " #include <iostream>",
347+
updated: 1672982822,
348+
userId: "5ef2bdebb60650001e1280f0",
349+
},
350+
{
351+
created: 1672982822,
352+
id: "63b7b1261280f00000c9bc36",
353+
text: " ",
354+
updated: 1672982822,
355+
userId: "5ef2bdebb60650001e1280f0",
356+
},
357+
],
358+
filename: "main.cpp",
359+
lang: "cpp",
360+
nextLine: {
361+
created: 1672982822,
362+
id: "63b7b1261280f00000c9bc37",
363+
text: " main函数の定義",
364+
updated: 1672982822,
365+
userId: "5ef2bdebb60650001e1280f0",
366+
},
367+
pageInfo: {
368+
pageTitle: "コードブロック記法",
369+
projectName: "takker",
370+
},
371+
titleLine: {
372+
created: 1672982822,
373+
id: "63b7b1261280f00000c9bc34",
374+
text: " code:main.cpp",
375+
updated: 1672982822,
376+
userId: "5ef2bdebb60650001e1280f0",
377+
},
378+
},
379+
]
380+
`;

rest/getCodeBlocks.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,16 @@ Deno.test("getCodeBlocks()", async (t) => {
257257
await Promise.all(yet);
258258
await assertSnapshot(st, codeBlocks);
259259
});
260+
await t.step("title line ID filter", async (st) => {
261+
const titleLineId = "63b7b1261280f00000c9bc34";
262+
const codeBlocks = await getCodeBlocks({ project, title, lines: sample }, {
263+
titleLineId,
264+
});
265+
const yet = [];
266+
for (const codeBlock of codeBlocks) {
267+
yet.push(assertEquals(codeBlock.titleLine.id, titleLineId));
268+
}
269+
await Promise.all(yet);
270+
await assertSnapshot(st, codeBlocks);
271+
});
260272
});

rest/getCodeBlocks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface GetCodeBlocksFilter {
3232
filename?: string;
3333
/** syntax highlightに使用されている言語名 */
3434
lang?: string;
35+
/** タイトル行の行ID */
36+
titleLineId?: string;
3537
}
3638

3739
/** 他のページ(または取得済みの行データ)のコードブロックを全て取得する
@@ -111,7 +113,8 @@ function isMatchFilter(
111113
const equals = (a: unknown, b: unknown) => !a || a === b;
112114
return (
113115
equals(filter?.filename, codeBlock.filename) &&
114-
equals(filter?.lang, codeBlock.lang)
116+
equals(filter?.lang, codeBlock.lang) &&
117+
equals(filter?.titleLineId, codeBlock.titleLine.id)
115118
);
116119
}
117120

0 commit comments

Comments
 (0)