github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/boilingcore/templates_test.go (about)

     1  package boilingcore
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  	"text/template"
     7  )
     8  
     9  func TestTemplateNameListSort(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	templs := templateNameList{
    13  		"bob.tpl",
    14  		"all.tpl",
    15  		"struct.tpl",
    16  		"ttt.tpl",
    17  	}
    18  
    19  	expected := []string{"bob.tpl", "all.tpl", "struct.tpl", "ttt.tpl"}
    20  
    21  	for i, v := range templs {
    22  		if v != expected[i] {
    23  			t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
    24  		}
    25  	}
    26  
    27  	expected = []string{"struct.tpl", "all.tpl", "bob.tpl", "ttt.tpl"}
    28  
    29  	sort.Sort(templs)
    30  
    31  	for i, v := range templs {
    32  		if v != expected[i] {
    33  			t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
    34  		}
    35  	}
    36  }
    37  
    38  func TestTemplateList_Templates(t *testing.T) {
    39  	t.Parallel()
    40  
    41  	tpl := template.New("")
    42  	tpl.New("wat.tpl").Parse("hello")
    43  	tpl.New("que.tpl").Parse("there")
    44  	tpl.New("not").Parse("hello")
    45  
    46  	tplList := templateList{tpl}
    47  	foundWat, foundQue, foundNot := false, false, false
    48  	for _, n := range tplList.Templates() {
    49  		switch n {
    50  		case "wat.tpl":
    51  			foundWat = true
    52  		case "que.tpl":
    53  			foundQue = true
    54  		case "not":
    55  			foundNot = true
    56  		}
    57  	}
    58  
    59  	if !foundWat {
    60  		t.Error("want wat")
    61  	}
    62  	if !foundQue {
    63  		t.Error("want que")
    64  	}
    65  	if foundNot {
    66  		t.Error("don't want not")
    67  	}
    68  }