MCPcopy Create free account
hub / github.com/docker/docker-language-server / TestFormattingCustom

Function TestFormattingCustom

internal/bake/hcl/formatting_test.go:501–533  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

499}
500
501func TestFormattingCustom(t *testing.T) {
502 testCases := []struct {
503 name string
504 content string
505 edits []protocol.TextEdit
506 }{
507 {
508 name: "handle whitespace after an args key's equals sign",
509 content: "target t {\n args = {\n var = value\n }\n}",
510 edits: []protocol.TextEdit{
511 {
512 NewText: " = ",
513 Range: protocol.Range{
514 Start: protocol.Position{Line: 2, Character: 7},
515 End: protocol.Position{Line: 2, Character: 12},
516 },
517 },
518 },
519 },
520 }
521
522 temporaryBakeFile := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "docker-bake.hcl")), "/"))
523 for _, tc := range testCases {
524 t.Run(tc.name, func(t *testing.T) {
525 doc := document.NewBakeHCLDocument(uri.URI(temporaryBakeFile), 1, []byte(tc.content))
526 edits, err := Formatting(doc, protocol.FormattingOptions{
527 protocol.FormattingOptionInsertSpaces: true, protocol.FormattingOptionTabSize: float64(2),
528 })
529 require.NoError(t, err)
530 require.Equal(t, tc.edits, edits)
531 })
532 }
533}
534
535func TestFormattingUnchanged(t *testing.T) {
536 testCases := []struct {

Callers

nothing calls this directly

Calls 3

NewBakeHCLDocumentFunction · 0.92
FormattingFunction · 0.70
URIMethod · 0.65

Tested by

no test coverage detected