跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

tab_completion_test.go

67 行 · 1.6 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "slices"
8 "testing"
9
10 "github.com/spf13/cobra"
11 "gotest.tools/v3/assert"
12)
13
14func TestSetFlagCompletion(t *testing.T) {
15 tests := []struct {
16 name string
17 toComplete string
18 wantMatch []string // We check that at least these values are present in the output
19 wantNil bool
20 }{
21 {
22 name: "Empty input returns properties",
23 toComplete: "",
24 wantMatch: []string{".vmType=", ".arch="},
25 },
26 {
27 name: "Partial property filter",
28 toComplete: ".vm",
29 wantMatch: []string{".vmType=", ".vmOpts="},
30 },
31 {
32 name: "Exact property with equals returns all enum values",
33 toComplete: ".vmType=",
34 wantMatch: []string{".vmType=qemu", ".vmType=vz", ".vmType=wsl2"},
35 },
36 {
37 name: "Nested property filter",
38 toComplete: ".ssh.",
39 wantMatch: []string{".ssh.localPort=", ".ssh.forwardAgent="},
40 },
41 {
42 name: "Partial value filter",
43 toComplete: ".vmType=q",
44 wantMatch: []string{".vmType=qemu"},
45 },
46 {
47 name: "Unknown property after equals returns nil",
48 toComplete: ".unknown=",
49 wantNil: true,
50 },
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 got, _ := setFlagCompletion(&cobra.Command{}, nil, tt.toComplete)
56
57 if tt.wantNil {
58 assert.Assert(t, got == nil, "expected nil completions")
59 return
60 }
61
62 for _, want := range tt.wantMatch {
63 assert.Assert(t, slices.Contains(got, want), "expected to find %q in completions, but didn't. Got: %v", want, got)
64 }
65 })
66 }
67}