Skip to content

Commit

Permalink
test: added i18n test to enforce kebab casing
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Oct 5, 2023
1 parent 6f5a965 commit 69dde2b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/i18n.js
Expand Up @@ -38,6 +38,8 @@ describe('i18n', () => {
const sourceStrings = new Map();

describe('source language file structure', () => {
const test = /^[0-9a-z.-]+$/;

it('should only contain valid JSON files', async () => {
try {
fullPaths.forEach((fullPath) => {
Expand All @@ -52,6 +54,27 @@ describe('i18n', () => {
assert(!e, `Invalid JSON found: ${e.message}`);
}
});

it('should only contain lowercase or numeric language keys separated by either dashes or periods', async () => {
fullPaths.forEach((fullPath) => {
if (fullPath.endsWith('_DO_NOT_EDIT_FILES_HERE.md')) {
return;
}

const hash = require(fullPath);
const keys = Object.keys(hash);

keys.forEach(key => assert(test.test(key), `${key} contains invalid characters`));
});
});

it('regexp used in test should test according to expectations', () => {
const valid = ['foo.bar', 'foo.bar-baz', 'foo.bar.baz-quux-lorem-ipsum-dolor-sit-amet'];
const invalid = ['camelCase', 'PascalCase', 'snake_case', 'badger.badger_badger_badger', 'snnnaaaaaaAAAAAAkeeee'];

assert(valid.every(key => test.test(key)));
assert(!invalid.every(key => test.test(key)));
});
});

folders.forEach((language) => {
Expand Down

0 comments on commit 69dde2b

Please sign in to comment.