bou.ke/statictemplate@v0.0.0-20180821122055-510411a5e7dd/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"gopkg.in/stretchr/testify.v1/assert"
     5  	"testing"
     6  )
     7  
     8  func TestParseCompilationTargets(t *testing.T) {
     9  	var ct compilationTargets
    10  	assert.NoError(t, ct.Set("Hi:hi.tmpl:string"))
    11  	assert.NoError(t, ct.Set("Hello:hi.tmpl:*text/template.Template"))
    12  	assert.NoError(t, ct.Set("Cool:hi.tmpl:text/template.Template"))
    13  	assert.NoError(t, ct.Set("Neat:hi.tmpl:*bou.ke/whatever.Template"))
    14  	expected := compilationTargets{
    15  		compilationTarget{
    16  			functionName: "Hi",
    17  			templateName: "hi.tmpl",
    18  			dot: dotType{
    19  				packagePath: "",
    20  				typeName:    "string",
    21  				prefix:      "",
    22  			},
    23  		},
    24  		compilationTarget{
    25  			functionName: "Hello",
    26  			templateName: "hi.tmpl",
    27  			dot: dotType{
    28  				packagePath: "text/template",
    29  				typeName:    "Template",
    30  				prefix:      "*",
    31  			},
    32  		},
    33  		compilationTarget{
    34  			functionName: "Cool",
    35  			templateName: "hi.tmpl",
    36  			dot: dotType{
    37  				packagePath: "text/template",
    38  				typeName:    "Template",
    39  				prefix:      "",
    40  			},
    41  		},
    42  		compilationTarget{
    43  			functionName: "Neat",
    44  			templateName: "hi.tmpl",
    45  			dot: dotType{
    46  				packagePath: "bou.ke/whatever",
    47  				typeName:    "Template",
    48  				prefix:      "*",
    49  			},
    50  		},
    51  	}
    52  	assert.Equal(t, expected, ct)
    53  }
    54  
    55  func TestParseCompilationTargetsError(t *testing.T) {
    56  	var ct compilationTargets
    57  	assert.Error(t, ct.Set("lol whatever man"), `expect compilation target in functionName:templateName:typeName format, got "lol whatever man"`)
    58  }