forked from mhujer/ankiai
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
4,512 additions
and
1,746 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,59 +1,61 @@ | ||
import { expect, test } from 'vitest'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { filterNoteContent, isSentence, splitMultiTerms } from './note-text-filter'; | ||
import type { NoteForProcessing } from '../anki'; | ||
|
||
test('Note content filtering', () => { | ||
expect(filterNoteContent('der Ton<br><br>(Das Bier gibt es in großen Einliterkrügen aus Glas oder Ton.)')).toEqual( | ||
'der Ton', | ||
); | ||
expect(filterNoteContent('der Führerschein')).toEqual('der Führerschein'); | ||
expect(filterNoteContent('der Kaufmann, die Kauffrau')).toEqual('der Kaufmann, die Kauffrau'); | ||
expect(filterNoteContent('anschwellen (schwillt an, o, i. o)')).toEqual('anschwellen'); | ||
expect( | ||
filterNoteContent('die Schwellung, die Anschwellung<br><br>(die Anschwellung nach einem Bienenstich)'), | ||
).toEqual('die Schwellung, die Anschwellung'); | ||
expect(filterNoteContent('(j-m/für j-n) den Daumen drücken<br><br>(Ich drücke dir die Daumen.)')).toEqual( | ||
'den Daumen drücken', | ||
); | ||
}); | ||
describe('Note content filtering', () => { | ||
test('filterNoteContent', () => { | ||
expect( | ||
filterNoteContent('der Ton<br><br>(Das Bier gibt es in großen Einliterkrügen aus Glas oder Ton.)'), | ||
).toEqual('der Ton'); | ||
expect(filterNoteContent('der Führerschein')).toEqual('der Führerschein'); | ||
expect(filterNoteContent('der Kaufmann, die Kauffrau')).toEqual('der Kaufmann, die Kauffrau'); | ||
expect(filterNoteContent('anschwellen (schwillt an, o, i. o)')).toEqual('anschwellen'); | ||
expect( | ||
filterNoteContent('die Schwellung, die Anschwellung<br><br>(die Anschwellung nach einem Bienenstich)'), | ||
).toEqual('die Schwellung, die Anschwellung'); | ||
expect(filterNoteContent('(j-m/für j-n) den Daumen drücken<br><br>(Ich drücke dir die Daumen.)')).toEqual( | ||
'den Daumen drücken', | ||
); | ||
}); | ||
|
||
test('Is sentence', () => { | ||
expect(isSentence('Meine Nase ist Verstopft.')).toBe(true); | ||
expect(isSentence('Alles auf den Kopf stellen.')).toBe(true); | ||
expect(isSentence('die Schuld')).toBe(false); | ||
expect(isSentence('mit einem blauen Auge davonkommen')).toBe(false); | ||
}); | ||
test('Is sentence', () => { | ||
expect(isSentence('Meine Nase ist Verstopft.')).toBe(true); | ||
expect(isSentence('Alles auf den Kopf stellen.')).toBe(true); | ||
expect(isSentence('die Schuld')).toBe(false); | ||
expect(isSentence('mit einem blauen Auge davonkommen')).toBe(false); | ||
}); | ||
|
||
test('Splits notes with multiple terms', () => { | ||
const input: NoteForProcessing[] = [ | ||
{ | ||
noteId: 1, | ||
text: 'der Foo, der Bar', | ||
definitions: 'This is the definition', | ||
}, | ||
test('Splits notes with multiple terms', () => { | ||
const input: NoteForProcessing[] = [ | ||
{ | ||
noteId: 1, | ||
text: 'der Foo, der Bar', | ||
definitions: 'This is the definition', | ||
}, | ||
|
||
{ | ||
noteId: 2, | ||
text: 'die FooBaz', | ||
definitions: 'This is the second definition', | ||
}, | ||
]; | ||
{ | ||
noteId: 2, | ||
text: 'die FooBaz', | ||
definitions: 'This is the second definition', | ||
}, | ||
]; | ||
|
||
expect(splitMultiTerms(input)).toStrictEqual([ | ||
{ | ||
noteId: 1, | ||
text: 'der Foo', | ||
definitions: 'This is the definition', | ||
}, | ||
{ | ||
noteId: 1, | ||
text: 'der Bar', | ||
definitions: 'This is the definition', | ||
}, | ||
{ | ||
noteId: 2, | ||
text: 'die FooBaz', | ||
definitions: 'This is the second definition', | ||
}, | ||
]); | ||
expect(splitMultiTerms(input)).toStrictEqual([ | ||
{ | ||
noteId: 1, | ||
text: 'der Foo', | ||
definitions: 'This is the definition', | ||
}, | ||
{ | ||
noteId: 1, | ||
text: 'der Bar', | ||
definitions: 'This is the definition', | ||
}, | ||
{ | ||
noteId: 2, | ||
text: 'die FooBaz', | ||
definitions: 'This is the second definition', | ||
}, | ||
]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,51 +1,53 @@ | ||
import { expect, test } from 'vitest'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { mergeExamples } from './merge-examples'; | ||
import type { NoteForProcessing } from '../anki'; | ||
|
||
test('merge-examples', () => { | ||
const note: NoteForProcessing = { | ||
noteId: 5, | ||
text: '又', | ||
definitions: 'none', | ||
}; | ||
const response = { | ||
items: [ | ||
{ | ||
id: 1, | ||
text: '又', | ||
exampleSentences: [ | ||
'他又高又帅,是我心目中的完美男人。', | ||
'她又聪明又勤奋,是我们班的学霸。', | ||
'这个问题又复杂又深奥,需要认真思考才能理解。', | ||
], | ||
partsOfSpeech: 'conjunction', | ||
}, | ||
{ | ||
id: 2, | ||
text: '又', | ||
exampleSentences: [ | ||
'他又来晚了,老板一定会生气的。', | ||
'她又哭又笑,情绪变化很快。', | ||
'这个电影又搞笑又感人,让人忍不住流泪。', | ||
], | ||
partsOfSpeech: 'adverb', | ||
}, | ||
], | ||
}; | ||
describe('merge-examples', () => { | ||
test('it should merge examples', () => { | ||
const note: NoteForProcessing = { | ||
noteId: 5, | ||
text: '又', | ||
definitions: 'none', | ||
}; | ||
const response = { | ||
items: [ | ||
{ | ||
id: 1, | ||
text: '又', | ||
exampleSentences: [ | ||
'他又高又帅,是我心目中的完美男人。', | ||
'她又聪明又勤奋,是我们班的学霸。', | ||
'这个问题又复杂又深奥,需要认真思考才能理解。', | ||
], | ||
partsOfSpeech: 'conjunction', | ||
}, | ||
{ | ||
id: 2, | ||
text: '又', | ||
exampleSentences: [ | ||
'他又来晚了,老板一定会生气的。', | ||
'她又哭又笑,情绪变化很快。', | ||
'这个电影又搞笑又感人,让人忍不住流泪。', | ||
], | ||
partsOfSpeech: 'adverb', | ||
}, | ||
], | ||
}; | ||
|
||
const mergedItems = mergeExamples(note, response.items); | ||
const mergedItems = mergeExamples(note, response.items); | ||
|
||
expect(mergedItems).toMatchObject({ | ||
id: 5, | ||
text: '又', | ||
partsOfSpeech: ['conjunction', 'adverb'], | ||
exampleSentences: [ | ||
'他又高又帅,是我心目中的完美男人。', | ||
'她又聪明又勤奋,是我们班的学霸。', | ||
'这个问题又复杂又深奥,需要认真思考才能理解。', | ||
'他又来晚了,老板一定会生气的。', | ||
'她又哭又笑,情绪变化很快。', | ||
'这个电影又搞笑又感人,让人忍不住流泪。', | ||
], | ||
expect(mergedItems).toMatchObject({ | ||
id: 5, | ||
text: '又', | ||
partsOfSpeech: ['conjunction', 'adverb'], | ||
exampleSentences: [ | ||
'他又高又帅,是我心目中的完美男人。', | ||
'她又聪明又勤奋,是我们班的学霸。', | ||
'这个问题又复杂又深奥,需要认真思考才能理解。', | ||
'他又来晚了,老板一定会生气的。', | ||
'她又哭又笑,情绪变化很快。', | ||
'这个电影又搞笑又感人,让人忍不住流泪。', | ||
], | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { expect, it } from 'vitest'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
|
||
import sleep from './sleep'; | ||
|
||
it('returns a promise', () => { | ||
const sleepPromise = sleep(1); | ||
expect(sleepPromise).instanceOf(Promise); | ||
}); | ||
describe('sleep', () => { | ||
test('returns a promise', () => { | ||
const sleepPromise = sleep(1); | ||
expect(sleepPromise).toBeInstanceOf(Promise); | ||
}); | ||
|
||
it('can be called with await', async () => { | ||
await sleep(1); | ||
test('can be called with await', async () => { | ||
await sleep(1); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.