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/output/formatter_test.go |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/internal/output/formatter_test.go b/internal/output/formatter_test.go
new file mode 100644
index 0000000..d74544a
--- /dev/null
+++ b/internal/output/formatter_test.go
@@ -0,0 +1,41 @@
+package output
+
+import (
+	"strings"
+	"testing"
+
+	"github.com/aisim/kb-cli/internal/search"
+)
+
+func TestFormatTable(t *testing.T) {
+	results := []search.SearchResult{
+		{Path: "FAQ/充装类/001.md", Title: "充装问题", Section: "FAQ", Score: 100},
+	}
+	output := FormatTable(results)
+	if !strings.Contains(output, "FAQ") {
+		t.Error("output should contain section")
+	}
+	if !strings.Contains(output, "100") {
+		t.Error("output should contain score")
+	}
+}
+
+func TestFormatTableEmpty(t *testing.T) {
+	output := FormatTable(nil)
+	if output != "未找到匹配结果" {
+		t.Errorf("output = %q, want %q", output, "未找到匹配结果")
+	}
+}
+
+func TestFormatJSON(t *testing.T) {
+	results := []search.SearchResult{
+		{Path: "test.md", Title: "Test", Score: 50},
+	}
+	output, err := FormatJSON(results)
+	if err != nil {
+		t.Fatalf("FormatJSON failed: %v", err)
+	}
+	if !strings.Contains(output, "test.md") {
+		t.Error("JSON should contain path")
+	}
+}

--
Gitblit v1.9.1