Merge pull request #15021 from cvosoft/test/add-osk-character-use-warnings

test(developer): add coverage tests for warning messages in kmc-analyze/AnalyzeOskCharacterUse
This commit is contained in:
Marc Durdin 2025-10-27 16:00:41 +01:00 committed by GitHub
commit 4a685ba8aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,10 @@
{
"map": [
{
"usages": [
"U+1780",
"U+1781"
]
}
]
}

View file

@ -0,0 +1,12 @@
{
"map": [
{
"usages": [
{
"char": "U+1780",
"count": 2
}
]
}
]
}

View file

@ -0,0 +1,60 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*/
import { assert } from 'chai';
import 'mocha';
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
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() {
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
});
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'
);
});
it('warns if previous map did include counts but includeCounts=false', function() {
const a = new AnalyzeOskCharacterUse(callbacks, {
includeCounts: false
});
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),
'Expected Warn_PreviousMapDidIncludeCounts warning'
);
});
});