(test) add tests for merging pronoun groups by key

This commit is contained in:
Valentyne Stigloher 2023-12-21 13:31:54 +01:00
parent 541013a558
commit c7735a522c
3 changed files with 132 additions and 63 deletions

View File

@ -9,69 +9,7 @@ jest.unstable_mockModule('../data/pronouns/morphemes.js', () => {
const { Pronoun } = await import('../src/classes.js'); const { Pronoun } = await import('../src/classes.js');
const { buildPronoun } = await import('../src/buildPronoun.js'); const { buildPronoun } = await import('../src/buildPronoun.js');
const { default: pronouns } = await import('./fixtures/pronouns.js');
const pronouns = {
he: new Pronoun(
'he',
'Normative “he/him”',
true,
{
pronoun_subject: 'he',
pronoun_object: 'him',
possessive_determiner: 'his',
possessive_pronoun: 'his',
reflexive: 'himself',
},
[false],
[false],
['he/him'],
'',
true,
'',
'',
'',
),
she: new Pronoun(
'she',
'Normative “she/her”',
true,
{
pronoun_subject: 'she',
pronoun_object: 'her',
possessive_determiner: 'her',
possessive_pronoun: 'hers',
reflexive: 'herself',
},
[false],
[false],
['she/her'],
'',
true,
'',
'',
'',
),
they: new Pronoun(
'they',
'Singular “they”',
true,
{
pronoun_subject: 'they',
pronoun_object: 'them',
possessive_determiner: 'their',
possessive_pronoun: 'theirs',
reflexive: 'themselves',
},
[true],
[true],
['they/them'],
'',
true,
'',
'themselves',
'',
),
};
beforeEach(() => { beforeEach(() => {
global.config.pronouns = { global.config.pronouns = {

61
test/classes.test.js Normal file
View File

@ -0,0 +1,61 @@
import { describe, expect, test } from '@jest/globals';
import { PronounGroup, PronounLibrary } from '../src/classes.js';
import pronouns from './fixtures/pronouns.js';
describe('when merging pronoun groups by key', () => {
test('groups without keys are not assigned a merged group', () => {
const groups = [
new PronounGroup('Normative-ish forms', ['they']),
];
const library = new PronounLibrary(groups, pronouns);
expect(library.byKey()).toEqual({});
});
test('groups with different keys are assigned different merged groups', () => {
const groups = [
new PronounGroup('Binary forms', ['he', 'she'], null, 'normative'),
new PronounGroup('Normative-ish forms', ['they'], null, 'normative-ish'),
];
const library = new PronounLibrary(groups, pronouns);
expect(library.byKey()).toEqual(
{
'normative': [
{
group: groups[0],
groupPronouns: { he: pronouns.he, she: pronouns.she },
},
],
'normative-ish': [
{
group: groups[1],
groupPronouns: { they: pronouns.they },
},
],
},
);
});
test('groups with same key are assigned same merged group', () => {
const groups = [
new PronounGroup('Binary forms', ['he', 'she'], null, 'normative-ish'),
new PronounGroup('Normative-ish forms', ['they'], null, 'normative-ish'),
];
const library = new PronounLibrary(groups, pronouns);
expect(library.byKey()).toEqual(
{
'normative-ish': [
{
group: groups[0],
groupPronouns: { he: pronouns.he, she: pronouns.she },
},
{
group: groups[1],
groupPronouns: { they: pronouns.they },
},
],
},
);
});
});

70
test/fixtures/pronouns.js vendored Normal file
View File

@ -0,0 +1,70 @@
import { Pronoun } from '../../src/classes.js';
const he = new Pronoun(
'he',
'Normative “he/him”',
true,
{
pronoun_subject: 'he',
pronoun_object: 'him',
possessive_determiner: 'his',
possessive_pronoun: 'his',
reflexive: 'himself',
},
[false],
[false],
['he/him'],
'',
true,
'',
'',
'',
);
const she = new Pronoun(
'she',
'Normative “she/her”',
true,
{
pronoun_subject: 'she',
pronoun_object: 'her',
possessive_determiner: 'her',
possessive_pronoun: 'hers',
reflexive: 'herself',
},
[false],
[false],
['she/her'],
'',
true,
'',
'',
'',
);
const they = new Pronoun(
'they',
'Singular “they”',
true,
{
pronoun_subject: 'they',
pronoun_object: 'them',
possessive_determiner: 'their',
possessive_pronoun: 'theirs',
reflexive: 'themselves',
},
[true],
[true],
['they/them'],
'',
true,
'',
'themselves',
'',
);
export default {
he,
she,
they,
};