Skip to content

Commit

Permalink
added some more test cases
Browse files Browse the repository at this point in the history
to test space preserving and HardWrap shortcut function
  • Loading branch information
treilik committed Sep 22, 2021
1 parent aad653e commit ef9f79a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 0 additions & 3 deletions wordwrap/wordwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ func (w *WordWrap) Write(b []byte) (int, error) {
// Close will finish the word-wrap operation. Always call it before trying to
// retrieve the final result.
func (w *WordWrap) Close() error {
if w.HardWrap && w.word.PrintableRuneWidth()+w.lineLen > w.Limit {
w.addNewLine()
}
if w.PreserveSpaces {
w.addSpace()
}
Expand Down
26 changes: 26 additions & 0 deletions wordwrap/wordwrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func TestHardWrap(t *testing.T) {
false,
"",
},
// If the text fits -> passing through
{
"test",
"test",
Expand All @@ -231,6 +232,7 @@ func TestHardWrap(t *testing.T) {
true,
"",
},
// If requested preserve spaces, no matter how much.
{
" ",
" \n \n \n \n \n \n \n \n \n ",
Expand All @@ -239,6 +241,15 @@ func TestHardWrap(t *testing.T) {
true,
"",
},
// If requested preserve spaces, no matter how much and wrap them accordingly
{
" ",
" \n \n \n \n \n \n \n \n \n \n ",
4,
true,
true,
"",
},
}
for i, tc := range tt {
f := NewWriter(tc.Limit)
Expand All @@ -257,3 +268,18 @@ func TestHardWrap(t *testing.T) {
}
}
}

func TestHardWrapShort(t *testing.T) {
testCase := "\x1B[38;2;249;38;114m(\x1B[0m\x1B[38;2;248;248;242mjust an\nother test\x1B[38;2;249;38;114m)\x1B[0m"
expected := `(ju
st
an
oth
er
tes
t)`
out := HardWrap(testCase, 3, " ")
if out != expected {
t.Errorf("From input expected:\n\n`%s`\n\nActual Output:\n\n`%s`", expected, out)
}
}

0 comments on commit ef9f79a

Please sign in to comment.