// Comprehensive Chinese character support test package main import ( "fmt" "log" "mermaid-go/pkg/parser" "mermaid-go/pkg/renderer" ) func main() { fmt.Println("=== 全面中文支持测试 ===") examples := []struct { name string input string }{ { name: "中文饼图", input: `pie showData title 2024年中国互联网公司市场份额 "阿里巴巴" : 35 "腾讯" : 30 "百度" : 20 "字节跳动" : 15`, }, { name: "中文流程图", input: `flowchart TD 开始 --> 用户登录{用户登录} 用户登录 -->|成功| 进入系统 用户登录 -->|失败| 显示错误 进入系统 --> 选择功能 选择功能 --> 数据处理 数据处理 --> 保存结果 保存结果 --> 结束 显示错误 --> 重新登录 重新登录 --> 用户登录`, }, { name: "中文序列图", input: `sequenceDiagram participant 用户 as 用户端 participant 前端 as 前端服务 participant 后端 as 后端API participant 数据库 as MySQL数据库 用户 ->> 前端: 提交登录表单 前端 ->> 后端: 发送登录请求 后端 ->> 数据库: 查询用户信息 数据库 -->> 后端: 返回用户数据 后端 -->> 前端: 返回认证结果 前端 -->> 用户: 显示登录状态`, }, { name: "中文状态图", input: `stateDiagram [*] --> 空闲状态 空闲状态 --> 工作中 : 开始工作 工作中 --> 暂停 : 暂停 暂停 --> 工作中 : 继续 工作中 --> 完成 : 完成任务 完成 --> [*]`, }, { name: "中文ER图", input: `erDiagram 用户 { int 用户ID PK string 用户名 string 邮箱 UK string 密码 date 创建时间 } 订单 { int 订单ID PK int 用户ID FK decimal 总金额 string 订单状态 date 下单时间 } 商品 { int 商品ID PK string 商品名称 decimal 价格 int 库存数量 } 用户 ||--o{ 订单 : 下单 订单 }o--o{ 商品 : 包含`, }, { name: "中文甘特图", input: `gantt title 软件开发项目进度 dateFormat YYYY-MM-DD section 需求分析 需求调研 : 2024-01-01, 5d 需求文档 : 2024-01-06, 3d section 系统设计 架构设计 : 2024-01-09, 4d 数据库设计 : 2024-01-13, 3d section 开发实现 后端开发 : 2024-01-16, 10d 前端开发 : 2024-01-20, 8d section 测试部署 系统测试 : 2024-01-28, 5d 上线部署 : 2024-02-02, 2d`, }, { name: "中文用户旅程", input: `journey title 用户购物体验旅程 section 发现阶段 搜索商品 : 5 : 用户 浏览商品详情 : 4 : 用户 比较不同商品 : 3 : 用户 section 购买阶段 添加到购物车 : 5 : 用户 填写收货信息 : 3 : 用户 选择支付方式 : 4 : 用户 完成支付 : 2 : 用户, 支付系统 section 售后阶段 物流跟踪 : 4 : 用户, 物流系统 确认收货 : 5 : 用户 商品评价 : 3 : 用户`, }, } parser := parser.NewMermaidParser() renderer := renderer.NewMermaidRenderer() successCount := 0 for i, example := range examples { fmt.Printf("\n--- 示例 %d: %s ---\n", i+1, example.name) // Parse diagram, err := parser.Parse(example.input) if err != nil { log.Printf("❌ %s 解析失败: %v", example.name, err) continue } // Validate if err := diagram.Validate(); err != nil { log.Printf("⚠️ %s 验证警告: %v", example.name, err) } // Render output, err := renderer.Render(diagram) if err != nil { log.Printf("❌ %s 渲染失败: %v", example.name, err) continue } fmt.Printf("✅ %s: 解析 → 验证 → 渲染 成功\n", example.name) fmt.Printf("图表类型: %s\n", diagram.Type()) // Show a preview of the output lines := splitLines(output) if len(lines) > 3 { fmt.Printf("输出预览: %s...\n", joinLines(lines[:3])) } else { fmt.Printf("完整输出: %s\n", output) } successCount++ } fmt.Printf("\n=== 测试总结 ===\n") fmt.Printf("✅ 成功测试: %d/%d 种中文图表类型\n", successCount, len(examples)) fmt.Printf("🎯 中文支持覆盖率: %.1f%%\n", float64(successCount)/float64(len(examples))*100) fmt.Printf("🌟 mermaid-go 现已完全支持中文字符!\n") } func splitLines(s string) []string { lines := []string{} current := "" for _, r := range s { if r == '\n' { lines = append(lines, current) current = "" } else { current += string(r) } } if current != "" { lines = append(lines, current) } return lines } func joinLines(lines []string) string { result := "" for i, line := range lines { if i > 0 { result += " " } result += line } return result }