From 09c2a03cefa687832257d3b816da50db3cfcc0f2 Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sat, 25 Jul 2026 23:48:11 +0800
Subject: [PATCH] feat: 实现输出格式化
---
internal/vault/parser_test.go | 71 +++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/internal/vault/parser_test.go b/internal/vault/parser_test.go
new file mode 100644
index 0000000..d0b65ec
--- /dev/null
+++ b/internal/vault/parser_test.go
@@ -0,0 +1,71 @@
+package vault
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestParseFile(t *testing.T) {
+ // 创建临时测试文件
+ tmpDir := t.TempDir()
+ testFile := filepath.Join(tmpDir, "test.md")
+ content := `---
+title: 测试文档
+tags:
+ - 充装
+ - 智能枪
+entities:
+ - YSP-35.5
+---
+
+# 测试内容
+
+这是一个关于 [[充装规格配置]] 的文档。
+也引用了 [[智能枪使用指南]]。
+`
+ os.WriteFile(testFile, []byte(content), 0644)
+
+ meta, err := ParseFile(testFile, "FAQ/充装类/test.md")
+ if err != nil {
+ t.Fatalf("ParseFile failed: %v", err)
+ }
+
+ if meta.Title != "测试文档" {
+ t.Errorf("Title = %q, want %q", meta.Title, "测试文档")
+ }
+ if len(meta.Tags) != 2 || meta.Tags[0] != "充装" {
+ t.Errorf("Tags = %v, want [充装 智能枪]", meta.Tags)
+ }
+ if len(meta.Entities) != 1 || meta.Entities[0] != "YSP-35.5" {
+ t.Errorf("Entities = %v, want [YSP-35.5]", meta.Entities)
+ }
+ if len(meta.Wikilinks) != 2 {
+ t.Errorf("Wikilinks count = %d, want 2", len(meta.Wikilinks))
+ }
+ if meta.Section != "FAQ" {
+ t.Errorf("Section = %q, want %q", meta.Section, "FAQ")
+ }
+}
+
+func TestParseFileNoFrontmatter(t *testing.T) {
+ tmpDir := t.TempDir()
+ testFile := filepath.Join(tmpDir, "nofm.md")
+ content := `# 没有 frontmatter
+
+只有内容。
+`
+ os.WriteFile(testFile, []byte(content), 0644)
+
+ meta, err := ParseFile(testFile, "笔记/nofm.md")
+ if err != nil {
+ t.Fatalf("ParseFile failed: %v", err)
+ }
+
+ if meta.Title != "" {
+ t.Errorf("Title = %q, want empty", meta.Title)
+ }
+ if len(meta.Tags) != 0 {
+ t.Errorf("Tags = %v, want empty", meta.Tags)
+ }
+}
--
Gitblit v1.9.1