mirror of
https://github.com/keymanapp/keyman.git
synced 2026-11-03 09:37:47 +00:00
chore(common/web): add four test cases for sourceOrBinaryTypeFromFilename()
This commit is contained in:
parent
324c57f793
commit
1782f8db09
1 changed files with 45 additions and 11 deletions
|
|
@ -8,21 +8,25 @@
|
|||
|
||||
import 'mocha';
|
||||
import { assert } from 'chai';
|
||||
import { removeExtension } from '../../src/util/file-types.js';
|
||||
|
||||
const sourceExts = [ // can't use Source, as it is const enum
|
||||
'.model.ts',
|
||||
'.kpj',
|
||||
'.kmn',
|
||||
'.xml',
|
||||
'.kvks',
|
||||
'.keyman-touch-layout',
|
||||
];
|
||||
import {
|
||||
ALL,
|
||||
ALL_SOURCE,
|
||||
ALL_BINARY,
|
||||
removeExtension,
|
||||
sourceOrBinaryTypeFromFilename
|
||||
} from '../../src/util/file-types.js';
|
||||
|
||||
describe('Test of File-Types', () => {
|
||||
describe('Test of removeExtension()', () => {
|
||||
it('can remove Source file extension', () => {
|
||||
sourceExts.forEach((ext) => {
|
||||
ALL_SOURCE.forEach((ext) => {
|
||||
const filename = `file${ext}`;
|
||||
const actual = removeExtension(filename);
|
||||
assert.deepEqual(actual, "file");
|
||||
});
|
||||
});
|
||||
it('can remove Binary file extension', () => {
|
||||
ALL_BINARY.forEach((ext) => {
|
||||
const filename = `file${ext}`;
|
||||
const actual = removeExtension(filename);
|
||||
assert.deepEqual(actual, "file");
|
||||
|
|
@ -33,4 +37,34 @@ describe('Test of File-Types', () => {
|
|||
assert.deepEqual(filename, "file");
|
||||
});
|
||||
});
|
||||
describe('Test of sourceOrBinaryTypeFromFilename()', () => {
|
||||
it('can extract Source file extension', () => {
|
||||
ALL_SOURCE.forEach((ext) => {
|
||||
const filename = `file${ext}`;
|
||||
const actual = sourceOrBinaryTypeFromFilename(filename);
|
||||
assert.deepEqual(actual, ext);
|
||||
});
|
||||
});
|
||||
it('can extract Binary file extension', () => {
|
||||
ALL_BINARY.forEach((ext) => {
|
||||
const filename = `file${ext}`;
|
||||
const actual = sourceOrBinaryTypeFromFilename(filename);
|
||||
assert.deepEqual(actual, ext);
|
||||
});
|
||||
});
|
||||
it('returns null for unmatched file extension', () => {
|
||||
const ext = ".cpp";
|
||||
assert.isFalse((Object.values(ALL) as string[]).includes(ext));
|
||||
const filename = `file${ext}`;
|
||||
const actual = sourceOrBinaryTypeFromFilename(filename);
|
||||
assert.isNull(actual);
|
||||
});
|
||||
it('can extract upper case file extension', () => {
|
||||
const ext = ALL[0];
|
||||
const upperCaseExt = ext.toUpperCase();
|
||||
const filename = `file${upperCaseExt}`;
|
||||
const actual = sourceOrBinaryTypeFromFilename(filename);
|
||||
assert.deepEqual(actual, ext);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue