Skip to content

Commit ef1dc0a

Browse files
committed
undent: last char was omitted when last line was "\n\t\t}"
Because of a mistake I made in the indexing, the "case 1" was only checking that all the remaining chars in the last line but the last char was made of indentation: in the example in the commit title, it was looking at "\t\t" rather than "\t\t}", thus wrongly going in the "case 1".
1 parent 70a84fa commit ef1dc0a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

pkg/testutil/undent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func Undent(s string) string {
122122

123123
// Case 1: we want the user to be able to omit some tabs or spaces in
124124
// the last line for readability purposes.
125-
case line == len(lineOffsets)-1 && s[last] != '\n' && isIndent(s[first:last]):
125+
case line == len(lineOffsets)-1 && s[last] != '\n' && isIndent(s[first:last+1]):
126126
lineStr = ""
127127

128128
// Case 2: we want the user to be able to omit the indentations for

pkg/testutil/undent_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func Test_Undent(t *testing.T) {
3434
3535
bar
3636
`, "foo\n\nbar\n"))
37+
t.Run("bug fix: last char is not omitted", runTest_Undent("\t\t{\n\t\t \"kind\": \"Secret\"\n\t\t}", "{\n \"kind\": \"Secret\"\n}"))
3738
}
3839

3940
func runTest_Undent(given, expected string) func(t *testing.T) {

0 commit comments

Comments
 (0)