From 69dde2b9ddfc2269b1fb9d500db38f92eb067f74 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 5 Oct 2023 14:41:24 -0400 Subject: [PATCH] test: added i18n test to enforce kebab casing --- test/i18n.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/i18n.js b/test/i18n.js index 916fa595bb..1c3cda9708 100644 --- a/test/i18n.js +++ b/test/i18n.js @@ -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) => { @@ -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) => {