-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build response string more efficiently
This is definitely a dumb premature optimization, but this does some basic string builder stuff so that we're not duplicating strings all willy nilly.
- Loading branch information
Showing
2 changed files
with
86 additions
and
10 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,33 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestStreamAndRemoveDoubleNewlines(t *testing.T) { | ||
inp := `Hello | ||
I am a string with | ||
some double newlines | ||
And a triple newline!` | ||
|
||
var buf bytes.Buffer | ||
if err := streamAndRemoveDoubleNewlines(inp, &buf); err != nil { | ||
t.Fatalf("streamAndRemoveDoubleNewlines: %v", err) | ||
} | ||
|
||
want := `Hello | ||
I am a string with | ||
some double newlines | ||
And a triple newline!` | ||
|
||
got := buf.String() | ||
|
||
if got != want { | ||
t.Errorf("unexpected output = %q, want %q", got, want) | ||
} | ||
} |