Browse Source

Add tests for EllipsisString() and fix bug if param length < 3

tags/v1.0.0
Matthias Loibl 7 years ago
parent
commit
030ba2894f
No account linked to committer's email address
2 changed files with 16 additions and 5 deletions
  1. 4
    1
      modules/base/tool.go
  2. 12
    4
      modules/base/tool_test.go

+ 4
- 1
modules/base/tool.go View File

// EllipsisString returns a truncated short string, // EllipsisString returns a truncated short string,
// it appends '...' in the end of the length of string is too large. // it appends '...' in the end of the length of string is too large.
func EllipsisString(str string, length int) string { func EllipsisString(str string, length int) string {
if len(str) < length {
if length <= 3 {
return "..."
}
if len(str) <= length {
return str return str
} }
return str[:length-3] + "..." return str[:length-3] + "..."

+ 12
- 4
modules/base/tool_test.go View File

) )
} }


// TODO: AvatarLink()
// TODO: computeTimeDiff() // TODO: computeTimeDiff()
// TODO: TimeSincePro() // TODO: TimeSincePro()
// TODO: timeSince() // TODO: timeSince()
// TODO: RawTimeSince() // TODO: RawTimeSince()
// TODO: TimeSince() // TODO: TimeSince()
// TODO: logn()
// TODO: humanateBytes()


func TestFileSize(t *testing.T) { func TestFileSize(t *testing.T) {
var size int64 var size int64
} }


// TODO: Subtract() // TODO: Subtract()
// TODO: EllipsisString()

func TestEllipsisString(t *testing.T) {
assert.Equal(t, "...", EllipsisString("foobar", 0))
assert.Equal(t, "...", EllipsisString("foobar", 1))
assert.Equal(t, "...", EllipsisString("foobar", 2))
assert.Equal(t, "...", EllipsisString("foobar", 3))
assert.Equal(t, "f...", EllipsisString("foobar", 4))
assert.Equal(t, "fo...", EllipsisString("foobar", 5))
assert.Equal(t, "foobar", EllipsisString("foobar", 6))
assert.Equal(t, "foobar", EllipsisString("foobar", 10))
}

// TODO: TruncateString() // TODO: TruncateString()
// TODO: StringsToInt64s() // TODO: StringsToInt64s()
// TODO: Int64sToStrings() // TODO: Int64sToStrings()

Loading…
Cancel
Save