๐Ÿš€ 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.

refactor: Merge benchmarks into formatter_test.go

Fuwn e72abfc4 d7b0de9f

+44 -49
-49
formatter_bench_test.go
··· 1 - package main 2 - 3 - import ( 4 - "strings" 5 - "testing" 6 - ) 7 - 8 - func BenchmarkFormatSmall(b *testing.B) { 9 - inputSource := []byte(`package main 10 - func main() { 11 - x := 1 12 - y := 2 13 - if x > 0 { 14 - z := 3 15 - } 16 - a := 4 17 - } 18 - `) 19 - formatter := &Formatter{CommentMode: CommentsFollow} 20 - 21 - for b.Loop() { 22 - _, _ = formatter.Format(inputSource) 23 - } 24 - } 25 - 26 - func BenchmarkFormatLarge(b *testing.B) { 27 - var sourceBuilder strings.Builder 28 - 29 - sourceBuilder.WriteString("package main\n\n") 30 - 31 - for functionIndex := range 100 { 32 - sourceBuilder.WriteString("func foo") 33 - sourceBuilder.WriteString(string(rune('A' + functionIndex%26))) 34 - sourceBuilder.WriteString("() {\n") 35 - sourceBuilder.WriteString("\tx := 1\n") 36 - sourceBuilder.WriteString("\tif x > 0 {\n") 37 - sourceBuilder.WriteString("\t\ty := 2\n") 38 - sourceBuilder.WriteString("\t}\n") 39 - sourceBuilder.WriteString("\tz := 3\n") 40 - sourceBuilder.WriteString("}\n\n") 41 - } 42 - 43 - inputSource := []byte(sourceBuilder.String()) 44 - formatter := &Formatter{CommentMode: CommentsFollow} 45 - 46 - for b.Loop() { 47 - _, _ = formatter.Format(inputSource) 48 - } 49 - }
+44
formatter_test.go
··· 1 1 package main 2 2 3 3 import ( 4 + "strings" 4 5 "testing" 5 6 ) 6 7 ··· 422 423 t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) 423 424 } 424 425 } 426 + 427 + func BenchmarkFormatSmall(b *testing.B) { 428 + inputSource := []byte(`package main 429 + func main() { 430 + x := 1 431 + y := 2 432 + if x > 0 { 433 + z := 3 434 + } 435 + a := 4 436 + } 437 + `) 438 + formatter := &Formatter{CommentMode: CommentsFollow} 439 + 440 + for b.Loop() { 441 + _, _ = formatter.Format(inputSource) 442 + } 443 + } 444 + 445 + func BenchmarkFormatLarge(b *testing.B) { 446 + var sourceBuilder strings.Builder 447 + 448 + sourceBuilder.WriteString("package main\n\n") 449 + 450 + for functionIndex := range 100 { 451 + sourceBuilder.WriteString("func foo") 452 + sourceBuilder.WriteString(string(rune('A' + functionIndex%26))) 453 + sourceBuilder.WriteString("() {\n") 454 + sourceBuilder.WriteString("\tx := 1\n") 455 + sourceBuilder.WriteString("\tif x > 0 {\n") 456 + sourceBuilder.WriteString("\t\ty := 2\n") 457 + sourceBuilder.WriteString("\t}\n") 458 + sourceBuilder.WriteString("\tz := 3\n") 459 + sourceBuilder.WriteString("}\n\n") 460 + } 461 + 462 + inputSource := []byte(sourceBuilder.String()) 463 + formatter := &Formatter{CommentMode: CommentsFollow} 464 + 465 + for b.Loop() { 466 + _, _ = formatter.Format(inputSource) 467 + } 468 + }