-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfrontmatter_command_test.go
More file actions
162 lines (155 loc) · 3.91 KB
/
frontmatter_command_test.go
File metadata and controls
162 lines (155 loc) · 3.91 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package markdown
import (
"testing"
"gopkg.in/yaml.v3"
)
func TestCommandFrontMatter_Marshal(t *testing.T) {
tests := []struct {
name string
command CommandFrontMatter
want string
}{
{
name: "minimal command",
command: CommandFrontMatter{},
want: "{}\n",
},
{
name: "command with standard id, name, description",
command: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Standard Command",
Description: "This is a standard command with metadata",
},
},
want: "{}\n",
},
{
name: "command with expand false",
command: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "No Expand Command",
Description: "Command with expansion disabled",
},
ExpandParams: func() *bool {
b := false
return &b
}(),
},
want: "expand: false\n",
},
{
name: "command with selectors",
command: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Selector Command",
Description: "Command with selectors",
},
Selectors: map[string]any{
"database": "postgres",
"feature": "auth",
},
},
want: "selectors:\n database: postgres\n feature: auth\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := yaml.Marshal(&tt.command)
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
if string(got) != tt.want {
t.Errorf("Marshal() = %q, want %q", string(got), tt.want)
}
})
}
}
func TestCommandFrontMatter_Unmarshal(t *testing.T) {
tests := []struct {
name string
yaml string
want CommandFrontMatter
wantErr bool
}{
{
name: "command with standard id, name, description",
yaml: `id: urn:agents:command:named
name: Named Command
description: A command with standard fields
`,
want: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Named Command",
Description: "A command with standard fields",
Content: map[string]any{"id": "urn:agents:command:named"},
},
},
},
{
name: "command with expand false",
yaml: `id: urn:agents:command:no-expand
name: No Expand
description: No expansion
expand: false
`,
want: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "No Expand",
Description: "No expansion",
Content: map[string]any{"id": "urn:agents:command:no-expand"},
},
ExpandParams: nil,
},
},
{
name: "command with selectors",
yaml: `id: urn:agents:command:selector
name: Selector Command
description: Has selectors
selectors:
database: postgres
feature: auth
`,
want: CommandFrontMatter{
BaseFrontMatter: BaseFrontMatter{
Name: "Selector Command",
Description: "Has selectors",
Content: map[string]any{"id": "urn:agents:command:selector"},
},
Selectors: map[string]any{
"database": "postgres",
"feature": "auth",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got CommandFrontMatter
err := yaml.Unmarshal([]byte(tt.yaml), &got)
if (err != nil) != tt.wantErr {
t.Fatalf("Unmarshal() error = %v, wantErr %v", err, tt.wantErr)
}
if err != nil {
return
}
// Compare fields individually
if got.Name != tt.want.Name {
t.Errorf("Name = %q, want %q", got.Name, tt.want.Name)
}
if got.Description != tt.want.Description {
t.Errorf("Description = %q, want %q", got.Description, tt.want.Description)
}
if tt.want.ExpandParams != nil {
if (got.ExpandParams == nil) != (tt.want.ExpandParams == nil) {
t.Errorf("ExpandParams nil mismatch: got %v, want %v", got.ExpandParams == nil, tt.want.ExpandParams == nil)
} else if got.ExpandParams != nil && tt.want.ExpandParams != nil {
if *got.ExpandParams != *tt.want.ExpandParams {
t.Errorf("ExpandParams = %v, want %v", *got.ExpandParams, *tt.want.ExpandParams)
}
}
}
})
}
}