t.Errorf("Incorrect output, expecting \"%s\" but got \"%s\"",tc.ResultData,out)
}
ifidx!=tc.ResultIDX{
t.Errorf("Incorrect last index, expected \"%d\" but got \"%d\"",tc.ResultIDX,idx)
}
})
}
}
funcTestGetExcerpt(t*testing.T){
tt:=[]struct{
Namestring
Datastring
Resultstring
}{
{
"Shorter than one line",
"This is much less than 80 chars",
"This is much less than 80 chars",
},{
"Exact length, one line",
"This will be only 80 chars. Maybe all the way to column 88, that will do it. ---",
"This will be only 80 chars. Maybe all the way to column 88, that will do it. ---",
},{
"Shorter than two lines",
"This will be more than one line but shorter than two. It should break at the 80th or less character. Let's check it out.",
"This will be more than one line but shorter than two. It should break at the\n 80th or less character. Let's check it out.",
},{
"Exact length, two lines",
"This should be the exact length for two lines. There should ideally be no trailing periods to indicate further text. However trimToLength breaks on word bounds.",
"This should be the exact length for two lines. There should ideally be no\n trailing periods to indicate further text. However trimToLength breaks on word...",
},{
"Longer than two lines",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque volutpat sagittis aliquet. Ut eu rutrum nisl. Proin molestie ante in dui vulputate dictum. Proin ac bibendum eros. Nulla porta congue tellus, sed vehicula sem bibendum eu. Donec vehicula erat viverra fermentum mattis. Integer volutpat.",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque volutpat\n sagittis aliquet. Ut eu rutrum nisl. Proin molestie ante in dui vulputate...",
},
}
for_,tc:=rangett{
t.Run(tc.Name,func(t*testing.T){
out:=getExcerpt(tc.Data)
ifout!=tc.Result{
t.Errorf("Output does not match:\nexpected \"%s\"\nbut got \"%s\"",tc.Result,out)