MCPcopy Index your code
hub / github.com/github/gh-aw / TestRemoveJavaScriptCommentsEdgeCases

Function TestRemoveJavaScriptCommentsEdgeCases

pkg/workflow/js_comments_test.go:622–670  ·  view source on GitHub ↗

TestRemoveJavaScriptCommentsEdgeCases tests additional edge cases

(t *testing.T)

Source from the content-addressed store, hash-verified

620
621// TestRemoveJavaScriptCommentsEdgeCases tests additional edge cases
622func TestRemoveJavaScriptCommentsEdgeCases(t *testing.T) {
623 t.Run("very long line with comment", func(t *testing.T) {
624 longLine := strings.Repeat("x", 10000) + " // comment"
625 result := removeJavaScriptComments(longLine)
626 expected := strings.Repeat("x", 10000) + " "
627 if result != expected {
628 t.Errorf("Failed to handle long line")
629 }
630 })
631
632 t.Run("many consecutive comments", func(t *testing.T) {
633 input := strings.Repeat("// comment\n", 100)
634 result := removeJavaScriptComments(input)
635 // Each comment line leaves an empty line (100 lines, each becoming empty)
636 // The function doesn't trim trailing newlines from repeated inputs
637 expected := strings.Repeat("\n", 100)
638 if len(result) != len(expected) {
639 t.Errorf("Failed to handle many consecutive comments: got %d chars, expected %d", len(result), len(expected))
640 }
641 })
642
643 t.Run("deeply nested strings and comments", func(t *testing.T) {
644 input := `const a = "/*"; const b = "*/"; // comment`
645 result := removeJavaScriptComments(input)
646 expected := `const a = "/*"; const b = "*/"; `
647 if result != expected {
648 t.Errorf("removeJavaScriptComments() = %q, expected %q", result, expected)
649 }
650 })
651
652 t.Run("multiple block comments on same line", func(t *testing.T) {
653 input := "/* c1 */ a /* c2 */ b /* c3 */"
654 result := removeJavaScriptComments(input)
655 expected := " a b "
656 if result != expected {
657 t.Errorf("removeJavaScriptComments() = %q, expected %q", result, expected)
658 }
659 })
660
661 t.Run("block comment across many lines", func(t *testing.T) {
662 input := "start /* comment\nline 2\nline 3\nline 4\nline 5 */ end"
663 result := removeJavaScriptComments(input)
664 // Block comments preserve line structure
665 expected := "start \n\n\n\n end"
666 if result != expected {
667 t.Errorf("removeJavaScriptComments() = %q, expected %q", result, expected)
668 }
669 })
670}
671
672// BenchmarkRemoveJavaScriptComments benchmarks the comment removal function
673func BenchmarkRemoveJavaScriptComments(b *testing.B) {

Callers

nothing calls this directly

Calls 3

removeJavaScriptCommentsFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected