-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,37 +99,16 @@ test('noteNamesFuzzyMatchSlashes', () => { | |
'link-topic' | ||
); | ||
// lower case is expected because 'slugifyTitle' includes toLowerCase | ||
expect(NoteWorkspace.slugifyTitle('Link/Topic')).toEqual( | ||
'link-topic' | ||
); | ||
expect(NoteWorkspace.normalizeNoteNameForFuzzyMatchText('Link/Topic')).toEqual( | ||
'link-topic' | ||
); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/Topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/Topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/Topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/topic') | ||
).toBeTruthy(); | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/Topic') | ||
).toBeTruthy(); | ||
|
||
expect(NoteWorkspace.slugifyTitle('Link/Topic')).toEqual('link-topic'); | ||
expect(NoteWorkspace.normalizeNoteNameForFuzzyMatchText('Link/Topic')).toEqual('link-topic'); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/Topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/Topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/Topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/topic')).toBeTruthy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/Topic')).toBeTruthy(); | ||
}); | ||
|
||
test('noteNamesFuzzyMatch', () => { | ||
|
@@ -199,8 +178,7 @@ test('Note.tagSet', () => { | |
expect(tags).toEqual(new Set(['#another_tag', '#tag'])); | ||
}); | ||
|
||
|
||
describe("Wikilinks", () => { | ||
describe('WikiLinks', () => { | ||
beforeEach(() => { | ||
NoteWorkspace.cfg = () => { | ||
let config = NoteWorkspace.DEFAULT_CONFIG; | ||
|
@@ -210,74 +188,60 @@ describe("Wikilinks", () => { | |
}); | ||
|
||
test('cleanPipedWikiLinks', () => { | ||
|
||
expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( | ||
"file" | ||
); | ||
expect(NoteWorkspace.cleanPipedWikiLink("description with lots of spaces, and other symbols|file.md")).toEqual( | ||
"file.md" | ||
); | ||
expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( | ||
"file" | ||
); | ||
|
||
expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('file'); | ||
expect( | ||
NoteWorkspace.cleanPipedWikiLink('description with lots of spaces, and other symbols|file.md') | ||
).toEqual('file.md'); | ||
expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('file'); | ||
|
||
// Odd case, but I suppose it should be treated | ||
expect(NoteWorkspace.cleanPipedWikiLink("description|file|but-with-a-pipe-symbol.md")).toEqual( | ||
"file|but-with-a-pipe-symbol.md" | ||
expect(NoteWorkspace.cleanPipedWikiLink('description|file|but-with-a-pipe-symbol.md')).toEqual( | ||
'file|but-with-a-pipe-symbol.md' | ||
); | ||
|
||
}); | ||
test("NoteWorkspace.noteNamesFuzzyMatch", () => { | ||
test('NoteWorkspace.noteNamesFuzzyMatch', () => { | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md') | ||
).toBeTruthy(); | ||
|
||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description |filename.md') | ||
).toBeTruthy(); | ||
|
||
}); | ||
|
||
// Tests the different settings for piped wikilinks | ||
test("Config changes", () => { | ||
|
||
test('Config changes', () => { | ||
// 1: Disable piped wikilinks | ||
NoteWorkspace.cfg = () => { | ||
let config = NoteWorkspace.DEFAULT_CONFIG; | ||
config.allowPipedWikiLinks = false; | ||
return config; | ||
}; | ||
// Because of this change, these should not match anymore... | ||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md') | ||
).toBeFalsy(); | ||
expect(NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md')).toBeFalsy(); | ||
|
||
// ... And cleanPipedWikiLink should return the original string. | ||
expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( | ||
"description|file" | ||
); | ||
expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('description|file'); | ||
|
||
// 2: Use a different separator | ||
NoteWorkspace.cfg = () => { | ||
let config = NoteWorkspace.DEFAULT_CONFIG; | ||
config.allowPipedWikiLinks = true; | ||
config.pipedWikiLinksSeparator = "@"; | ||
config.pipedWikiLinksSeparator = '@'; | ||
return config; | ||
}; | ||
|
||
expect( | ||
NoteWorkspace.noteNamesFuzzyMatch('filename.md', '[email protected]') | ||
).toBeTruthy(); | ||
|
||
expect(NoteWorkspace.cleanPipedWikiLink("description@file")).toEqual( | ||
"file" | ||
); | ||
expect(NoteWorkspace.cleanPipedWikiLink('description@file')).toEqual('file'); | ||
|
||
// 3: Use a different syntax | ||
NoteWorkspace.cfg = () => { | ||
let config = NoteWorkspace.DEFAULT_CONFIG; | ||
config.allowPipedWikiLinks = true; | ||
config.pipedWikiLinksSeparator = "\\|"; | ||
config.pipedWikiLinksSeparator = '\\|'; | ||
return config; | ||
}; | ||
|
||
|
@@ -289,47 +253,43 @@ describe("Wikilinks", () => { | |
NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'filename.md|description') | ||
).toBeTruthy(); | ||
|
||
expect(NoteWorkspace.cleanPipedWikiLink("file|description")).toEqual( | ||
"file" | ||
); | ||
|
||
expect(NoteWorkspace.cleanPipedWikiLink('file|description')).toEqual('file'); | ||
}); | ||
|
||
}); | ||
|
||
describe('NoteWorkspace.newNoteContent', () => { | ||
const newNote = (template: string, title: string) => { | ||
NoteWorkspace.cfg = () => { | ||
return { | ||
...NoteWorkspace.DEFAULT_CONFIG, | ||
newNoteTemplate: template | ||
newNoteTemplate: template, | ||
}; | ||
}; | ||
|
||
return NoteWorkspace.newNoteContent(title); | ||
}; | ||
it('handles noteName tag', () => { | ||
const template = "# ${noteName}\n\nThis is ${noteName}"; | ||
const content = newNote(template, "this is my test note!"); | ||
const template = '# ${noteName}\n\nThis is ${noteName}'; | ||
|
||
const content = newNote(template, 'this is my test note!'); | ||
|
||
expect(content).toBe('# this is my test note!\n\nThis is this is my test note!'); | ||
}); | ||
|
||
it('handles escaped newlines', () => { | ||
const template = "# Title\\n\\nContent"; | ||
const template = '# Title\\n\\nContent'; | ||
|
||
const content = newNote(template, 'nevermind'); | ||
|
||
expect(content).toBe('# Title\n\nContent'); | ||
}); | ||
|
||
it('handles timestamp', () => { | ||
const template = "# Title\n\nCreated: ${timestamp}\n"; | ||
const template = '# Title\n\nCreated: ${timestamp}\n'; | ||
|
||
const content = newNote(template, 'nevermind'); | ||
const regex = /# Title\n\nCreated: (.*)\n/; | ||
|
||
expect(content).toMatch(regex); | ||
const matches = regex.exec(content); | ||
const date1 = Date.parse(matches![1]); | ||
|
Oops, something went wrong.