offline-twitter/pkg/terminal_utils/formatting_test.go
2023-07-30 14:20:07 -03:00

78 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package terminal_utils_test
import (
"testing"
"reflect"
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/terminal_utils"
)
func TestWrapParagraph(t *testing.T) {
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)
}
}
}
func TestWrapText(t *testing.T) {
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
about your lifestyle because they know more about health,
fitness and well-being than you do`,
},
{
`Things I learned in law school:
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, doesnt matter. Try again & fail better`,
`Things I learned in law school:
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, doesnt matter. Try again & fail better`,
},
}
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)
}
}
}