diff --git a/test/buildPronoun.test.js b/test/buildPronoun.test.js index 93c0cd979..e32cc5a72 100644 --- a/test/buildPronoun.test.js +++ b/test/buildPronoun.test.js @@ -9,69 +9,7 @@ jest.unstable_mockModule('../data/pronouns/morphemes.js', () => { const { Pronoun } = await import('../src/classes.js'); const { buildPronoun } = await import('../src/buildPronoun.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', - '', - ), -}; +const { default: pronouns } = await import('./fixtures/pronouns.js'); beforeEach(() => { global.config.pronouns = { diff --git a/test/classes.test.js b/test/classes.test.js new file mode 100644 index 000000000..de1d97af3 --- /dev/null +++ b/test/classes.test.js @@ -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 }, + }, + ], + }, + ); + }); +}); diff --git a/test/fixtures/pronouns.js b/test/fixtures/pronouns.js new file mode 100644 index 000000000..e1fbe4665 --- /dev/null +++ b/test/fixtures/pronouns.js @@ -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, +};