2017-06-17 01:17:22 +02:00
|
|
|
package helpers
|
2017-06-11 22:00:03 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-06-16 22:47:49 +02:00
|
|
|
"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) {
|
2017-06-16 22:47:49 +02:00
|
|
|
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) {
|
2017-06-16 22:47:49 +02:00
|
|
|
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",
|
|
|
|
}
|
2017-06-16 22:47:49 +02:00
|
|
|
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
|
|
|
|
2017-06-16 22:47:49 +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}
|
2017-06-16 21:47:41 +02:00
|
|
|
actual := MergeVariableMaps(m1, m2)
|
2017-06-16 22:47:49 +02:00
|
|
|
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)
|
2017-06-16 22:47:49 +02:00
|
|
|
require.Equal(t, expected, actual)
|
2017-06-11 22:00:03 +02:00
|
|
|
}
|