11e1b3ca3b
CI / docker (push) Failing after 11s
包含 JSON 格式化、文本/JSON 对比、编解码、变量名转换、二维码、时间戳与颜色转换等工具;修复编辑器行号同步;补充 Vitest 单元测试、Docker 部署与 Gitea CI;完善开源文档;支持通过环境变量配置站点标题、备案号及第三方集成。 Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
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')
|
|
})
|
|
})
|
|
})
|