Files
wwjcloud-nest-v1/tools-v1/scripts/test-dict-fix.js
wanwujie b5826ee469 feat: 发布 v1 智能框架 0.1.0 版本
🚀 新增功能:
- wwjcloud-nest-v1: 完整的 NestJS 智能框架
- AI 自愈机制: @wwjcloud/auto-healing 模块
- 智能代码生成: tools-v1/php-tools 迁移工具链
- AI 能力规划: v1/docs/AI-CAPABILITY-ROADMAP.md

📦 核心模块:
- libs/wwjcloud-ai: AI 策略和恢复服务
- libs/wwjcloud-boot: 启动和配置管理
- libs/wwjcloud-core: 核心基础设施
- libs/wwjcloud-addon: 插件系统

🏗️ 架构特性:
- 分层渐进式 AI 策略
- 微服务导向的模块化设计
- 与 PHP 项目 100% 业务一致性
- Docker 容器化部署支持

📋 版本信息:
- 版本: v0.1.0
- 发布日期: 2025-01-25
- 分支: v1
2025-10-19 19:55:52 +08:00

176 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 测试 dict-generator 修复
* 验证文件命名和重叠名问题
*/
const DictGenerator = require('./generators/dict-generator');
class DictFixTester {
constructor() {
this.errors = [];
this.passed = [];
}
async run() {
console.log('🧪 测试 dict-generator 修复...\n');
// 测试1: 继承 BaseGenerator
this.testInheritance();
// 测试2: 文件命名规范
this.testFileNaming();
// 测试3: 避免重叠名
this.testNoOverlappingNames();
// 输出结果
this.printResults();
}
testInheritance() {
console.log('📝 测试1: 继承 BaseGenerator');
const generator = new DictGenerator();
if (typeof generator.writeFile === 'function') {
this.passed.push('DictGenerator 继承了 BaseGenerator.writeFile');
console.log(' ✅ 继承了 BaseGenerator.writeFile');
} else {
this.errors.push('DictGenerator 未继承 BaseGenerator.writeFile');
console.log(' ❌ 未继承 BaseGenerator.writeFile');
}
if (typeof generator.printStats === 'function') {
this.passed.push('DictGenerator 继承了 BaseGenerator.printStats');
console.log(' ✅ 继承了 BaseGenerator.printStats');
} else {
this.errors.push('DictGenerator 未继承 BaseGenerator.printStats');
console.log(' ❌ 未继承 BaseGenerator.printStats');
}
if (generator.dryRun !== undefined) {
this.passed.push('DictGenerator 支持 dry-run 模式');
console.log(' ✅ 支持 dry-run 模式');
} else {
this.errors.push('DictGenerator 不支持 dry-run 模式');
console.log(' ❌ 不支持 dry-run 模式');
}
}
testFileNaming() {
console.log('\n📝 测试2: 文件命名规范kebab-case');
const generator = new DictGenerator();
// 模拟生成内容并检查
const testCases = [
{ input: 'Dict', expected: 'dict.enum.ts' },
{ input: 'MemberLevel', expected: 'member-level.enum.ts' },
{ input: 'PayChannel', expected: 'pay-channel.enum.ts' },
{ input: 'dict_service', expected: 'dict-service.enum.ts' }
];
for (const testCase of testCases) {
const kebabName = generator.toKebabCase(testCase.input);
const fileName = `${kebabName}.enum.ts`;
if (fileName === testCase.expected) {
this.passed.push(`文件命名正确: ${testCase.input}${fileName}`);
console.log(`${testCase.input}${fileName}`);
} else {
this.errors.push(`文件命名错误: ${testCase.input} 应为 ${testCase.expected},实际为 ${fileName}`);
console.log(`${testCase.input} 应为 ${testCase.expected},实际为 ${fileName}`);
}
}
}
testNoOverlappingNames() {
console.log('\n📝 测试3: 避免重叠名问题');
const generator = new DictGenerator();
const content = generator.generateDictContent('test', 'Dict');
// 检查1: 应该生成 DictEnum 而不是 DictDict
if (content.includes('export enum DictEnum')) {
this.passed.push('使用 DictEnum 而不是 DictDict');
console.log(' ✅ 使用 DictEnum避免重叠名');
} else if (content.includes('export enum DictDict')) {
this.errors.push('错误使用了 DictDict重叠名');
console.log(' ❌ 错误使用了 DictDict重叠名');
} else {
this.errors.push('未找到枚举定义');
console.log(' ❌ 未找到枚举定义');
}
// 检查2: dictDict 变量名是合理的
if (content.includes('export const dictDict')) {
this.passed.push('dictDict 变量名符合预期');
console.log(' ✅ dictDict 变量名符合预期');
} else {
this.errors.push('dictDict 变量名不正确');
console.log(' ❌ dictDict 变量名不正确');
}
// 检查3: 工具类命名
if (content.includes('export class DictEnumUtil')) {
this.passed.push('工具类使用 DictEnumUtil');
console.log(' ✅ 工具类使用 DictEnumUtil');
} else {
this.errors.push('工具类命名不正确');
console.log(' ❌ 工具类命名不正确');
}
// 检查4: 文件名建议
console.log('\n 💡 推荐文件名模式:');
console.log(' - dict.enum.ts (kebab-case + .enum.ts 后缀)');
console.log(' - member-level.enum.ts');
console.log(' - pay-channel.enum.ts');
console.log('\n ❌ 禁止的文件名:');
console.log(' - DictDict.ts (PascalCase + 重叠名)');
console.log(' - Dict.ts (无后缀)');
}
printResults() {
console.log('\n\n📊 测试结果汇总');
console.log('='.repeat(60));
console.log(`\n✅ 通过项 (${this.passed.length}):`);
this.passed.forEach(item => console.log(` - ${item}`));
if (this.errors.length > 0) {
console.log(`\n❌ 错误项 (${this.errors.length}):`);
this.errors.forEach(item => console.log(` - ${item}`));
}
console.log('\n' + '='.repeat(60));
const totalChecks = this.passed.length + this.errors.length;
const successRate = totalChecks > 0
? ((this.passed.length / totalChecks) * 100).toFixed(2)
: '0.00';
console.log(`📈 成功率: ${successRate}% (${this.passed.length}/${totalChecks})`);
if (this.errors.length === 0) {
console.log('\n🎉 dict-generator 修复验证通过!');
return true;
} else {
console.log(`\n💔 发现 ${this.errors.length} 个错误,需要修复`);
return false;
}
}
}
// 运行测试
if (require.main === module) {
const tester = new DictFixTester();
tester.run().then(passed => {
process.exit(passed ? 0 : 1);
});
}
module.exports = DictFixTester;