@@ -71,10 +71,12 @@ func TestTrimConsecutiveNewlines(t *testing.T) {
71
71
72
72
for _ , tt := range tests {
73
73
t .Run (tt .name , func (t * testing.T ) {
74
- got := string (TrimConsecutiveNewlines ([]byte (tt .input )))
75
- if got != tt .expected {
74
+ output := TrimConsecutiveNewlines ([]byte (tt .input ))
75
+ output = TrimUnnecessaryHardLineBreaks (output )
76
+
77
+ if string (output ) != tt .expected {
76
78
t .Errorf ("\n input: %q\n expected: %q\n got: %q" ,
77
- tt .input , tt .expected , got ,
79
+ tt .input , tt .expected , string ( output ) ,
78
80
)
79
81
}
80
82
})
@@ -85,7 +87,7 @@ func TestTrimConsecutiveNewlines_Allocs(t *testing.T) {
85
87
const N = 1000
86
88
87
89
t .Run ("no newlines" , func (t * testing.T ) {
88
- var expectedAverage float64 = 4
90
+ var expectedAverage float64 = 1
89
91
90
92
actualAverage := testing .AllocsPerRun (N , func () {
91
93
input := []byte ("abc" )
@@ -97,7 +99,7 @@ func TestTrimConsecutiveNewlines_Allocs(t *testing.T) {
97
99
}
98
100
})
99
101
t .Run ("exactly two newlines" , func (t * testing.T ) {
100
- var expectedAverage float64 = 4
102
+ var expectedAverage float64 = 1
101
103
102
104
actualAverage := testing .AllocsPerRun (N , func () {
103
105
input := []byte ("abc\n \n abc" )
@@ -109,7 +111,7 @@ func TestTrimConsecutiveNewlines_Allocs(t *testing.T) {
109
111
}
110
112
})
111
113
t .Run ("three newlines" , func (t * testing.T ) {
112
- var expectedAverage float64 = 4
114
+ var expectedAverage float64 = 1
113
115
114
116
actualAverage := testing .AllocsPerRun (N , func () {
115
117
input := []byte ("abc\n \n \n abc" )
@@ -121,7 +123,7 @@ func TestTrimConsecutiveNewlines_Allocs(t *testing.T) {
121
123
}
122
124
})
123
125
t .Run ("many newlines" , func (t * testing.T ) {
124
- var expectedAverage float64 = 19
126
+ var expectedAverage float64 = 16
125
127
126
128
actualAverage := testing .AllocsPerRun (N , func () {
127
129
input := bytes .Repeat ([]byte ("abc\n \n \n \n \n \n abc" ), 1000 )
0 commit comments