本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
// dacli/tests/unit/codegen_snake_to_pascal.test.ts
|
|
/**
|
|
* snakeToPascalCase 单元测试 (P1b 2026-06-24 固化)
|
|
*
|
|
* 覆盖:
|
|
* - 丢 appCode 前缀 (jxcj_xxx → Xxx)
|
|
* - PascalCase 输入原样保留
|
|
* - 单段输入 (jxcj → Jxcj)
|
|
* - 极端 case (空 / 纯下划线)
|
|
*
|
|
* 防止 v0.10+ 命名规则回归
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { snakeToPascalCase } from '../../src/commands/form/codegen'
|
|
|
|
describe('snakeToPascalCase (P1b)', () => {
|
|
describe('丢 appCode 前缀 (主要场景)', () => {
|
|
it('jxcj_announcement + jxcj → Announcement', () => {
|
|
expect(snakeToPascalCase('jxcj_announcement', 'jxcj')).toBe('Announcement')
|
|
})
|
|
it('jxcj_develop_project + jxcj → DevelopProject', () => {
|
|
expect(snakeToPascalCase('jxcj_develop_project', 'jxcj')).toBe('DevelopProject')
|
|
})
|
|
it('jxcj_notification_record + jxcj → NotificationRecord', () => {
|
|
expect(snakeToPascalCase('jxcj_notification_record', 'jxcj')).toBe('NotificationRecord')
|
|
})
|
|
it('tds_billing + tds → Billing', () => {
|
|
expect(snakeToPascalCase('tds_billing', 'tds')).toBe('Billing')
|
|
})
|
|
it('tds_sandbox_config + tds → SandboxConfig', () => {
|
|
expect(snakeToPascalCase('tds_sandbox_config', 'tds')).toBe('SandboxConfig')
|
|
})
|
|
it('大小写不敏感匹配: Jxcj_xxx + jxcj → Xxx', () => {
|
|
expect(snakeToPascalCase('Jxcj_announcement', 'jxcj')).toBe('Announcement')
|
|
})
|
|
})
|
|
|
|
describe('PascalCase 输入原样保留', () => {
|
|
it('JxcjAnnouncement (无 _) → 原样', () => {
|
|
expect(snakeToPascalCase('JxcjAnnouncement', 'jxcj')).toBe('JxcjAnnouncement')
|
|
})
|
|
it('TdsBilling → 原样', () => {
|
|
expect(snakeToPascalCase('TdsBilling', undefined)).toBe('TdsBilling')
|
|
})
|
|
it('不传 appCode 不破坏 PascalCase', () => {
|
|
expect(snakeToPascalCase('TdsBilling', 'jxcj')).toBe('TdsBilling')
|
|
})
|
|
})
|
|
|
|
describe('边缘 case', () => {
|
|
it('单段 + appCode 匹配: jxcj + jxcj → Jxcj', () => {
|
|
expect(snakeToPascalCase('jxcj', 'jxcj')).toBe('Jxcj')
|
|
})
|
|
it('单段无 appCode: hello → Hello', () => {
|
|
expect(snakeToPascalCase('hello', undefined)).toBe('Hello')
|
|
})
|
|
it('空字符串 → 空字符串', () => {
|
|
expect(snakeToPascalCase('', undefined)).toBe('')
|
|
})
|
|
it('a_b_c (多段无 appCode) → ABC', () => {
|
|
expect(snakeToPascalCase('a_b_c', undefined)).toBe('ABC')
|
|
})
|
|
})
|
|
|
|
describe('jxcj 28 form 实际 enCode 回归', () => {
|
|
const cases: [string, string][] = [
|
|
['jxcj_enroll_record', 'EnrollRecord'],
|
|
['jxcj_competition_info', 'CompetitionInfo'],
|
|
['jxcj_data_resource', 'DataResource'],
|
|
['jxcj_topic_direction', 'TopicDirection'],
|
|
['jxcj_announcement', 'Announcement'],
|
|
['jxcj_final_ranking', 'FinalRanking'],
|
|
['jxcj_review_score', 'ReviewScore'],
|
|
['jxcj_sandbox_config', 'SandboxConfig'],
|
|
['jxcj_code_audit_record', 'CodeAuditRecord'],
|
|
['jxcj_team_member', 'TeamMember'],
|
|
]
|
|
for (const [enCode, expected] of cases) {
|
|
it(`${enCode} + jxcj → ${expected}`, () => {
|
|
expect(snakeToPascalCase(enCode, 'jxcj')).toBe(expected)
|
|
})
|
|
}
|
|
})
|
|
})
|