2017-06-11 22:00:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-06-16 01:49:04 +02:00
|
|
|
func TestSlugify(t *testing.T) {
|
|
|
|
assert.Equal(t, "abc", Slugify("abc"))
|
|
|
|
assert.Equal(t, "ab-c", Slugify("ab.c"))
|
|
|
|
assert.Equal(t, "ab-c", Slugify("ab-c"))
|
|
|
|
assert.Equal(t, "ab-c", Slugify("ab()[]c"))
|
|
|
|
assert.Equal(t, "ab123-cde-f-g", Slugify("ab123(cde)[]f.g"))
|
|
|
|
}
|
2017-06-11 22:00:03 +02:00
|
|
|
func TestLeftPad(t *testing.T) {
|
2017-06-13 23:19:05 +02:00
|
|
|
assert.Equal(t, "abc", LeftPad("abc", 0))
|
|
|
|
assert.Equal(t, "abc", LeftPad("abc", 3))
|
|
|
|
assert.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-14 23:41:15 +02:00
|
|
|
assert.Equal(t, true, d.Bool("t", true))
|
|
|
|
assert.Equal(t, true, d.Bool("t", false))
|
|
|
|
assert.Equal(t, false, d.Bool("f", true))
|
|
|
|
assert.Equal(t, false, d.Bool("f", true))
|
|
|
|
assert.Equal(t, true, d.Bool("-", true))
|
|
|
|
assert.Equal(t, false, d.Bool("-", false))
|
|
|
|
assert.Equal(t, true, d.Bool("s", true))
|
|
|
|
assert.Equal(t, false, d.Bool("s", false))
|
|
|
|
|
|
|
|
assert.Equal(t, "ss", d.String("s", "-"))
|
|
|
|
assert.Equal(t, "--", d.String("-", "--"))
|
|
|
|
assert.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-11 22:00:03 +02:00
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStringArrayToMap(t *testing.T) {
|
|
|
|
input := []string{"a", "b", "c"}
|
|
|
|
expected := map[string]bool{"a": true, "b": true, "c": true}
|
|
|
|
actual := stringArrayToMap(input)
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|