From 703fd2cbe6ec2be2995d0c3bb6ae8be08ac480b9 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 16 Dec 2024 15:41:00 +0000 Subject: [PATCH] chore(common/web): add use case for string array --- .../kmx/kmx-plus/element-string.tests.ts | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/common/web/types/tests/kmx/kmx-plus/element-string.tests.ts b/common/web/types/tests/kmx/kmx-plus/element-string.tests.ts index ce3db90fc3..7c187d9920 100644 --- a/common/web/types/tests/kmx/kmx-plus/element-string.tests.ts +++ b/common/web/types/tests/kmx/kmx-plus/element-string.tests.ts @@ -9,11 +9,12 @@ import 'mocha'; import { assert } from 'chai'; import { ElemElementFlags, ElemElement, ElementString } from '../../../src/kmx/kmx-plus/element-string.js'; -import { StrsItem, UsetItem } from '../../../src/kmx/kmx-plus/kmx-plus.js'; +import { StrsItem, UsetItem, DependencySections, Strs } from '../../../src/kmx/kmx-plus/kmx-plus.js'; import { UnicodeSet } from '../../../src/ldml-keyboard/unicodeset-parser-api.js'; const GOTHIC_A = new StrsItem("𐌰", 0x10330); const GOTHIC_B = new StrsItem("𐌱", 0x10331); +const GOTHIC_C = new StrsItem("𐌲", 0x10332); const UGARITIC_A = new StrsItem("𐎀", 0x10380); const GOTHIC_SET = new UsetItem( new UnicodeSet("[𐌰-𐍊]", [[0x10330,0x1034A]]), @@ -43,13 +44,13 @@ describe('Test of ElementString', () => { assert.isFalse(one.isEqual(two)); }); it('returns false when tertiary differs', () => { - const one = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 1); - const two = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 2); + const one = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 0); + const two = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 1); assert.isFalse(one.isEqual(two)); }); it('returns false when flags differs', () => { - const one = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 1, ElemElementFlags.none); - const two = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 1, ElemElementFlags.type); + const one = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 0, ElemElementFlags.none); + const two = initElemElement(GOTHIC_A, GOTHIC_SET, 0, 0, ElemElementFlags.type); assert.isFalse(one.isEqual(two)); }); it('returns true even though uset differs', () => { @@ -61,19 +62,30 @@ describe('Test of ElementString', () => { }); describe('Test of ElementString', () => { describe('Test of fromStrings()', () => { - it('returns an empty El;ementString if source is null', () => { + it('returns an empty ElementString if source is null', () => { const es = ElementString.fromStrings({}, null); assert.deepEqual(es, new ElementString()); }); + it('can create an ElementString from a string array', () => { + const strs: Strs = new Strs(); + const sections: DependencySections = { strs: strs }; + const actual = ElementString.fromStrings(sections, ["𐌰", "𐌱", "𐌲"]); + const expected = [ + initElemElement(GOTHIC_A), + initElemElement(GOTHIC_B), + initElemElement(GOTHIC_C), + ]; + assert.deepEqual(actual, expected); + }); }); }); }); function initElemElement( value: StrsItem = GOTHIC_A, - uset: UsetItem = GOTHIC_SET, + uset: UsetItem = undefined, order: number = 0, - tertiary: number = 1, + tertiary: number = 0, flags: ElemElementFlags = ElemElementFlags.none, ): ElemElement { const ee = new ElemElement();