Skip to content

Commit 2dd03c2

Browse files
unit test fix
1 parent 674c44f commit 2dd03c2

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { splitCamelCase } from '../../rulesets/functions/utils/schemaUtils.js';
2+
import { describe, expect, it } from '@jest/globals';
3+
4+
describe('splitCamelCase', () => {
5+
it('should split basic camelCase strings', () => {
6+
expect(splitCamelCase('camelCase')).toEqual(['camel', 'case']);
7+
expect(splitCamelCase('thisIsCamelCase')).toEqual(['this', 'is', 'camel', 'case']);
8+
});
9+
10+
it('should handle single-word strings', () => {
11+
expect(splitCamelCase('word')).toEqual(['word']);
12+
expect(splitCamelCase('Word')).toEqual(['word']);
13+
});
14+
15+
it('should handle strings with numbers', () => {
16+
expect(splitCamelCase('user123Name')).toEqual(['user123', 'name']);
17+
expect(splitCamelCase('user123name')).toEqual(['user123name']);
18+
});
19+
20+
it('should handle empty strings', () => {
21+
expect(splitCamelCase('')).toEqual(['']);
22+
});
23+
24+
it('should handle edge cases from the project', () => {
25+
expect(splitCamelCase('project')).toEqual(['project']);
26+
expect(splitCamelCase('projectId')).toEqual(['project', 'id']);
27+
expect(splitCamelCase('myProjectDetails')).toEqual(['my', 'project', 'details']);
28+
expect(splitCamelCase('projection')).toEqual(['projection']);
29+
});
30+
});

tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function checkViolationsAndReturnErrors(input, options, path) {
3838
const prohibitedName = prohibitedItem.name || '';
3939
const alternative = prohibitedItem.alternative || '';
4040

41-
if (words.some((word) => word.toLowerCase() === prohibitedName)) {
41+
if (words.some((word) => word === prohibitedName)) {
4242
return [
4343
{
4444
path,

tools/spectral/ipa/rulesets/functions/utils/schemaUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ export function getSchemaPathFromEnumPath(path) {
3838
* @returns {*}
3939
*/
4040
export function splitCamelCase(str) {
41-
return str.split(/(?=[A-Z])/);
41+
if (!str) return [''];
42+
43+
// Special handling for single words
44+
if (!/[A-Z]/.test(str)) return [str];
45+
46+
return str.split(/(?=[A-Z])/).map((word) => word.toLowerCase());
4247
}

0 commit comments

Comments
 (0)