diff options
author | Daniel Baumann <daniel@debian.org> | 2025-01-24 09:00:09 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2025-01-24 09:00:09 +0100 |
commit | 4bf4dabd48aa70da3699b9a023f22689645d24f4 (patch) | |
tree | ed8175444649e71c0ed0e5f1d30101786ca2473e /pkg/common/line_writer_test.go | |
parent | Initial commit. (diff) | |
download | forgejo-act-debian.tar.xz forgejo-act-debian.zip |
Adding upstream version 1.24.0.HEADupstream/1.24.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'pkg/common/line_writer_test.go')
-rw-r--r-- | pkg/common/line_writer_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/common/line_writer_test.go b/pkg/common/line_writer_test.go new file mode 100644 index 0000000..44e11ef --- /dev/null +++ b/pkg/common/line_writer_test.go @@ -0,0 +1,37 @@ +package common + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLineWriter(t *testing.T) { + lines := make([]string, 0) + lineHandler := func(s string) bool { + lines = append(lines, s) + return true + } + + lineWriter := NewLineWriter(lineHandler) + + assert := assert.New(t) + write := func(s string) { + n, err := lineWriter.Write([]byte(s)) + assert.NoError(err) + assert.Equal(len(s), n, s) + } + + write("hello") + write(" ") + write("world!!\nextra") + write(" line\n and another\nlast") + write(" line\n") + write("no newline here...") + + assert.Len(lines, 4) + assert.Equal("hello world!!\n", lines[0]) + assert.Equal("extra line\n", lines[1]) + assert.Equal(" and another\n", lines[2]) + assert.Equal("last line\n", lines[3]) +} |