mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
test: worked with chatgpt to restrict the i18n test a bit to match requirements
This commit is contained in:
44
test/i18n.js
44
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) => {
|
||||
|
||||
Reference in New Issue
Block a user