summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cache-map.test.js18
-rw-r--r--test/core.test.js573
-rw-r--r--test/css-json.test.js17
-rw-r--r--test/hotkey-util.test.js21
-rw-r--r--test/japanese-util.test.js93
-rw-r--r--test/json-schema.test.js42
-rw-r--r--test/language-transformer.test.js14
-rw-r--r--test/object-property-accessor.test.js75
-rw-r--r--test/options-util.test.js53
-rw-r--r--test/profile-conditions-util.test.js17
-rw-r--r--test/text-source-map.test.js26
11 files changed, 330 insertions, 619 deletions
diff --git a/test/cache-map.test.js b/test/cache-map.test.js
index 9be5363a..e7a8b836 100644
--- a/test/cache-map.test.js
+++ b/test/cache-map.test.js
@@ -19,8 +19,7 @@
import {describe, expect, test} from 'vitest';
import {CacheMap} from '../ext/js/general/cache-map.js';
-/** */
-function testConstructor() {
+describe('CacheMap', () => {
describe('constructor', () => {
const shouldThrow = [-1, 1.5, Number.NaN, Number.POSITIVE_INFINITY];
const shouldNotThrow = [0, 1, Number.MAX_VALUE];
@@ -32,10 +31,7 @@ function testConstructor() {
expect(() => new CacheMap(param)).toThrowError();
});
});
-}
-/** */
-function testApi() {
describe('api', () => {
/* eslint-disable @stylistic/no-multi-spaces */
const data = [
@@ -111,14 +107,4 @@ function testApi() {
expect(cache.size).toStrictEqual(expectedSize);
});
});
-}
-
-
-/** */
-function main() {
- testConstructor();
- testApi();
-}
-
-
-main();
+});
diff --git a/test/core.test.js b/test/core.test.js
index 7e19d04d..178f509a 100644
--- a/test/core.test.js
+++ b/test/core.test.js
@@ -20,315 +20,300 @@ import {describe, expect, test} from 'vitest';
import {DynamicProperty} from '../ext/js/core/dynamic-property.js';
import {deepEqual} from '../ext/js/core/utilities.js';
-/** */
-function testDynamicProperty() {
- describe('DynamicProperty', () => {
- /** @type {import('test/core').DynamicPropertyTestData} */
- const data = [
- {
- initialValue: 0,
- operations: [
- {
- operation: null,
- args: [0],
- expectedDefaultValue: 0,
- expectedValue: 0,
- expectedOverrideCount: 0,
- expectedEventOccurred: false
- },
- {
- operation: 'set.defaultValue',
- args: [1],
- expectedDefaultValue: 1,
- expectedValue: 1,
- expectedOverrideCount: 0,
- expectedEventOccurred: true
- },
- {
- operation: 'set.defaultValue',
- args: [1],
- expectedDefaultValue: 1,
- expectedValue: 1,
- expectedOverrideCount: 0,
- expectedEventOccurred: false
- },
- {
- operation: 'set.defaultValue',
- args: [0],
- expectedDefaultValue: 0,
- expectedValue: 0,
- expectedOverrideCount: 0,
- expectedEventOccurred: true
- },
- {
- operation: 'setOverride',
- args: [8],
- expectedDefaultValue: 0,
- expectedValue: 8,
- expectedOverrideCount: 1,
- expectedEventOccurred: true
- },
- {
- operation: 'setOverride',
- args: [16],
- expectedDefaultValue: 0,
- expectedValue: 8,
- expectedOverrideCount: 2,
- expectedEventOccurred: false
- },
- {
- operation: 'setOverride',
- args: [32, 1],
- expectedDefaultValue: 0,
- expectedValue: 32,
- expectedOverrideCount: 3,
- expectedEventOccurred: true
- },
- {
- operation: 'setOverride',
- args: [64, -1],
- expectedDefaultValue: 0,
- expectedValue: 32,
- expectedOverrideCount: 4,
- expectedEventOccurred: false
- },
- {
- operation: 'clearOverride',
- args: [-4],
- expectedDefaultValue: 0,
- expectedValue: 32,
- expectedOverrideCount: 3,
- expectedEventOccurred: false
- },
- {
- operation: 'clearOverride',
- args: [-3],
- expectedDefaultValue: 0,
- expectedValue: 32,
- expectedOverrideCount: 2,
- expectedEventOccurred: false
- },
- {
- operation: 'clearOverride',
- args: [-2],
- expectedDefaultValue: 0,
- expectedValue: 64,
- expectedOverrideCount: 1,
- expectedEventOccurred: true
- },
- {
- operation: 'clearOverride',
- args: [-1],
- expectedDefaultValue: 0,
- expectedValue: 0,
- expectedOverrideCount: 0,
- expectedEventOccurred: true
- }
- ]
- }
- ];
+describe('DynamicProperty', () => {
+ /** @type {import('test/core').DynamicPropertyTestData} */
+ const data = [
+ {
+ initialValue: 0,
+ operations: [
+ {
+ operation: null,
+ args: [0],
+ expectedDefaultValue: 0,
+ expectedValue: 0,
+ expectedOverrideCount: 0,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'set.defaultValue',
+ args: [1],
+ expectedDefaultValue: 1,
+ expectedValue: 1,
+ expectedOverrideCount: 0,
+ expectedEventOccurred: true
+ },
+ {
+ operation: 'set.defaultValue',
+ args: [1],
+ expectedDefaultValue: 1,
+ expectedValue: 1,
+ expectedOverrideCount: 0,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'set.defaultValue',
+ args: [0],
+ expectedDefaultValue: 0,
+ expectedValue: 0,
+ expectedOverrideCount: 0,
+ expectedEventOccurred: true
+ },
+ {
+ operation: 'setOverride',
+ args: [8],
+ expectedDefaultValue: 0,
+ expectedValue: 8,
+ expectedOverrideCount: 1,
+ expectedEventOccurred: true
+ },
+ {
+ operation: 'setOverride',
+ args: [16],
+ expectedDefaultValue: 0,
+ expectedValue: 8,
+ expectedOverrideCount: 2,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'setOverride',
+ args: [32, 1],
+ expectedDefaultValue: 0,
+ expectedValue: 32,
+ expectedOverrideCount: 3,
+ expectedEventOccurred: true
+ },
+ {
+ operation: 'setOverride',
+ args: [64, -1],
+ expectedDefaultValue: 0,
+ expectedValue: 32,
+ expectedOverrideCount: 4,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'clearOverride',
+ args: [-4],
+ expectedDefaultValue: 0,
+ expectedValue: 32,
+ expectedOverrideCount: 3,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'clearOverride',
+ args: [-3],
+ expectedDefaultValue: 0,
+ expectedValue: 32,
+ expectedOverrideCount: 2,
+ expectedEventOccurred: false
+ },
+ {
+ operation: 'clearOverride',
+ args: [-2],
+ expectedDefaultValue: 0,
+ expectedValue: 64,
+ expectedOverrideCount: 1,
+ expectedEventOccurred: true
+ },
+ {
+ operation: 'clearOverride',
+ args: [-1],
+ expectedDefaultValue: 0,
+ expectedValue: 0,
+ expectedOverrideCount: 0,
+ expectedEventOccurred: true
+ }
+ ]
+ }
+ ];
- describe.each(data)('Test DynamicProperty($initialValue)', ({initialValue, operations}) => {
- test('works as expected', () => {
- const property = new DynamicProperty(initialValue);
- const overrideTokens = [];
- let eventOccurred = false;
- const onChange = () => { eventOccurred = true; };
- property.on('change', onChange);
- for (const {operation, args, expectedDefaultValue, expectedValue, expectedOverrideCount, expectedEventOccurred} of operations) {
- eventOccurred = false;
- switch (operation) {
- case 'set.defaultValue': property.defaultValue = args[0]; break;
- case 'setOverride': overrideTokens.push(property.setOverride(...args)); break;
- case 'clearOverride': property.clearOverride(overrideTokens[overrideTokens.length + args[0]]); break;
- }
- expect(eventOccurred).toStrictEqual(expectedEventOccurred);
- expect(property.defaultValue).toStrictEqual(expectedDefaultValue);
- expect(property.value).toStrictEqual(expectedValue);
- expect(property.overrideCount).toStrictEqual(expectedOverrideCount);
+ describe.each(data)('Test DynamicProperty($initialValue)', ({initialValue, operations}) => {
+ test('works as expected', () => {
+ const property = new DynamicProperty(initialValue);
+ const overrideTokens = [];
+ let eventOccurred = false;
+ const onChange = () => { eventOccurred = true; };
+ property.on('change', onChange);
+ for (const {operation, args, expectedDefaultValue, expectedValue, expectedOverrideCount, expectedEventOccurred} of operations) {
+ eventOccurred = false;
+ switch (operation) {
+ case 'set.defaultValue': property.defaultValue = args[0]; break;
+ case 'setOverride': overrideTokens.push(property.setOverride(...args)); break;
+ case 'clearOverride': property.clearOverride(overrideTokens[overrideTokens.length + args[0]]); break;
}
- property.off('change', onChange);
- });
+ expect(eventOccurred).toStrictEqual(expectedEventOccurred);
+ expect(property.defaultValue).toStrictEqual(expectedDefaultValue);
+ expect(property.value).toStrictEqual(expectedValue);
+ expect(property.overrideCount).toStrictEqual(expectedOverrideCount);
+ }
+ property.off('change', onChange);
});
});
-}
+});
-/** */
-function testDeepEqual() {
- describe('deepEqual', () => {
- /** @type {import('test/core').DeepEqualTestData} */
- const simpleTestsData = [
- {
- value1: 0,
- value2: 0,
- expected: true
- },
- {
- value1: null,
- value2: null,
- expected: true
- },
- {
- value1: 'test',
- value2: 'test',
- expected: true
- },
- {
- value1: true,
- value2: true,
- expected: true
- },
- {
- value1: 0,
- value2: 1,
- expected: false
- },
- {
- value1: null,
- value2: false,
- expected: false
- },
- {
- value1: 'test1',
- value2: 'test2',
- expected: false
- },
- {
- value1: true,
- value2: false,
- expected: false
- }
- ];
- /** @type {import('test/core').DeepEqualTestData} */
- const simpleObjectTestsData = [
- {
- value1: {},
- value2: {},
- expected: true
- },
- {
- value1: {},
- value2: [],
- expected: false
- },
- {
- value1: [],
- value2: [],
- expected: true
- },
- {
- value1: {},
- value2: null,
- expected: false
- }
- ];
- /** @type {import('test/core').DeepEqualTestData} */
- const complexObjectTestsData = [
- {
- value1: [1],
- value2: [],
- expected: false
- },
- {
- value1: [1],
- value2: [1],
- expected: true
- },
- {
- value1: [1],
- value2: [2],
- expected: false
- },
+describe('deepEqual', () => {
+ /** @type {import('test/core').DeepEqualTestData} */
+ const simpleTestsData = [
+ {
+ value1: 0,
+ value2: 0,
+ expected: true
+ },
+ {
+ value1: null,
+ value2: null,
+ expected: true
+ },
+ {
+ value1: 'test',
+ value2: 'test',
+ expected: true
+ },
+ {
+ value1: true,
+ value2: true,
+ expected: true
+ },
+ {
+ value1: 0,
+ value2: 1,
+ expected: false
+ },
+ {
+ value1: null,
+ value2: false,
+ expected: false
+ },
+ {
+ value1: 'test1',
+ value2: 'test2',
+ expected: false
+ },
+ {
+ value1: true,
+ value2: false,
+ expected: false
+ }
+ ];
+ /** @type {import('test/core').DeepEqualTestData} */
+ const simpleObjectTestsData = [
+ {
+ value1: {},
+ value2: {},
+ expected: true
+ },
+ {
+ value1: {},
+ value2: [],
+ expected: false
+ },
+ {
+ value1: [],
+ value2: [],
+ expected: true
+ },
+ {
+ value1: {},
+ value2: null,
+ expected: false
+ }
+ ];
+ /** @type {import('test/core').DeepEqualTestData} */
+ const complexObjectTestsData = [
+ {
+ value1: [1],
+ value2: [],
+ expected: false
+ },
+ {
+ value1: [1],
+ value2: [1],
+ expected: true
+ },
+ {
+ value1: [1],
+ value2: [2],
+ expected: false
+ },
- {
- value1: {},
- value2: {test: 1},
- expected: false
- },
- {
- value1: {test: 1},
- value2: {test: 1},
- expected: true
- },
- {
- value1: {test: 1},
- value2: {test: {test2: false}},
- expected: false
- },
- {
- value1: {test: {test2: true}},
- value2: {test: {test2: false}},
- expected: false
- },
- {
- value1: {test: {test2: [true]}},
- value2: {test: {test2: [true]}},
- expected: true
- }
- ];
- /** @type {import('test/core').DeepEqualTestData} */
- const recursiveTestsData = [
- {
- value1: (() => {
- const x = {};
- x.x = x;
- return x;
- })(),
- value2: (() => {
- const x = {};
- x.x = x;
- return x;
- })(),
- expected: false
- }
- ];
- describe('simple tests', () => {
- test.each(simpleTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
- const actual1 = deepEqual(value1, value2);
- expect(actual1).toStrictEqual(expected);
+ {
+ value1: {},
+ value2: {test: 1},
+ expected: false
+ },
+ {
+ value1: {test: 1},
+ value2: {test: 1},
+ expected: true
+ },
+ {
+ value1: {test: 1},
+ value2: {test: {test2: false}},
+ expected: false
+ },
+ {
+ value1: {test: {test2: true}},
+ value2: {test: {test2: false}},
+ expected: false
+ },
+ {
+ value1: {test: {test2: [true]}},
+ value2: {test: {test2: [true]}},
+ expected: true
+ }
+ ];
+ /** @type {import('test/core').DeepEqualTestData} */
+ const recursiveTestsData = [
+ {
+ value1: (() => {
+ const x = {};
+ x.x = x;
+ return x;
+ })(),
+ value2: (() => {
+ const x = {};
+ x.x = x;
+ return x;
+ })(),
+ expected: false
+ }
+ ];
+ describe('simple tests', () => {
+ test.each(simpleTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
+ const actual1 = deepEqual(value1, value2);
+ expect(actual1).toStrictEqual(expected);
- const actual2 = deepEqual(value2, value1);
- expect(actual2).toStrictEqual(expected);
- });
+ const actual2 = deepEqual(value2, value1);
+ expect(actual2).toStrictEqual(expected);
});
+ });
- describe('simple object tests', () => {
- test.each(simpleObjectTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
- const actual1 = deepEqual(value1, value2);
- expect(actual1).toStrictEqual(expected);
+ describe('simple object tests', () => {
+ test.each(simpleObjectTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
+ const actual1 = deepEqual(value1, value2);
+ expect(actual1).toStrictEqual(expected);
- const actual2 = deepEqual(value2, value1);
- expect(actual2).toStrictEqual(expected);
- });
+ const actual2 = deepEqual(value2, value1);
+ expect(actual2).toStrictEqual(expected);
});
+ });
- describe('complex object tests', () => {
- test.each(complexObjectTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
- const actual1 = deepEqual(value1, value2);
- expect(actual1).toStrictEqual(expected);
+ describe('complex object tests', () => {
+ test.each(complexObjectTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
+ const actual1 = deepEqual(value1, value2);
+ expect(actual1).toStrictEqual(expected);
- const actual2 = deepEqual(value2, value1);
- expect(actual2).toStrictEqual(expected);
- });
+ const actual2 = deepEqual(value2, value1);
+ expect(actual2).toStrictEqual(expected);
});
+ });
- describe('recursive tests', () => {
- test.each(recursiveTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
- const actual1 = deepEqual(value1, value2);
- expect(actual1).toStrictEqual(expected);
+ describe('recursive tests', () => {
+ test.each(recursiveTestsData)('deepEqual($value1, $value2) -> $expected', ({value1, value2, expected}) => {
+ const actual1 = deepEqual(value1, value2);
+ expect(actual1).toStrictEqual(expected);
- const actual2 = deepEqual(value2, value1);
- expect(actual2).toStrictEqual(expected);
- });
+ const actual2 = deepEqual(value2, value1);
+ expect(actual2).toStrictEqual(expected);
});
});
-}
-
-
-/** */
-function main() {
- testDynamicProperty();
- testDeepEqual();
-}
-
-main();
+});
diff --git a/test/css-json.test.js b/test/css-json.test.js
index 87d24d6c..25f1ca75 100644
--- a/test/css-json.test.js
+++ b/test/css-json.test.js
@@ -20,15 +20,10 @@ import fs from 'fs';
import {describe, expect, test} from 'vitest';
import {formatRulesJson, generateRules, getTargets} from '../dev/generate-css-json.js';
-/** */
-function main() {
- describe('css-json', () => {
- test.each(getTargets())('css-json-test-%#', ({cssFilePath, overridesCssFilePath, outputPath}) => {
- const actual = fs.readFileSync(outputPath, {encoding: 'utf8'});
- const expected = formatRulesJson(generateRules(cssFilePath, overridesCssFilePath));
- expect(actual).toStrictEqual(expected);
- });
+describe('css-json', () => {
+ test.each(getTargets())('css-json-test-%#', ({cssFilePath, overridesCssFilePath, outputPath}) => {
+ const actual = fs.readFileSync(outputPath, {encoding: 'utf8'});
+ const expected = formatRulesJson(generateRules(cssFilePath, overridesCssFilePath));
+ expect(actual).toStrictEqual(expected);
});
-}
-
-main();
+});
diff --git a/test/hotkey-util.test.js b/test/hotkey-util.test.js
index 01a2b536..6eb3f975 100644
--- a/test/hotkey-util.test.js
+++ b/test/hotkey-util.test.js
@@ -19,8 +19,7 @@
import {describe, expect, test} from 'vitest';
import {HotkeyUtil} from '../ext/js/input/hotkey-util.js';
-/** */
-function testCommandConversions() {
+describe('HotkeyUtil', () => {
describe('CommandConversions', () => {
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {{os: import('environment').OperatingSystem, command: string, expectedCommand: string, expectedInput: {key: string, modifiers: import('input').Modifier[]}}[]} */
@@ -53,10 +52,7 @@ function testCommandConversions() {
});
}
});
-}
-/** */
-function testDisplayNames() {
describe('DisplayNames', () => {
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {{os: import('environment').OperatingSystem, key: ?string, modifiers: import('input').Modifier[], expected: string}[]} */
@@ -147,10 +143,7 @@ function testDisplayNames() {
expect(displayName).toStrictEqual(expected);
});
});
-}
-/** */
-function testSortModifiers() {
describe('SortModifiers', () => {
/** @type {{modifiers: import('input').Modifier[], expected: import('input').Modifier[]}[]} */
const data = [
@@ -167,14 +160,4 @@ function testSortModifiers() {
});
}
});
-}
-
-
-/** */
-function main() {
- testCommandConversions();
- testDisplayNames();
- testSortModifiers();
-}
-
-main();
+});
diff --git a/test/japanese-util.test.js b/test/japanese-util.test.js
index 8997df73..5f64a714 100644
--- a/test/japanese-util.test.js
+++ b/test/japanese-util.test.js
@@ -21,8 +21,7 @@ import {TextSourceMap} from '../ext/js/general/text-source-map.js';
import * as jpw from '../ext/js/language/ja/japanese-wanakana.js';
import * as jp from '../ext/js/language/ja/japanese.js';
-/** */
-function testIsCodePointKanji() {
+describe('Japanese utility functions', () => {
describe('isCodePointKanji', () => {
/** @type {[characters: string, expected: boolean][]} */
const data = [
@@ -40,10 +39,7 @@ function testIsCodePointKanji() {
}
});
});
-}
-/** */
-function testIsCodePointKana() {
describe('isCodePointKana', () => {
/** @type {[characters: string, expected: boolean][]} */
const data = [
@@ -60,10 +56,7 @@ function testIsCodePointKana() {
}
});
});
-}
-/** */
-function testIsCodePointJapanese() {
describe('isCodePointJapanese', () => {
/** @type {[characters: string, expected: boolean][]} */
const data = [
@@ -81,10 +74,7 @@ function testIsCodePointJapanese() {
}
});
});
-}
-/** */
-function testIsStringEntirelyKana() {
describe('isStringEntirelyKana', () => {
/** @type {[string: string, expected: boolean][]} */
const data = [
@@ -105,10 +95,7 @@ function testIsStringEntirelyKana() {
expect(jp.isStringEntirelyKana(string)).toStrictEqual(expected);
});
});
-}
-/** */
-function testIsStringPartiallyJapanese() {
describe('isStringPartiallyJapanese', () => {
/** @type {[string: string, expected: boolean][]} */
const data = [
@@ -130,10 +117,7 @@ function testIsStringPartiallyJapanese() {
expect(jp.isStringPartiallyJapanese(string)).toStrictEqual(expected);
});
});
-}
-/** */
-function testConvertKatakanaToHiragana() {
describe('convertKatakanaToHiragana', () => {
/** @type {[string: string, expected: string, keepProlongedSoundMarks?: boolean][]} */
const data = [
@@ -156,11 +140,8 @@ function testConvertKatakanaToHiragana() {
});
}
});
-}
-/** */
-function testConvertHiraganaToKatakana() {
- describe('ConvertHiraganaToKatakana', () => {
+ describe('convertHiraganaToKatakana', () => {
/** @type {[string: string, expected: string][]} */
const data = [
['かたかな', 'カタカナ'],
@@ -178,11 +159,8 @@ function testConvertHiraganaToKatakana() {
expect(jp.convertHiraganaToKatakana(string)).toStrictEqual(expected);
});
});
-}
-/** */
-function testConvertToRomaji() {
- describe('ConvertToRomaji', () => {
+ describe('convertToRomaji', () => {
/** @type {[string: string, expected: string][]} */
const data = [
['かたかな', 'katakana'],
@@ -200,11 +178,8 @@ function testConvertToRomaji() {
expect(jpw.convertToRomaji(string)).toStrictEqual(expected);
});
});
-}
-/** */
-function testConvertNumericToFullWidth() {
- describe('ConvertNumericToFullWidth', () => {
+ describe('convertNumericToFullWidth', () => {
/** @type {[string: string, expected: string][]} */
const data = [
['0123456789', '0123456789'],
@@ -217,11 +192,8 @@ function testConvertNumericToFullWidth() {
expect(jp.convertNumericToFullWidth(string)).toStrictEqual(expected);
});
});
-}
-/** */
-function testConvertHalfWidthKanaToFullWidth() {
- describe('ConvertHalfWidthKanaToFullWidth', () => {
+ describe('convertHalfWidthKanaToFullWidth', () => {
/** @type {[string: string, expected: string, expectedSourceMapping?: number[]][]} */
const data = [
['0123456789', '0123456789'],
@@ -247,11 +219,8 @@ function testConvertHalfWidthKanaToFullWidth() {
});
}
});
-}
-/** */
-function testConvertAlphabeticToKana() {
- describe('ConvertAlphabeticToKana', () => {
+ describe('convertAlphabeticToKana', () => {
/** @type {[string: string, expected: string, expectedSourceMapping?: number[]][]} */
const data = [
['0123456789', '0123456789'],
@@ -276,11 +245,8 @@ function testConvertAlphabeticToKana() {
});
}
});
-}
-/** */
-function testDistributeFurigana() {
- describe('DistributeFurigana', () => {
+ describe('distributeFurigana', () => {
/** @type {[input: [term: string, reading: string], expected: {text: string, reading: string}[]][]} */
const data = [
[
@@ -746,11 +712,8 @@ function testDistributeFurigana() {
expect(actual).toStrictEqual(expected);
});
});
-}
-/** */
-function testDistributeFuriganaInflected() {
- describe('DistributeFuriganaInflected', () => {
+ describe('distributeFuriganaInflected', () => {
/** @type {[input: [term: string, reading: string, source: string], expected: {text: string, reading: string}[]][]} */
const data = [
[
@@ -800,11 +763,8 @@ function testDistributeFuriganaInflected() {
expect(actual).toStrictEqual(expected);
});
});
-}
-/** */
-function testCollapseEmphaticSequences() {
- describe('CollapseEmphaticSequences', () => {
+ describe('collapseEmphaticSequences', () => {
/** @type {[input: [text: string, fullCollapse: boolean], output: [expected: string, expectedSourceMapping: number[]]][]} */
const data = [
[['かこい', false], ['かこい', [1, 1, 1]]],
@@ -860,11 +820,8 @@ function testCollapseEmphaticSequences() {
}
});
});
-}
-/** */
-function testIsMoraPitchHigh() {
- describe('IsMoraPitchHigh', () => {
+ describe('isMoraPitchHigh', () => {
/** @type {[input: [moraIndex: number, pitchAccentDownstepPosition: number], expected: boolean][]} */
const data = [
[[0, 0], false],
@@ -899,11 +856,8 @@ function testIsMoraPitchHigh() {
expect(actual).toStrictEqual(expected);
});
});
-}
-/** */
-function testGetKanaMorae() {
- describe('GetKanaMorae', () => {
+ describe('getKanaMorae', () => {
/** @type {[text: string, expected: string[]][]} */
const data = [
['かこ', ['か', 'こ']],
@@ -922,27 +876,4 @@ function testGetKanaMorae() {
expect(actual).toStrictEqual(expected);
});
});
-}
-
-
-/** */
-function main() {
- testIsCodePointKanji();
- testIsCodePointKana();
- testIsCodePointJapanese();
- testIsStringEntirelyKana();
- testIsStringPartiallyJapanese();
- testConvertKatakanaToHiragana();
- testConvertHiraganaToKatakana();
- testConvertToRomaji();
- testConvertNumericToFullWidth();
- testConvertHalfWidthKanaToFullWidth();
- testConvertAlphabeticToKana();
- testDistributeFurigana();
- testDistributeFuriganaInflected();
- testCollapseEmphaticSequences();
- testIsMoraPitchHigh();
- testGetKanaMorae();
-}
-
-main();
+});
diff --git a/test/json-schema.test.js b/test/json-schema.test.js
index af4b7acd..dba14c54 100644
--- a/test/json-schema.test.js
+++ b/test/json-schema.test.js
@@ -17,7 +17,6 @@
*/
import {describe, expect, test} from 'vitest';
-import {parseJson} from '../dev/json.js';
import {JsonSchema} from '../ext/js/data/json-schema.js';
/**
@@ -47,18 +46,8 @@ function createProxy(schema, value) {
return new JsonSchema(schema).createProxy(value);
}
-/**
- * @template [T=unknown]
- * @param {T} value
- * @returns {T}
- */
-function clone(value) {
- return parseJson(JSON.stringify(value));
-}
-
-/** */
-function testValidate1() {
+describe('JsonSchema', () => {
describe('Validate1', () => {
/** @type {import('ext/json-schema').Schema} */
const schema = {
@@ -118,10 +107,7 @@ function testValidate1() {
}
});
});
-}
-/** */
-function testValidate2() {
describe('Validate2', () => {
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {{schema: import('ext/json-schema').Schema, inputs: {expected: boolean, value: unknown}[]}[]} */
@@ -526,11 +512,7 @@ function testValidate2() {
});
});
});
-}
-
-/** */
-function testGetValidValueOrDefault1() {
describe('GetValidValueOrDefault1', () => {
/** @type {{schema: import('ext/json-schema').Schema, inputs: [value: unknown, expected: unknown][]}[]} */
const data = [
@@ -884,11 +866,7 @@ function testGetValidValueOrDefault1() {
});
});
});
-}
-
-/** */
-function testProxy1() {
describe('Proxy1', () => {
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {{schema: import('ext/json-schema').Schema, tests: {error: boolean, value?: import('ext/json-schema').Value, action: (value: import('core').SafeAny) => void}[]}[]} */
@@ -1029,7 +1007,7 @@ function testProxy1() {
describe.each(data)('Schema %#', ({schema, tests}) => {
test.each(tests)('proxy %#', ({error, value, action}) => {
if (typeof value === 'undefined') { value = getValidValueOrDefault(schema, void 0); }
- value = clone(value);
+ value = structuredClone(value);
expect(schemaValidate(schema, value)).toBe(true);
const valueProxy = createProxy(schema, value);
if (error) {
@@ -1043,7 +1021,7 @@ function testProxy1() {
for (const {schema, tests} of data) {
for (let {error, value, action} of tests) {
if (typeof value === 'undefined') { value = getValidValueOrDefault(schema, void 0); }
- value = clone(value);
+ value = structuredClone(value);
expect(schemaValidate(schema, value)).toBe(true);
const valueProxy = createProxy(schema, value);
if (error) {
@@ -1054,16 +1032,4 @@ function testProxy1() {
}
}
});
-}
-
-
-/** */
-function main() {
- testValidate1();
- testValidate2();
- testGetValidValueOrDefault1();
- testProxy1();
-}
-
-
-main();
+});
diff --git a/test/language-transformer.test.js b/test/language-transformer.test.js
index 857b5ed0..0c8ef08d 100644
--- a/test/language-transformer.test.js
+++ b/test/language-transformer.test.js
@@ -61,9 +61,7 @@ function hasTermReasons(languageTransformer, source, expectedTerm, expectedCondi
return {has: false, reasons: null, rules: null};
}
-
-/** */
-function testDeinflections() {
+describe('LanguageTransformer', () => {
/* eslint-disable @stylistic/no-multi-spaces */
const data = [
{
@@ -1172,12 +1170,4 @@ function testDeinflections() {
}
});
});
-}
-
-
-/** */
-function main() {
- testDeinflections();
-}
-
-main();
+});
diff --git a/test/object-property-accessor.test.js b/test/object-property-accessor.test.js
index 79f78ace..ce72553c 100644
--- a/test/object-property-accessor.test.js
+++ b/test/object-property-accessor.test.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import {expect, test} from 'vitest';
+import {describe, expect, test} from 'vitest';
import {ObjectPropertyAccessor} from '../ext/js/general/object-property-accessor.js';
/**
@@ -38,9 +38,7 @@ function createTestObject() {
};
}
-
-/** */
-function testGet1() {
+describe('ObjectPropertyAccessor', () => {
test('Get1', () => {
/** @type {[pathArray: (string|number)[], getExpected: (object: import('core').SafeAny) => unknown][]} */
const data = [
@@ -64,10 +62,7 @@ function testGet1() {
expect(accessor.get(pathArray)).toStrictEqual(expected);
}
});
-}
-/** */
-function testGet2() {
test('Get2', () => {
const object = createTestObject();
const accessor = new ObjectPropertyAccessor(object);
@@ -99,11 +94,7 @@ function testGet2() {
expect(() => accessor.get(pathArray)).toThrow(message);
}
});
-}
-
-/** */
-function testSet1() {
test('Set1', () => {
const testValue = {};
/** @type {(string|number)[][]} */
@@ -127,10 +118,7 @@ function testSet1() {
expect(accessor.get(pathArray)).toStrictEqual(testValue);
}
});
-}
-/** */
-function testSet2() {
test('Set2', () => {
const object = createTestObject();
const accessor = new ObjectPropertyAccessor(object);
@@ -156,11 +144,7 @@ function testSet2() {
expect(() => accessor.set(pathArray, testValue)).toThrow(message);
}
});
-}
-
-/** */
-function testDelete1() {
test('Delete1', () => {
/**
* @param {unknown} object
@@ -187,10 +171,7 @@ function testDelete1() {
expect(validate(object)).toBe(true);
}
});
-}
-/** */
-function testDelete2() {
test('Delete2', () => {
/** @type {[pathArray: (string|number)[], message: string][]} */
const data = [
@@ -218,11 +199,7 @@ function testDelete2() {
expect(() => accessor.delete(pathArray)).toThrow(message);
}
});
-}
-
-/** */
-function testSwap1() {
test('Swap1', () => {
/** @type {[pathArray: (string|number)[], compareValues: boolean][]} */
const data = [
@@ -257,10 +234,7 @@ function testSwap1() {
}
}
});
-}
-/** */
-function testSwap2() {
test('Swap2', () => {
/** @type {[pathArray1: (string|number)[], pathArray2: (string|number)[], checkRevert: boolean, message: string][]} */
const data = [
@@ -297,11 +271,7 @@ function testSwap2() {
expect(value2a).toStrictEqual(value2b);
}
});
-}
-
-/** */
-function testGetPathString1() {
test('GetPathString1', () => {
/** @type {[pathArray: (string|number)[], expected: string][]} */
const data = [
@@ -322,10 +292,7 @@ function testGetPathString1() {
expect(ObjectPropertyAccessor.getPathString(pathArray)).toStrictEqual(expected);
}
});
-}
-/** */
-function testGetPathString2() {
test('GetPathString2', () => {
/** @type {[pathArray: unknown[], message: string][]} */
const data = [
@@ -338,11 +305,7 @@ function testGetPathString2() {
expect(() => ObjectPropertyAccessor.getPathString(pathArray)).toThrow(message);
}
});
-}
-
-/** */
-function testGetPathArray1() {
test('GetPathArray1', () => {
/** @type {[pathString: string, pathArray: (string|number)[]][]} */
const data = [
@@ -367,10 +330,7 @@ function testGetPathArray1() {
expect(ObjectPropertyAccessor.getPathArray(pathString)).toStrictEqual(expected);
}
});
-}
-/** */
-function testGetPathArray2() {
test('GetPathArray2', () => {
/** @type {[pathString: string, message: string][]} */
const data = [
@@ -402,11 +362,7 @@ function testGetPathArray2() {
expect(() => ObjectPropertyAccessor.getPathArray(pathString)).toThrow(message);
}
});
-}
-
-/** */
-function testHasProperty() {
test('HasProperty', () => {
/** @type {[object: unknown, property: unknown, expected: boolean][]} */
const data = [
@@ -428,10 +384,7 @@ function testHasProperty() {
expect(ObjectPropertyAccessor.hasProperty(object, property)).toStrictEqual(expected);
}
});
-}
-/** */
-function testIsValidPropertyType() {
test('IsValidPropertyType', () => {
/** @type {[object: unknown, property: unknown, expected: boolean][]} */
const data = [
@@ -453,26 +406,4 @@ function testIsValidPropertyType() {
expect(ObjectPropertyAccessor.isValidPropertyType(object, property)).toStrictEqual(expected);
}
});
-}
-
-
-/** */
-function main() {
- testGet1();
- testGet2();
- testSet1();
- testSet2();
- testDelete1();
- testDelete2();
- testSwap1();
- testSwap2();
- testGetPathString1();
- testGetPathString2();
- testGetPathArray1();
- testGetPathArray2();
- testHasProperty();
- testIsValidPropertyType();
-}
-
-
-main();
+});
diff --git a/test/options-util.test.js b/test/options-util.test.js
index c2050c3f..a178aecb 100644
--- a/test/options-util.test.js
+++ b/test/options-util.test.js
@@ -613,9 +613,22 @@ function createOptionsUpdatedTestData1() {
};
}
+/**
+ * @param {string} templates
+ * @returns {Map<string, string>}
+ */
+function getHandlebarsPartials(templates) {
+ const inlinePartialRegex = /{{~?#\*inline .*?"([^"]*)"~?}}.*?{{~?\/inline~?}}/gs;
+ const matches = templates.matchAll(inlinePartialRegex);
+ const partials = new Map();
+ for (const match of matches) {
+ const [template, name] = match;
+ partials.set(name, template);
+ }
+ return partials;
+}
-/** */
-async function testUpdate() {
+describe('OptionsUtil', () => {
test('Update', async () => {
const optionsUtil = new OptionsUtil();
await optionsUtil.prepare();
@@ -625,24 +638,7 @@ async function testUpdate() {
const optionsExpected = createOptionsUpdatedTestData1();
expect(optionsUpdated).toStrictEqual(optionsExpected);
});
-}
-/** */
-async function testCumulativeFieldTemplatesUpdates() {
- /**
- * @param {string} templates
- * @returns {Map<string, string>}
- */
- const getHandlebarsPartials = (templates) => {
- const inlinePartialRegex = /{{~?#\*inline .*?"([^"]*)"~?}}.*?{{~?\/inline~?}}/gs;
- const matches = templates.matchAll(inlinePartialRegex);
- const partials = new Map();
- for (const match of matches) {
- const [template, name] = match;
- partials.set(name, template);
- }
- return partials;
- };
test('CumulativeFieldTemplatesUpdates', async () => {
const optionsUtil = new OptionsUtil();
await optionsUtil.prepare();
@@ -661,10 +657,7 @@ async function testCumulativeFieldTemplatesUpdates() {
expect(partialsUpdated).toStrictEqual(partialsExpected);
});
-}
-/** */
-async function testDefault() {
describe('Default', () => {
/** @type {((options: import('options-util').IntermediateOptions) => void)[]} */
const data = [
@@ -688,10 +681,7 @@ async function testDefault() {
expect(structuredClone(optionsUpdated)).toStrictEqual(structuredClone(options));
});
});
-}
-/** */
-async function testFieldTemplatesUpdate() {
describe('FieldTemplatesUpdate', () => {
const templatePatcher = new TemplatePatcher();
/**
@@ -1725,15 +1715,4 @@ async function testFieldTemplatesUpdate() {
expect(fieldTemplatesActual).toStrictEqual(expected2);
});
});
-}
-
-
-/** */
-async function main() {
- await testUpdate();
- await testDefault();
- await testFieldTemplatesUpdate();
- await testCumulativeFieldTemplatesUpdates();
-}
-
-await main();
+});
diff --git a/test/profile-conditions-util.test.js b/test/profile-conditions-util.test.js
index 261225d9..6de5ad1d 100644
--- a/test/profile-conditions-util.test.js
+++ b/test/profile-conditions-util.test.js
@@ -19,8 +19,7 @@
import {describe, expect, test} from 'vitest';
import {createSchema, normalizeContext} from '../ext/js/background/profile-conditions-util.js';
-/** */
-function testNormalizeContext() {
+describe('Profile conditions utilities', () => {
describe('NormalizeContext', () => {
/** @type {{context: import('settings').OptionsContext, expected: import('profile-conditions-util').NormalizedOptionsContext}[]} */
const data = [
@@ -54,10 +53,7 @@ function testNormalizeContext() {
expect(actual).toStrictEqual(expected);
});
});
-}
-/** */
-function testSchemas() {
describe('Schemas', () => {
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {{conditionGroups: import('settings').ProfileConditionGroup[], expectedSchema?: import('ext/json-schema').Schema, inputs?: {expected: boolean, context: import('settings').OptionsContext}[]}[]} */
@@ -1113,13 +1109,4 @@ function testSchemas() {
}
});
});
-}
-
-
-/** */
-function main() {
- testNormalizeContext();
- testSchemas();
-}
-
-main();
+});
diff --git a/test/text-source-map.test.js b/test/text-source-map.test.js
index 18252627..09341774 100644
--- a/test/text-source-map.test.js
+++ b/test/text-source-map.test.js
@@ -19,8 +19,7 @@
import {describe, expect, test} from 'vitest';
import {TextSourceMap} from '../ext/js/general/text-source-map.js';
-/** */
-function testSource() {
+describe('TextSourceMap', () => {
describe('Source', () => {
const data = [
['source1'],
@@ -33,10 +32,7 @@ function testSource() {
expect(source).toStrictEqual(sourceMap.source);
});
});
-}
-/** */
-function testEquals() {
describe('Equals', () => {
/** @type {[args1: [source1: string, mapping1: ?(number[])], args2: [source2: string, mapping2: ?(number[])], expectedEquals: boolean][]} */
const data = [
@@ -77,10 +73,7 @@ function testEquals() {
expect(sourceMap1.equals(sourceMap2)).toStrictEqual(expectedEquals);
});
});
-}
-/** */
-function testGetSourceLength() {
describe('GetSourceLength', () => {
/** @type {[args: [source: string, mapping: number[]], finalLength: number, expectedValue: number][]} */
const data = [
@@ -106,10 +99,7 @@ function testGetSourceLength() {
expect(sourceMap.getSourceLength(finalLength)).toStrictEqual(expectedValue);
});
});
-}
-/** */
-function testCombineInsert() {
describe('CombineInsert', () => {
/** @type {[args: [source: string, mapping: ?(number[])], expectedArgs: [expectedSource: string, expectedMapping: ?(number[])], operations: [operation: string, arg1: number, arg2: number][]][]} */
const data = [
@@ -230,16 +220,4 @@ function testCombineInsert() {
expect(sourceMap.equals(expectedSourceMap)).toBe(true);
});
});
-}
-
-
-/** */
-function main() {
- testSource();
- testEquals();
- testGetSourceLength();
- testCombineInsert();
-}
-
-
-main();
+});