@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
parseToWords,
|
||||
toCamelCase,
|
||||
toPascalCase,
|
||||
toSnakeCase,
|
||||
toKebabCase,
|
||||
toConstantCase,
|
||||
} from '../../src/utils/variableName.js'
|
||||
|
||||
describe('variableName', () => {
|
||||
describe('parseToWords', () => {
|
||||
it('returns empty array for blank input', () => {
|
||||
expect(parseToWords('')).toEqual([])
|
||||
expect(parseToWords(' ')).toEqual([])
|
||||
})
|
||||
|
||||
it('parses snake_case', () => {
|
||||
expect(parseToWords('hello_world')).toEqual(['hello', 'world'])
|
||||
})
|
||||
|
||||
it('parses kebab-case', () => {
|
||||
expect(parseToWords('hello-world')).toEqual(['hello', 'world'])
|
||||
})
|
||||
|
||||
it('parses camelCase', () => {
|
||||
expect(parseToWords('helloWorld')).toEqual(['hello', 'world'])
|
||||
})
|
||||
|
||||
it('parses PascalCase', () => {
|
||||
expect(parseToWords('HelloWorld')).toEqual(['hello', 'world'])
|
||||
})
|
||||
|
||||
it('parses consecutive uppercase (XMLHttpRequest)', () => {
|
||||
expect(parseToWords('XMLHttpRequest')).toEqual(['xml', 'http', 'request'])
|
||||
})
|
||||
|
||||
it('parses numbers in identifiers', () => {
|
||||
expect(parseToWords('item2')).toEqual(['item', '2'])
|
||||
expect(parseToWords('temp2Detail')).toEqual(['temp', '2', 'detail'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('case conversions', () => {
|
||||
const words = ['hello', 'world']
|
||||
|
||||
it('converts to camelCase', () => {
|
||||
expect(toCamelCase(words)).toBe('helloWorld')
|
||||
expect(toCamelCase([])).toBe('')
|
||||
})
|
||||
|
||||
it('converts to PascalCase', () => {
|
||||
expect(toPascalCase(words)).toBe('HelloWorld')
|
||||
})
|
||||
|
||||
it('converts to snake_case', () => {
|
||||
expect(toSnakeCase(words)).toBe('hello_world')
|
||||
})
|
||||
|
||||
it('converts to kebab-case', () => {
|
||||
expect(toKebabCase(words)).toBe('hello-world')
|
||||
})
|
||||
|
||||
it('converts to CONSTANT_CASE', () => {
|
||||
expect(toConstantCase(words)).toBe('HELLO_WORLD')
|
||||
})
|
||||
|
||||
it('preserves numeric words in camelCase', () => {
|
||||
expect(toCamelCase(['item', '2'])).toBe('item2')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user