From cbaae084f7ae7cbee9d9dc69b1c44d497ae41dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20V=C3=B6lker?= Date: Fri, 24 Oct 2025 13:31:15 +0200 Subject: [PATCH 1/4] test(kmc-analyze): add warnings coverage tests for AnalyzeOskCharacterUse --- .../test/osk-character-use-warnings.tests.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts diff --git a/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts b/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts new file mode 100644 index 0000000000..e1cfdf35f0 --- /dev/null +++ b/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts @@ -0,0 +1,52 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + */ +import * as fs from 'fs'; +import { assert } from 'chai'; +import 'mocha'; +import { AnalyzeOskCharacterUse } from '../src/osk-character-use/index.js'; +import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; +import { AnalyzerMessages } from '../src/analyzer-messages.js'; + +describe('AnalyzeOskCharacterUse warnings', function() { + const callbacks = new TestCompilerCallbacks(); + const TMP_NO_COUNTS = '/tmp/mock-map-no-counts.json'; + const TMP_WITH_COUNTS = '/tmp/mock-map-with-counts.json'; + + before(() => { + fs.writeFileSync(TMP_NO_COUNTS, JSON.stringify({ + map: [{ usages: ['U+1780', 'U+1781'] }] + })); + fs.writeFileSync(TMP_WITH_COUNTS, JSON.stringify({ + map: [{ usages: [{ char: 'U+1780', count: 2 }] }] + })); + }); + + beforeEach(() => callbacks.clear()); + + it('warns if previous map did not include counts but includeCounts=true', function() { + const a = new AnalyzeOskCharacterUse(callbacks, { + includeCounts: true + }); + + a.unitTestEndPoints.loadPreviousMap(TMP_NO_COUNTS); + + assert.isTrue( + callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidNotIncludeCounts), + 'Expected Warn_PreviousMapDidNotIncludeCounts warning' + ); + }); + + it('warns if previous map did include counts but includeCounts=false', function() { + const a = new AnalyzeOskCharacterUse(callbacks, { + includeCounts: false + }); + + a.unitTestEndPoints.loadPreviousMap(TMP_WITH_COUNTS); + + assert.isTrue( + callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidIncludeCounts), + 'Expected Warn_PreviousMapDidIncludeCounts warning' + ); + }); +}); From 07c13e81ac032b9d1257aad3f0d485747c1da691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20V=C3=B6lker?= Date: Sat, 25 Oct 2025 07:34:31 +0200 Subject: [PATCH 2/4] test(kmc-analyze): add message coverage tests for AnalyzeOskCharacterUse --- .../osk-character-use/mock-map-no-counts.json | 10 ++++ .../mock-map-with-counts.json | 12 ++++ .../test/osk-character-use-messages.tests.ts | 58 +++++++++++++++++++ .../test/osk-character-use-warnings.tests.ts | 52 ----------------- 4 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-no-counts.json create mode 100644 developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-with-counts.json create mode 100644 developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts delete mode 100644 developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts diff --git a/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-no-counts.json b/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-no-counts.json new file mode 100644 index 0000000000..713091194b --- /dev/null +++ b/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-no-counts.json @@ -0,0 +1,10 @@ +{ + "map": [ + { + "usages": [ + "U+1780", + "U+1781" + ] + } + ] +} \ No newline at end of file diff --git a/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-with-counts.json b/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-with-counts.json new file mode 100644 index 0000000000..bec0e8727b --- /dev/null +++ b/developer/src/kmc-analyze/test/fixtures/osk-character-use/mock-map-with-counts.json @@ -0,0 +1,12 @@ +{ + "map": [ + { + "usages": [ + { + "char": "U+1780", + "count": 2 + } + ] + } + ] +} \ No newline at end of file diff --git a/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts new file mode 100644 index 0000000000..c3c59a8260 --- /dev/null +++ b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts @@ -0,0 +1,58 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + */ +import { assert } from 'chai'; +import 'mocha'; +import { AnalyzeOskCharacterUse } from './osk-character-use/index.js'; +import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; +import { AnalyzerMessages } from './analyzer-messages.js'; +import { makePathToFixture } from './helpers/index.js'; + +describe('AnalyzeOskCharacterUse warnings', function() { + const callbacks = new TestCompilerCallbacks(); + + const MOCK_MAP_NO_COUNTS = makePathToFixture( + 'osk-character-use', + 'mock-map-no-counts.json' + ); + const MOCK_MAP_WITH_COUNTS = makePathToFixture( + 'osk-character-use', + 'mock-map-with-counts.json' + ); + + this.beforeEach(function() { + callbacks.clear(); + }); + + this.afterEach(function() { + if (this.currentTest?.isFailed()) { + callbacks.printMessages(); + } + }); + + it('warns if previous map did not include counts but includeCounts=true', function() { + const a = new AnalyzeOskCharacterUse(callbacks, { + includeCounts: true + }); + + a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_NO_COUNTS); + + assert.isTrue( + callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidNotIncludeCounts), + 'Expected Warn_PreviousMapDidNotIncludeCounts warning' + ); + }); + + it('warns if previous map did include counts but includeCounts=false', function() { + const a = new AnalyzeOskCharacterUse(callbacks, { + includeCounts: false + }); + + a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_WITH_COUNTS); + + assert.isTrue( + callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidIncludeCounts), + 'Expected Warn_PreviousMapDidIncludeCounts warning' + ); + }); +}); diff --git a/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts b/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts deleted file mode 100644 index e1cfdf35f0..0000000000 --- a/developer/src/kmc-analyze/test/osk-character-use-warnings.tests.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Keyman is copyright (C) SIL Global. MIT License. - */ -import * as fs from 'fs'; -import { assert } from 'chai'; -import 'mocha'; -import { AnalyzeOskCharacterUse } from '../src/osk-character-use/index.js'; -import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; -import { AnalyzerMessages } from '../src/analyzer-messages.js'; - -describe('AnalyzeOskCharacterUse warnings', function() { - const callbacks = new TestCompilerCallbacks(); - const TMP_NO_COUNTS = '/tmp/mock-map-no-counts.json'; - const TMP_WITH_COUNTS = '/tmp/mock-map-with-counts.json'; - - before(() => { - fs.writeFileSync(TMP_NO_COUNTS, JSON.stringify({ - map: [{ usages: ['U+1780', 'U+1781'] }] - })); - fs.writeFileSync(TMP_WITH_COUNTS, JSON.stringify({ - map: [{ usages: [{ char: 'U+1780', count: 2 }] }] - })); - }); - - beforeEach(() => callbacks.clear()); - - it('warns if previous map did not include counts but includeCounts=true', function() { - const a = new AnalyzeOskCharacterUse(callbacks, { - includeCounts: true - }); - - a.unitTestEndPoints.loadPreviousMap(TMP_NO_COUNTS); - - assert.isTrue( - callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidNotIncludeCounts), - 'Expected Warn_PreviousMapDidNotIncludeCounts warning' - ); - }); - - it('warns if previous map did include counts but includeCounts=false', function() { - const a = new AnalyzeOskCharacterUse(callbacks, { - includeCounts: false - }); - - a.unitTestEndPoints.loadPreviousMap(TMP_WITH_COUNTS); - - assert.isTrue( - callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidIncludeCounts), - 'Expected Warn_PreviousMapDidIncludeCounts warning' - ); - }); -}); From 469149e72d606f4632b5cb15b19e0dc7528a0d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20V=C3=B6lker?= Date: Mon, 27 Oct 2025 08:36:56 +0100 Subject: [PATCH 3/4] test(kmc-analyze): add message coverage tests for AnalyzeOskCharacterUse --- .../kmc-analyze/test/osk-character-use-messages.tests.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts index c3c59a8260..1e4cc66a40 100644 --- a/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts +++ b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts @@ -35,8 +35,9 @@ describe('AnalyzeOskCharacterUse warnings', function() { includeCounts: true }); - a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_NO_COUNTS); - + const result = a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_NO_COUNTS); + assert.isNotNull(result, 'Expected map to be loaded successfully'); + assert.isTrue( callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidNotIncludeCounts), 'Expected Warn_PreviousMapDidNotIncludeCounts warning' @@ -48,7 +49,8 @@ describe('AnalyzeOskCharacterUse warnings', function() { includeCounts: false }); - a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_WITH_COUNTS); + const result = a.unitTestEndPoints.loadPreviousMap(MOCK_MAP_WITH_COUNTS); + assert.isNotNull(result, 'Expected map to be loaded successfully'); assert.isTrue( callbacks.hasMessage(AnalyzerMessages.WARN_PreviousMapDidIncludeCounts), From 368766acdc990b891f3a4ced1f1f86b21bc3f9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20V=C3=B6lker?= Date: Mon, 27 Oct 2025 14:05:13 +0100 Subject: [PATCH 4/4] test(kmc-analyze): fix import paths and order --- .../src/kmc-analyze/test/osk-character-use-messages.tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts index 1e4cc66a40..540ef3cb41 100644 --- a/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts +++ b/developer/src/kmc-analyze/test/osk-character-use-messages.tests.ts @@ -3,9 +3,9 @@ */ import { assert } from 'chai'; import 'mocha'; -import { AnalyzeOskCharacterUse } from './osk-character-use/index.js'; import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; -import { AnalyzerMessages } from './analyzer-messages.js'; +import { AnalyzeOskCharacterUse } from '../src/osk-character-use/index.js'; +import { AnalyzerMessages } from '../src/analyzer-messages.js'; import { makePathToFixture } from './helpers/index.js'; describe('AnalyzeOskCharacterUse warnings', function() {