2021-12-19 13:08:09 -08:00
|
|
|
package funcmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-01 07:44:18 -08:00
|
|
|
"github.com/mikestefanello/pagoda/config"
|
2021-12-19 13:08:09 -08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHasField(t *testing.T) {
|
|
|
|
type example struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
var e example
|
|
|
|
assert.True(t, HasField(e, "name"))
|
|
|
|
assert.False(t, HasField(e, "abcd"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink(t *testing.T) {
|
|
|
|
link := string(Link("/abc", "Text", "/abc"))
|
|
|
|
expected := `<a class="is-active" href="/abc">Text</a>`
|
|
|
|
assert.Equal(t, expected, link)
|
|
|
|
|
|
|
|
link = string(Link("/abc", "Text", "/abc", "first", "second"))
|
|
|
|
expected = `<a class="first second is-active" href="/abc">Text</a>`
|
|
|
|
assert.Equal(t, expected, link)
|
|
|
|
|
|
|
|
link = string(Link("/abc", "Text", "/def"))
|
|
|
|
expected = `<a class="" href="/abc">Text</a>`
|
|
|
|
assert.Equal(t, expected, link)
|
|
|
|
}
|
|
|
|
|
2023-12-16 08:07:20 -08:00
|
|
|
func TestFile(t *testing.T) {
|
2021-12-19 13:08:09 -08:00
|
|
|
file := File("test.png")
|
|
|
|
expected := fmt.Sprintf("/%s/test.png?v=%s", config.StaticPrefix, CacheBuster)
|
|
|
|
assert.Equal(t, expected, file)
|
|
|
|
}
|