From 370fcd5659d934655cb4139d9dcc2bd73e7bd5ae Mon Sep 17 00:00:00 2001 From: DGCK81LNN <54282183+DGCK81LNN@users.noreply.github.com> Date: Tue, 9 Jan 2024 12:16:43 +0800 Subject: [PATCH] test: improve test for sorting alternations --- package/test/base_transcribers.spec.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/package/test/base_transcribers.spec.ts b/package/test/base_transcribers.spec.ts index b03dc0b..7fd121f 100644 --- a/package/test/base_transcribers.spec.ts +++ b/package/test/base_transcribers.spec.ts @@ -60,7 +60,11 @@ describe("base_transcribers", function () { it("reorders alternations according to hints", function () { const t = new HanziToAlphaTranscriber({ dict: [ - { h: "A", x: "111", n: "bottom", hh: "-" }, + // Correct order is: + // conditional matching > regular > conditional non-matching > exceptional > legacy + // A should give 333-222-111-000 when condition for 333 matches, 222-333-111-000 otherwise + { h: "A", x: "000", n: "legacy", hh: "-", xh: "-" }, + { h: "A", x: "111", n: "exceptional", hh: "-" }, { h: "A", x: "222", n: "regular" }, { h: "A", x: "333", n: "conditional", hh: "A~ B~ ~D" }, { h: "B", x: "444" }, @@ -77,6 +81,7 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], ]) expect(t.transcribe("AA")).toEqual([ @@ -84,11 +89,13 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], [ OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], ]) expect(t.transcribe("BA")).toEqual([ @@ -97,6 +104,7 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], ]) expect(t.transcribe("CA")).toEqual([ @@ -105,6 +113,7 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], ]) expect(t.transcribe("AD")).toEqual([ @@ -112,6 +121,7 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], OW({ h: "D", x: "666" }), ]) @@ -120,6 +130,7 @@ describe("base_transcribers", function () { OW({ content: [OW({ h: "A", x: "222" })] }), OW({ content: [OW({ h: "A", x: "333" })] }), OW({ content: [OW({ h: "A", x: "111" })] }), + OW({ content: [OW({ h: "A", x: "000" })] }), ], OW({ h: "E", x: "777" }), ])