1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 09:49:00 +01:00
gojekyll/helpers/string_test.go

56 lines
1.5 KiB
Go
Raw Normal View History

2017-06-17 01:17:22 +02:00
package helpers
2017-06-11 22:00:03 +02:00
import (
"testing"
"github.com/stretchr/testify/require"
2017-06-11 22:00:03 +02:00
)
2017-06-16 01:49:04 +02:00
func TestSlugify(t *testing.T) {
require.Equal(t, "abc", Slugify("abc"))
require.Equal(t, "ab-c", Slugify("ab.c"))
require.Equal(t, "ab-c", Slugify("ab-c"))
require.Equal(t, "ab-c", Slugify("ab()[]c"))
require.Equal(t, "ab123-cde-f-g", Slugify("ab123(cde)[]f.g"))
2017-06-16 01:49:04 +02:00
}
2017-06-11 22:00:03 +02:00
func TestLeftPad(t *testing.T) {
require.Equal(t, "abc", LeftPad("abc", 0))
require.Equal(t, "abc", LeftPad("abc", 3))
require.Equal(t, " abc", LeftPad("abc", 6))
2017-06-11 22:00:03 +02:00
}
func TestGetXXX(t *testing.T) {
2017-06-14 23:41:15 +02:00
d := VariableMap{
2017-06-11 22:00:03 +02:00
"t": true,
"f": false,
"s": "ss",
}
require.Equal(t, true, d.Bool("t", true))
require.Equal(t, true, d.Bool("t", false))
require.Equal(t, false, d.Bool("f", true))
require.Equal(t, false, d.Bool("f", true))
require.Equal(t, true, d.Bool("-", true))
require.Equal(t, false, d.Bool("-", false))
require.Equal(t, true, d.Bool("s", true))
require.Equal(t, false, d.Bool("s", false))
2017-06-14 23:41:15 +02:00
require.Equal(t, "ss", d.String("s", "-"))
require.Equal(t, "--", d.String("-", "--"))
require.Equal(t, "--", d.String("t", "--"))
2017-06-11 22:00:03 +02:00
}
2017-06-14 23:41:15 +02:00
func TestMergeVariableMaps(t *testing.T) {
m1 := VariableMap{"a": 1, "b": 2}
m2 := VariableMap{"b": 3, "c": 4}
expected := VariableMap{"a": 1, "b": 3, "c": 4}
actual := MergeVariableMaps(m1, m2)
require.Equal(t, expected, actual)
2017-06-11 22:00:03 +02:00
}
func TestStringArrayToMap(t *testing.T) {
input := []string{"a", "b", "c"}
expected := map[string]bool{"a": true, "b": true, "c": true}
actual := stringArrayToMap(input)
require.Equal(t, expected, actual)
2017-06-11 22:00:03 +02:00
}