diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-15 23:59:38 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-15 23:59:38 +0100 |
commit | 9d927b399e409990003b25efa8ca7395e9cad021 (patch) | |
tree | 62647e87c23536c68bc4ecb8fdbeb5d6c8ab3086 /pkg/util/fixWriter_test.go | |
parent | 0aa048e3032f963335670fc882a4f97e3c00ee8d (diff) | |
download | feed2imap-go-9d927b399e409990003b25efa8ca7395e9cad021.tar.gz feed2imap-go-9d927b399e409990003b25efa8ca7395e9cad021.tar.bz2 feed2imap-go-9d927b399e409990003b25efa8ca7395e9cad021.zip |
Issue #46: Improvements; add tests
Diffstat (limited to 'pkg/util/fixWriter_test.go')
-rw-r--r-- | pkg/util/fixWriter_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/util/fixWriter_test.go b/pkg/util/fixWriter_test.go new file mode 100644 index 0000000..91961be --- /dev/null +++ b/pkg/util/fixWriter_test.go @@ -0,0 +1,47 @@ +package util + +import ( + "bytes" + "io" + "testing" +) + +func TestFixWriter_Write(t *testing.T) { + tests := []struct { + before string + after string + }{ + {"", ""}, + {"foo", "foo"}, + {"foo\r", "foo\r\n"}, + {"foo\n", "foo\r\n"}, + {"foo\r\n", "foo\r\n"}, + {"\r", "\r\n"}, + {"\n", "\r\n"}, + {"\r\n", "\r\n"}, + {"foo\rbar", "foo\r\nbar"}, + {"foo\nbar", "foo\r\nbar"}, + {"foo\r\nbar", "foo\r\nbar"}, + {"\r\r", "\r\n\r\n"}, + {"\n\n", "\r\n\r\n"}, + {"\r\r\n", "\r\n\r\n"}, + {"\n\r", "\r\n\r\n"}, + {"\rbar", "\r\nbar"}, + {"\nbar", "\r\nbar"}, + {"\r\nbar", "\r\nbar"}, + } + for _, tt := range tests { + t.Run(tt.before, func(t *testing.T) { + b := bytes.Buffer{} + w := FixWriter(&b) + if _, err := io.WriteString(w, tt.before); err != nil { + t.Errorf("Error: %v", err) + return + } + res := b.String() + if tt.after != res { + t.Errorf("Expected: %q, got: %q", tt.after, res) + } + }) + } +} |