From 99364427069d133fbb200c789fe7e35d3cb924ea Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 13 Oct 2023 12:46:37 -0400 Subject: [PATCH] test: worked with chatgpt to restrict the i18n test a bit to match requirements --- test/i18n.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/test/i18n.js b/test/i18n.js index 6d7a2ee4b3..2b1e9863f0 100644 --- a/test/i18n.js +++ b/test/i18n.js @@ -38,7 +38,7 @@ describe('i18n', () => { const sourceStrings = new Map(); describe('source language file structure', () => { - const test = /^[0-9\w.\-/]+$/; + const test = /^[a-zA-Z0-9-/]+(\.([0-9a-z]+([A-Z][0-9a-zA-Z]*)*-*\.?)+)*$/; // enhanced by chatgpt so only it knows what this does. it('should only contain valid JSON files', async () => { try { @@ -56,6 +56,37 @@ describe('i18n', () => { }); describe('should only contain lowercase or numeric language keys separated by either dashes or periods', async () => { + describe('(regexp validation)', () => { + const valid = [ + 'foo.bar', 'foo.bar-baz', 'foo.bar.baz-quux-lorem-ipsum-dolor-sit-amet', 'foo.barBazQuux', // human generated + "example-name.isValid", "kebab-case.isGood", "camelcase.isFine", "camelcase.with-dashes.isAlsoFine", "single-character.is-ok", "abc.def", // chatgpt generated + ]; + const invalid = [ + // human generated + 'foo.PascalCase', 'foo.snake_case', + 'badger.badger_badger_badger', + 'foo.BarBazQuux', + + // chatgpt generated + "!notValid", // Starts with a special character + "with space.isInvalid", // Contains a space + ".startsWithPeriod.isInvalid", // Starts with a period + "invalid..case.isInvalid", // Consecutive periods + "camelCase.With-Dashes.isAlsoInvalid", // PascalCase "With" is not allowed + ]; + + valid.forEach((key) => { + it(key, () => { + assert(test.test(key)) + }); + }); + invalid.forEach((key) => { + it(key, () => { + assert(!test.test(key)) + }); + }); + }); + fullPaths.forEach((fullPath) => { if (fullPath.endsWith('_DO_NOT_EDIT_FILES_HERE.md')) { return; @@ -71,17 +102,6 @@ describe('i18n', () => { }); }); }); - /* - 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) => {