| 6 | ) |
| 7 | |
| 8 | func TestFormatterBasic(t *testing.T) { |
| 9 | tests := []struct { |
| 10 | name string |
| 11 | input string |
| 12 | want string |
| 13 | }{ |
| 14 | { |
| 15 | name: "simple_assignment", |
| 16 | input: `package main |
| 17 | let x=42`, |
| 18 | want: `package main |
| 19 | let x = 42 |
| 20 | `, |
| 21 | }, |
| 22 | { |
| 23 | name: "function_call", |
| 24 | input: `fmt.Println(x,y,z)`, |
| 25 | want: `fmt.Println(x, y, z) |
| 26 | `, |
| 27 | }, |
| 28 | { |
| 29 | name: "comment_preservation", |
| 30 | input: `// This is a comment |
| 31 | let x=42`, |
| 32 | want: `// This is a comment |
| 33 | let x = 42 |
| 34 | `, |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | f := New(DefaultConfig()) |
| 39 | |
| 40 | for _, tt := range tests { |
| 41 | t.Run(tt.name, func(t *testing.T) { |
| 42 | got, err := f.Format([]byte(tt.input)) |
| 43 | if err != nil { |
| 44 | t.Fatalf("Format() error = %v", err) |
| 45 | } |
| 46 | |
| 47 | gotStr := string(got) |
| 48 | if gotStr != tt.want { |
| 49 | t.Errorf("Format() mismatch:\nInput:\n%s\nGot:\n%s\nWant:\n%s", |
| 50 | tt.input, gotStr, tt.want) |
| 51 | } |
| 52 | }) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestMatchFormatting(t *testing.T) { |
| 57 | tests := []struct { |