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 Nov 1, 2020
1 parent 7457b5f commit aca706d
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 @@ -215,9 +215,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 TestHarWrapShort(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 aca706d

Please sign in to comment.