diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-20 00:47:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 05:47:15 +0000 |
commit | 8b943cc97fab890085448122e7c13dd035d0e238 (patch) | |
tree | a7a749a44771c6a82b1b72bb35cc0c81d57ddb54 /types/test | |
parent | b13fbd47941fc20cf623871396e34a6dfe9b4dba (diff) |
JSON validation (#394)
* Set up JSON testing
* Add schema validation
* Use parseJson
* Finish types
* Disambiguate ext/json-schema from node dependency with the same name
* Add support for specifying the jsconfig file
* Don't expose types
* Update types
* Use dictionary map type
* Fix types
* Fix AJV warnings
* Move types
* Move anb rename file
* Move common mocks
* Simplify types
Diffstat (limited to 'types/test')
-rw-r--r-- | types/test/json.d.ts | 42 | ||||
-rw-r--r-- | types/test/mocks.d.ts | 32 | ||||
-rw-r--r-- | types/test/translator.d.ts | 45 |
3 files changed, 115 insertions, 4 deletions
diff --git a/types/test/json.d.ts b/types/test/json.d.ts new file mode 100644 index 00000000..9ae21b0f --- /dev/null +++ b/types/test/json.d.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +import type {Schema} from 'ajv'; + +export type JsonInfo = { + files: JsonFileInfo[]; +}; + +export type JsonFileInfo = JsonFileIgnoreInfo | JsonFileParseInfo; + +export type JsonFileIgnoreInfo = { + path: string; + ignore: true; +}; + +export type JsonFileParseInfo = { + path: string; + ignore?: undefined; + typeFile: string; + type: string; + schema?: string; + jsconfig?: JsconfigType; +}; + +export type AjvSchema = Schema; + +export type JsconfigType = 'main' | 'dev' | 'test'; diff --git a/types/test/mocks.d.ts b/types/test/mocks.d.ts new file mode 100644 index 00000000..13b56ac6 --- /dev/null +++ b/types/test/mocks.d.ts @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +export type ChromeMock = { + runtime: { + getURL(path: string): string; + }; +}; + +export type FetchMock = (url: string) => Promise<FetchResponseMock>; + +export type FetchResponseMock = { + ok: boolean; + status: number; + statusText: string; + text(): Promise<string>; + json(): Promise<unknown>; +}; diff --git a/types/test/translator.d.ts b/types/test/translator.d.ts index 3e4c8b9d..7dff116e 100644 --- a/types/test/translator.d.ts +++ b/types/test/translator.d.ts @@ -15,12 +15,49 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import type {OptionsPresetObject} from 'dev/vm'; +import type {FindTermsMatchType, FindTermsSortOrder, FindTermsVariantMode, FindTermsEmphaticSequencesMode, FindKanjiDictionary, FindTermDictionary} from '../ext/translation'; import type {FindTermsMode} from 'translator'; import type {DictionaryEntry} from 'dictionary'; import type {NoteData} from 'anki-templates'; import type {NoteFields} from 'anki'; +export type OptionsPresetObject = { + [key: string]: OptionsPreset; +}; + +export type OptionsList = string | (string | OptionsPreset)[]; + +export type OptionsPreset = FindKanjiOptionsPreset | FindTermsOptionsPreset; + +export type FindKanjiOptionsPreset = { + enabledDictionaryMap?: [key: string, value: FindKanjiDictionary][]; + removeNonJapaneseCharacters?: boolean; +}; + +export type FindTermsOptionsPreset = { + matchType?: FindTermsMatchType; + deinflect?: boolean; + mainDictionary?: string; + sortFrequencyDictionary?: string | null; + sortFrequencyDictionaryOrder?: FindTermsSortOrder; + removeNonJapaneseCharacters?: boolean; + convertHalfWidthCharacters?: FindTermsVariantMode; + convertNumericCharacters?: FindTermsVariantMode; + convertAlphabeticCharacters?: FindTermsVariantMode; + convertHiraganaToKatakana?: FindTermsVariantMode; + convertKatakanaToHiragana?: FindTermsVariantMode; + collapseEmphaticSequences?: FindTermsEmphaticSequencesMode; + textReplacements?: (FindTermsTextReplacement[] | null)[]; + enabledDictionaryMap?: [key: string, value: FindTermDictionary][]; + excludeDictionaryDefinitions?: string[] | null; +}; + +export type FindTermsTextReplacement = { + pattern: string; + flags: string; + replacement: string; +}; + export type TranslatorTestInputs = { optionsPresets: OptionsPresetObject; tests: TestInput[]; @@ -32,7 +69,7 @@ export type TestInputFindKanji = { func: 'findKanji'; name: string; text: string; - options: string; + options: OptionsList; }; export type TestInputFindTerm = { @@ -40,7 +77,7 @@ export type TestInputFindTerm = { name: string; mode: FindTermsMode; text: string; - options: string; + options: OptionsList; }; export type TranslatorTestResults = TranslatorTestResult[]; @@ -55,7 +92,7 @@ export type TranslatorTestNoteDataResults = TranslatorTestNoteDataResult[]; export type TranslatorTestNoteDataResult = { name: string; - noteDataList: NoteData[]; + noteDataList: Omit<NoteData, 'dictionaryEntry'>[] | null; }; export type AnkiNoteBuilderTestResults = AnkiNoteBuilderTestResult[]; |