Skip to content

Commit

Permalink
Bug fixed and unit test case added
Browse files Browse the repository at this point in the history
  • Loading branch information
ronzulu committed Mar 20, 2024
1 parent 7817705 commit d30d88b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
4 changes: 2 additions & 2 deletions src/NoteQuestionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class NoteQuestionParser {
let frontmatterLineCount: number = null;
if (filteredTagCacheList.length > 0) {
// To simplify analysis, ensure that the supplied list is ordered by line number
tagCacheList.sort((a, b) => a.position.start.line - b.position.start.line);
filteredTagCacheList.sort((a, b) => a.position.start.line - b.position.start.line);

// Treat the frontmatter slightly differently (all tags grouped together even if on separate lines)
const [frontmatter, _] = extractFrontmatter(this.noteText);
Expand All @@ -200,7 +200,7 @@ export class NoteQuestionParser {

// Doesn't matter what line number we specify, as long as it's less than frontmatterLineCount
if (frontmatterTagCacheList.length > 0)
frontmatterTopicPathList = this.createTopicPathList(tagCacheList, 0);
frontmatterTopicPathList = this.createTopicPathList(frontmatterTagCacheList, 0);
}
}
//
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/NoteQuestionParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,57 @@ A::B
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});

test("SingleLineBasic: Multiple topics", async () => {
let noteText: string = `#flashcards/science #flashcards/poetry
A::B
`;
let noteFile: ISRFile = new UnitTestSRFile(noteText);

let folderTopicPath: TopicPath = TopicPath.emptyPath;
let expected = [
{
questionType: CardType.SingleLineBasic,
topicPathList: TopicPathList.fromPsv("#flashcards/science|#flashcards/poetry", 0),
questionText: {
original: `A::B`,
actualQuestion: "A::B",
},
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});

// https://github.com/st3v3nmw/obsidian-spaced-repetition/issues/908
test("SingleLineBasic: Multiple tags in note (including non-flashcard ones)", async () => {
let noteText: string = `---
created: 2024-03-11 10:41
tags:
- flashcards
- data-structure
---
#2024/03-11
**What is a Heap?**
?
In computer-science, a *heap* is a tree-based data-structure, that satisfies the *heap property*. A heap is a complete *binary-tree*!
`;
let noteFile: ISRFile = new UnitTestSRFile(noteText);

let folderTopicPath: TopicPath = TopicPath.emptyPath;
let expected = [
{
questionType: CardType.MultiLineBasic,
// Explicitly checking that #data-structure and #2024/03-11 are not included
topicPathList: TopicPathList.fromPsv("#flashcards", 0),
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});
});

describe("Single question in the text (with block identifier)", () => {
Expand Down

0 comments on commit d30d88b

Please sign in to comment.