cbcd945251
* preview of work so far * stylistic improvements * fix linters * remove golden tests, they may cause the system to be too rigid to changes * remove unnecessary code for golden tests * remove white space mangling in Execute * also handle output data, improve API, examples and docs * add helper methods * fix interface
29 lines
469 B
Go
29 lines
469 B
Go
package sqltemplate
|
|
|
|
import (
|
|
"testing"
|
|
"text/template"
|
|
)
|
|
|
|
func TestExecute(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tmpl := template.Must(template.New("test").Parse(`{{ .ID }}`))
|
|
|
|
data := struct {
|
|
ID int
|
|
}{
|
|
ID: 1,
|
|
}
|
|
|
|
txt, err := Execute(tmpl, data)
|
|
if txt != "1" || err != nil {
|
|
t.Fatalf("unexpected error, txt: %q, err: %v", txt, err)
|
|
}
|
|
|
|
txt, err = Execute(tmpl, 1)
|
|
if txt != "" || err == nil {
|
|
t.Fatalf("unexpected result, txt: %q, err: %v", txt, err)
|
|
}
|
|
}
|