(t *testing.T)
| 499 | } |
| 500 | |
| 501 | func 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 | |
| 535 | func TestFormattingUnchanged(t *testing.T) { |
| 536 | testCases := []struct { |
nothing calls this directly
no test coverage detected