BenchmarkRemoveJavaScriptComments benchmarks the comment removal function
(b *testing.B)
| 671 | |
| 672 | // BenchmarkRemoveJavaScriptComments benchmarks the comment removal function |
| 673 | func BenchmarkRemoveJavaScriptComments(b *testing.B) { |
| 674 | testCases := []struct { |
| 675 | name string |
| 676 | input string |
| 677 | }{ |
| 678 | { |
| 679 | name: "simple code no comments", |
| 680 | input: "const x = 1;\nconst y = 2;\nconst z = 3;", |
| 681 | }, |
| 682 | { |
| 683 | name: "code with comments", |
| 684 | input: "// Comment\nconst x = 1; // inline\n/* block */ const y = 2;", |
| 685 | }, |
| 686 | { |
| 687 | name: "real world script", |
| 688 | input: `// @ts-check |
| 689 | /// <reference types="@actions/github-script" /> |
| 690 | |
| 691 | async function main() { |
| 692 | const { eventName } = context; |
| 693 | |
| 694 | // skip check for safe events |
| 695 | const safeEvents = ["workflow_dispatch", "schedule"]; |
| 696 | if (safeEvents.includes(eventName)) { |
| 697 | core.info('Event does not require validation'); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | /* Process the event */ |
| 702 | const actor = context.actor; |
| 703 | const { owner, repo } = context.repo; |
| 704 | |
| 705 | // Return result |
| 706 | return { actor, owner, repo }; |
| 707 | }`, |
| 708 | }, |
| 709 | } |
| 710 | |
| 711 | for _, tc := range testCases { |
| 712 | b.Run(tc.name, func(b *testing.B) { |
| 713 | for range b.N { |
| 714 | removeJavaScriptComments(tc.input) |
| 715 | } |
| 716 | }) |
| 717 | } |
| 718 | } |
nothing calls this directly
no test coverage detected