1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00
lazygit/pkg/utils/utils_test.go

90 lines
1.2 KiB
Go
Raw Normal View History

package utils
2018-08-19 08:51:37 +02:00
import (
"testing"
"github.com/stretchr/testify/assert"
)
2018-11-30 02:47:14 +02:00
// TestMin is a function.
2018-09-19 11:31:29 +02:00
func TestMin(t *testing.T) {
type scenario struct {
a int
b int
expected int
}
scenarios := []scenario{
{
1,
1,
1,
},
{
1,
2,
1,
},
{
2,
1,
1,
},
}
for _, s := range scenarios {
assert.EqualValues(t, s.expected, Min(s.a, s.b))
}
}
2018-12-07 09:52:31 +02:00
func TestAsJson(t *testing.T) {
type myStruct struct {
a string
}
output := AsJson(&myStruct{a: "foo"})
// no idea why this is returning empty hashes but it's works in the app ¯\_(ツ)_/¯
assert.EqualValues(t, "{}", output)
}
2021-06-05 08:39:59 +02:00
func TestSafeTruncate(t *testing.T) {
type scenario struct {
str string
limit int
expected string
}
scenarios := []scenario{
{
str: "",
limit: 0,
expected: "",
},
{
str: "12345",
limit: 3,
expected: "123",
},
{
str: "12345",
limit: 4,
expected: "1234",
},
{
str: "12345",
limit: 5,
expected: "12345",
},
{
str: "12345",
limit: 6,
expected: "12345",
},
}
for _, s := range scenarios {
assert.EqualValues(t, s.expected, SafeTruncate(s.str, s.limit))
}
}