2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-01-12 01:10:35 +00:00
|
|
|
import { assert } from 'chai';
|
2020-04-15 20:44:46 +00:00
|
|
|
|
2022-01-12 01:10:35 +00:00
|
|
|
import { getLanguages } from '../../../app/spell_check';
|
2020-04-15 20:44:46 +00:00
|
|
|
|
|
|
|
describe('SpellCheck', () => {
|
|
|
|
describe('getLanguages', () => {
|
|
|
|
it('works with locale and base available', () => {
|
2023-03-31 22:36:14 +00:00
|
|
|
assert.deepEqual(getLanguages(['en-US'], ['en-US', 'en'], 'en'), [
|
2020-04-15 20:44:46 +00:00
|
|
|
'en-US',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-03-31 22:36:14 +00:00
|
|
|
it('uses icu likely subtags rules to match languages', () => {
|
|
|
|
assert.deepEqual(getLanguages(['fa-FR'], ['fa-IR'], 'en'), ['fa-IR']);
|
|
|
|
assert.deepEqual(getLanguages(['zh'], ['zh-Hans-CN'], 'en'), [
|
|
|
|
'zh-Hans-CN',
|
2020-04-15 20:44:46 +00:00
|
|
|
]);
|
2023-03-31 22:36:14 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
getLanguages(['zh-HK'], ['zh-Hans-CN', 'zh-Hant-HK'], 'en'),
|
|
|
|
['zh-Hant-HK']
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('matches multiple locales', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
getLanguages(['fr-FR', 'es'], ['fr', 'es-ES', 'en-US'], 'en'),
|
|
|
|
['fr', 'es-ES']
|
|
|
|
);
|
2020-04-15 20:44:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('works with only base locale available', () => {
|
2023-03-31 22:36:14 +00:00
|
|
|
assert.deepEqual(getLanguages(['en-US'], ['en'], 'en'), ['en']);
|
2020-04-15 20:44:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('works with only full locale available', () => {
|
2023-03-31 22:36:14 +00:00
|
|
|
assert.deepEqual(getLanguages(['en-US'], ['en-CA', 'en-US'], 'en'), [
|
|
|
|
'en-US',
|
|
|
|
]);
|
2020-04-15 20:44:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('works with base provided and base available', () => {
|
2023-03-31 22:36:14 +00:00
|
|
|
assert.deepEqual(getLanguages(['en'], ['en-CA', 'en-US', 'en'], 'en'), [
|
|
|
|
'en',
|
|
|
|
]);
|
2020-04-15 20:44:46 +00:00
|
|
|
});
|
|
|
|
|
2023-03-31 22:36:14 +00:00
|
|
|
it('falls back to default', () => {
|
|
|
|
assert.deepEqual(getLanguages(['fa-IR'], ['es-ES', 'fr-FR'], 'en'), [
|
|
|
|
'en',
|
2020-04-15 20:44:46 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|