2021-07-23 19:59:33 -07:00
|
|
|
|
package terminal_utils_test
|
|
|
|
|
|
|
|
|
|
import (
|
2022-03-06 17:07:05 -08:00
|
|
|
|
"testing"
|
2021-07-23 19:59:33 -07:00
|
|
|
|
|
2022-03-06 17:07:05 -08:00
|
|
|
|
"reflect"
|
2021-07-23 19:59:33 -07:00
|
|
|
|
|
2023-07-30 14:19:07 -03:00
|
|
|
|
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/terminal_utils"
|
2022-03-06 17:07:05 -08:00
|
|
|
|
)
|
2021-07-23 19:59:33 -07:00
|
|
|
|
|
|
|
|
|
func TestWrapParagraph(t *testing.T) {
|
2022-03-06 17:07:05 -08:00
|
|
|
|
test_cases := []struct {
|
|
|
|
|
Text string
|
|
|
|
|
Expected []string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"These are public health officials who are making decisions about your lifestyle because they know more about health, " +
|
|
|
|
|
"fitness and well-being than you do",
|
|
|
|
|
[]string{
|
|
|
|
|
"These are public health officials who are making decisions",
|
|
|
|
|
"about your lifestyle because they know more about health,",
|
|
|
|
|
"fitness and well-being than you do",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
`Things I learned in law school:`,
|
|
|
|
|
[]string{`Things I learned in law school:`},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
`Every student is smarter than you except the ones in your group project.`,
|
|
|
|
|
[]string{
|
|
|
|
|
`Every student is smarter than you except the ones in your`,
|
|
|
|
|
`group project.`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, testcase := range test_cases {
|
|
|
|
|
result := terminal_utils.WrapParagraph(testcase.Text, 60)
|
|
|
|
|
if !reflect.DeepEqual(result, testcase.Expected) {
|
|
|
|
|
t.Errorf("Expected:\n%s\nGot:\n%s\n", testcase.Expected, result)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-23 19:59:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestWrapText(t *testing.T) {
|
2022-03-06 17:07:05 -08:00
|
|
|
|
test_cases := []struct {
|
|
|
|
|
Text string
|
|
|
|
|
Expected string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"These are public health officials who are making decisions about your lifestyle because they know more about health, " +
|
|
|
|
|
"fitness and well-being than you do",
|
|
|
|
|
`These are public health officials who are making decisions
|
2021-07-23 19:59:33 -07:00
|
|
|
|
about your lifestyle because they know more about health,
|
|
|
|
|
fitness and well-being than you do`,
|
2022-03-06 17:07:05 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
`Things I learned in law school:
|
2021-07-23 19:59:33 -07:00
|
|
|
|
Falling behind early gives you more time to catch up.
|
|
|
|
|
Never use a long word when a diminutive one will suffice.
|
|
|
|
|
Every student is smarter than you except the ones in your group project.
|
|
|
|
|
If you try & fail, doesn’t matter. Try again & fail better`,
|
2022-03-06 17:07:05 -08:00
|
|
|
|
`Things I learned in law school:
|
2021-07-23 19:59:33 -07:00
|
|
|
|
Falling behind early gives you more time to catch up.
|
|
|
|
|
Never use a long word when a diminutive one will suffice.
|
|
|
|
|
Every student is smarter than you except the ones in your
|
|
|
|
|
group project.
|
|
|
|
|
If you try & fail, doesn’t matter. Try again & fail better`,
|
2022-03-06 17:07:05 -08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, testcase := range test_cases {
|
|
|
|
|
result := terminal_utils.WrapText(testcase.Text, 60)
|
|
|
|
|
if result != testcase.Expected {
|
|
|
|
|
t.Errorf("Expected:\n%s\nGot:\n%s\n", testcase.Expected, result)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-23 19:59:33 -07:00
|
|
|
|
}
|