ai_xiaopei
2026-07-25 09c2a03cefa687832257d3b816da50db3cfcc0f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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")
    }
}