๐Ÿš€ Grammar-Aware Code Formatter: Structure through separation (supports Go, JavaScript, TypeScript, JSX, and TSX)
go formatter code-formatter javascript typescript jsx tsx
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

style: Use idiomatic Go test naming conventions

Fuwn d7b0de9f fa619e7b

+40 -40
+4 -4
formatter_bench_test.go
··· 5 5 "testing" 6 6 ) 7 7 8 - func BenchmarkFormat_Small(benchmarkRunner *testing.B) { 8 + func BenchmarkFormatSmall(b *testing.B) { 9 9 inputSource := []byte(`package main 10 10 func main() { 11 11 x := 1 ··· 18 18 `) 19 19 formatter := &Formatter{CommentMode: CommentsFollow} 20 20 21 - for benchmarkRunner.Loop() { 21 + for b.Loop() { 22 22 _, _ = formatter.Format(inputSource) 23 23 } 24 24 } 25 25 26 - func BenchmarkFormat_Large(benchmarkRunner *testing.B) { 26 + func BenchmarkFormatLarge(b *testing.B) { 27 27 var sourceBuilder strings.Builder 28 28 29 29 sourceBuilder.WriteString("package main\n\n") ··· 43 43 inputSource := []byte(sourceBuilder.String()) 44 44 formatter := &Formatter{CommentMode: CommentsFollow} 45 45 46 - for benchmarkRunner.Loop() { 46 + for b.Loop() { 47 47 _, _ = formatter.Format(inputSource) 48 48 } 49 49 }
+36 -36
formatter_test.go
··· 4 4 "testing" 5 5 ) 6 6 7 - func TestFormat_RemovesExtraBlankLines(testRunner *testing.T) { 7 + func TestFormatRemovesExtraBlankLines(t *testing.T) { 8 8 inputSource := `package main 9 9 10 10 func main() { ··· 25 25 formattedResult, err := formatter.Format([]byte(inputSource)) 26 26 27 27 if err != nil { 28 - testRunner.Fatalf("Format error: %v", err) 28 + t.Fatalf("Format error: %v", err) 29 29 } 30 30 31 31 if string(formattedResult) != expectedOutput { 32 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 32 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 33 33 } 34 34 } 35 35 36 - func TestFormat_AddsBlankLineAroundScopedStatements(testRunner *testing.T) { 36 + func TestFormatScopedStatements(t *testing.T) { 37 37 inputSource := `package main 38 38 39 39 func main() { ··· 60 60 formattedResult, err := formatter.Format([]byte(inputSource)) 61 61 62 62 if err != nil { 63 - testRunner.Fatalf("Format error: %v", err) 63 + t.Fatalf("Format error: %v", err) 64 64 } 65 65 66 66 if string(formattedResult) != expectedOutput { 67 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 67 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 68 68 } 69 69 } 70 70 71 - func TestFormat_NestedScopes(testRunner *testing.T) { 71 + func TestFormatNestedScopes(t *testing.T) { 72 72 inputSource := `package main 73 73 74 74 func main() { ··· 99 99 formattedResult, err := formatter.Format([]byte(inputSource)) 100 100 101 101 if err != nil { 102 - testRunner.Fatalf("Format error: %v", err) 102 + t.Fatalf("Format error: %v", err) 103 103 } 104 104 105 105 if string(formattedResult) != expectedOutput { 106 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 106 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 107 107 } 108 108 } 109 109 110 - func TestFormat_ForLoop(testRunner *testing.T) { 110 + func TestFormatForLoop(t *testing.T) { 111 111 inputSource := `package main 112 112 113 113 func main() { ··· 134 134 formattedResult, err := formatter.Format([]byte(inputSource)) 135 135 136 136 if err != nil { 137 - testRunner.Fatalf("Format error: %v", err) 137 + t.Fatalf("Format error: %v", err) 138 138 } 139 139 140 140 if string(formattedResult) != expectedOutput { 141 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 141 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 142 142 } 143 143 } 144 144 145 - func TestFormat_Switch(testRunner *testing.T) { 145 + func TestFormatSwitch(t *testing.T) { 146 146 inputSource := `package main 147 147 148 148 func main() { ··· 171 171 formattedResult, err := formatter.Format([]byte(inputSource)) 172 172 173 173 if err != nil { 174 - testRunner.Fatalf("Format error: %v", err) 174 + t.Fatalf("Format error: %v", err) 175 175 } 176 176 177 177 if string(formattedResult) != expectedOutput { 178 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 178 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 179 179 } 180 180 } 181 181 182 - func TestFormat_MultipleFunctions(testRunner *testing.T) { 182 + func TestFormatMultipleFunctions(t *testing.T) { 183 183 inputSource := `package main 184 184 185 185 func foo() { ··· 205 205 formattedResult, err := formatter.Format([]byte(inputSource)) 206 206 207 207 if err != nil { 208 - testRunner.Fatalf("Format error: %v", err) 208 + t.Fatalf("Format error: %v", err) 209 209 } 210 210 211 211 if string(formattedResult) != expectedOutput { 212 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 212 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 213 213 } 214 214 } 215 215 216 - func TestFormat_TypeStruct(testRunner *testing.T) { 216 + func TestFormatTypeStruct(t *testing.T) { 217 217 inputSource := `package main 218 218 219 219 type Foo struct { ··· 233 233 formattedResult, err := formatter.Format([]byte(inputSource)) 234 234 235 235 if err != nil { 236 - testRunner.Fatalf("Format error: %v", err) 236 + t.Fatalf("Format error: %v", err) 237 237 } 238 238 239 239 if string(formattedResult) != expectedOutput { 240 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 240 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 241 241 } 242 242 } 243 243 244 - func TestFormat_DifferentStatementTypes(testRunner *testing.T) { 244 + func TestFormatDifferentStatementTypes(t *testing.T) { 245 245 inputSource := `package main 246 246 247 247 func main() { ··· 274 274 formattedResult, err := formatter.Format([]byte(inputSource)) 275 275 276 276 if err != nil { 277 - testRunner.Fatalf("Format error: %v", err) 277 + t.Fatalf("Format error: %v", err) 278 278 } 279 279 280 280 if string(formattedResult) != expectedOutput { 281 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 281 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 282 282 } 283 283 } 284 284 285 - func TestFormat_ConsecutiveIfs(testRunner *testing.T) { 285 + func TestFormatConsecutiveIfs(t *testing.T) { 286 286 inputSource := `package main 287 287 288 288 func main() { ··· 310 310 formattedResult, err := formatter.Format([]byte(inputSource)) 311 311 312 312 if err != nil { 313 - testRunner.Fatalf("Format error: %v", err) 313 + t.Fatalf("Format error: %v", err) 314 314 } 315 315 316 316 if string(formattedResult) != expectedOutput { 317 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 317 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 318 318 } 319 319 } 320 320 321 - func TestFormat_CaseClauseStatements(testRunner *testing.T) { 321 + func TestFormatCaseClauseStatements(t *testing.T) { 322 322 inputSource := `package main 323 323 324 324 func main() { ··· 348 348 formattedResult, err := formatter.Format([]byte(inputSource)) 349 349 350 350 if err != nil { 351 - testRunner.Fatalf("Format error: %v", err) 351 + t.Fatalf("Format error: %v", err) 352 352 } 353 353 354 354 if string(formattedResult) != expectedOutput { 355 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 355 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 356 356 } 357 357 } 358 358 359 - func TestFormat_DeferWithInlineFunc(testRunner *testing.T) { 359 + func TestFormatDeferInlineFunc(t *testing.T) { 360 360 inputSource := `package main 361 361 362 362 func main() { ··· 376 376 formattedResult, err := formatter.Format([]byte(inputSource)) 377 377 378 378 if err != nil { 379 - testRunner.Fatalf("Format error: %v", err) 379 + t.Fatalf("Format error: %v", err) 380 380 } 381 381 382 382 if string(formattedResult) != expectedOutput { 383 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 383 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 384 384 } 385 385 } 386 386 387 - func TestFormat_CaseClauseConsecutiveAssignments(testRunner *testing.T) { 387 + func TestFormatCaseClauseAssignments(t *testing.T) { 388 388 inputSource := `package main 389 389 390 390 func main() { ··· 415 415 formattedResult, err := formatter.Format([]byte(inputSource)) 416 416 417 417 if err != nil { 418 - testRunner.Fatalf("Format error: %v", err) 418 + t.Fatalf("Format error: %v", err) 419 419 } 420 420 421 421 if string(formattedResult) != expectedOutput { 422 - testRunner.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 422 + t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 423 423 } 424 424 }