MCPcopy
hub / github.com/cli/cli / TestSerialize

Function TestSerialize

internal/skills/frontmatter/frontmatter_test.go:207–255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func TestSerialize(t *testing.T) {
208 tests := []struct {
209 name string
210 frontmatter map[string]interface{}
211 body string
212 wantPrefix string
213 wantSuffix string
214 wantContains []string
215 }{
216 {
217 name: "with body",
218 frontmatter: map[string]interface{}{"name": "test"},
219 body: "# Body content",
220 wantPrefix: "---\n",
221 wantContains: []string{
222 "name: test",
223 "# Body content",
224 },
225 },
226 {
227 name: "empty body",
228 frontmatter: map[string]interface{}{"name": "test"},
229 body: "",
230 wantSuffix: "---\n",
231 },
232 {
233 name: "body without trailing newline gets one added",
234 frontmatter: map[string]interface{}{"name": "test"},
235 body: "# No trailing newline",
236 wantSuffix: "# No trailing newline\n",
237 },
238 }
239
240 for _, tt := range tests {
241 t.Run(tt.name, func(t *testing.T) {
242 got, err := Serialize(tt.frontmatter, tt.body)
243 require.NoError(t, err)
244 if tt.wantPrefix != "" {
245 assert.True(t, strings.HasPrefix(got, tt.wantPrefix))
246 }
247 if tt.wantSuffix != "" {
248 assert.True(t, strings.HasSuffix(got, tt.wantSuffix))
249 }
250 for _, s := range tt.wantContains {
251 assert.Contains(t, got, s)
252 }
253 })
254 }
255}

Callers

nothing calls this directly

Calls 3

SerializeFunction · 0.85
ContainsMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected