-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add comment formatter and unit tests
- Loading branch information
1 parent
629aeea
commit f2b2019
Showing
2 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package buflsp | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_formatComment(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
input string | ||
expected string | ||
}{ | ||
{ | ||
name: "Single-line comment", | ||
input: "// This is a single-line comment", | ||
expected: " This is a single-line comment", | ||
}, | ||
{ | ||
name: "Multi-line comment", | ||
input: "/*\n * This is a\n * multi-line comment\n */", | ||
expected: "This is a\nmulti-line comment", | ||
}, | ||
{ | ||
name: "Multi-line comment with mixed indentation", | ||
input: "/*\n * First line\n * - Second line\n * - Third line\n */", | ||
expected: "First line\n- Second line\n - Third line", | ||
}, | ||
{ | ||
name: "Multi-line comment with multi-asterisks", | ||
input: "/*** This is a\n *** multi-line comment\n *** with multi-asterisks ***/", | ||
expected: "This is a\nmulti-line comment\nwith multi-asterisks", | ||
}, | ||
{ | ||
name: "Multi-line comment without asterisks", | ||
input: "/* This is a\n multi-line comment\n without asterisks */", | ||
expected: "This is a\nmulti-line comment\nwithout asterisks", | ||
}, | ||
{ | ||
name: "Single-line multi-line comment", | ||
input: "/* Single-line multi-line comment */", | ||
expected: "Single-line multi-line comment", | ||
}, | ||
{ | ||
name: "Empty comment", | ||
input: "/**/", | ||
expected: "", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
result := formatComment(tt.input) | ||
if result != tt.expected { | ||
assert.Equal(t, tt.input, result) | ||
} | ||
}) | ||
} | ||
} |