Skip to content

Commit

Permalink
Cleaned up based on gofmt and ineffassign results
Browse files Browse the repository at this point in the history
  • Loading branch information
bmdelacruz committed Sep 9, 2018
1 parent fcc128e commit 2fb2212
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
40 changes: 20 additions & 20 deletions node_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestNodeExtension_Conditional(t *testing.T) {

// test if-only conditional element
h1Node := tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "go-if", Val: "shouldRender"},
{Key: "go-if", Val: "shouldRender"},
}, false)
tplinator.ConditionalExtensionNodeProcessor(h1Node)

Expand All @@ -32,35 +32,35 @@ func TestNodeExtension_Conditional(t *testing.T) {
t.Errorf("shouldRender is false but finalH1Node is not nil")
}
delete(params, "shouldRender")
finalH1Node, _, err = h1Node.ApplyExtensions(extdep, params)
_, _, err = h1Node.ApplyExtensions(extdep, params)
if err == nil {
t.Errorf("expecting an error")
}

h1Node = tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "go-if", Val: "shouldRende]r"},
{Key: "go-if", Val: "shouldRende]r"},
}, false)
tplinator.ConditionalExtensionNodeProcessor(h1Node)

params["shouldRender"] = false
finalH1Node, _, err = h1Node.ApplyExtensions(extdep, params)
_, _, err = h1Node.ApplyExtensions(extdep, params)
if err == nil {
t.Errorf("expecting an error")
}

// test branching conditional elements
divNode := tplinator.CreateNode(html.ElementNode, "div", nil, false)
h1Node = tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "go-if", Val: "hasOne"},
{Key: "go-if", Val: "hasOne"},
}, false)
h2Node := tplinator.CreateNode(html.ElementNode, "h2", []html.Attribute{
html.Attribute{Key: "go-elif", Val: "hasTwo"},
{Key: "go-elif", Val: "hasTwo"},
}, false)
h3Node := tplinator.CreateNode(html.ElementNode, "h3", []html.Attribute{
html.Attribute{Key: "go-else-if", Val: "hasThree"},
{Key: "go-else-if", Val: "hasThree"},
}, false)
h4Node := tplinator.CreateNode(html.ElementNode, "h4", []html.Attribute{
html.Attribute{Key: "go-else", Val: ""},
{Key: "go-else", Val: ""},
}, false)

divNode.AppendChild(h1Node)
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestNodeExtension_Conditional(t *testing.T) {
// test absent else-if and else branch conditional elements
divNode = tplinator.CreateNode(html.ElementNode, "div", nil, false)
h1Node = tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "go-if", Val: "hasOne"},
{Key: "go-if", Val: "hasOne"},
}, false)
h2Node = tplinator.CreateNode(html.ElementNode, "h2", nil, false)

Expand All @@ -122,7 +122,7 @@ func TestNodeExtension_ConditionalClass(t *testing.T) {
params := make(map[string]interface{})

divNode := tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-if-class-animal", Val: "isAnAnimal"},
{Key: "go-if-class-animal", Val: "isAnAnimal"},
}, false)
tplinator.ConditionalClassExtensionNodeProcessor(divNode)

Expand Down Expand Up @@ -161,7 +161,7 @@ func TestNodeExtension_ConditionalClass(t *testing.T) {
}

divNode = tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-if-class-animal", Val: "isAnAnima]l"},
{Key: "go-if-class-animal", Val: "isAnAnima]l"},
}, false)
tplinator.ConditionalClassExtensionNodeProcessor(divNode)

Expand All @@ -172,8 +172,8 @@ func TestNodeExtension_ConditionalClass(t *testing.T) {
}

divNode = tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "class", Val: "photo-entry"},
html.Attribute{Key: "go-if-class-animal", Val: "isAnAnimal"},
{Key: "class", Val: "photo-entry"},
{Key: "go-if-class-animal", Val: "isAnAnimal"},
}, false)
tplinator.ConditionalClassExtensionNodeProcessor(divNode)

Expand Down Expand Up @@ -213,7 +213,7 @@ func TestNodeExtension_Range(t *testing.T) {
params := make(map[string]interface{})

divNode := tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-range", Val: "pets"},
{Key: "go-range", Val: "pets"},
}, false)
tplinator.RangeExtensionNodeProcessor(divNode)

Expand All @@ -237,7 +237,7 @@ func TestNodeExtension_Range(t *testing.T) {
}

divNode = tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-range", Val: "pets"},
{Key: "go-range", Val: "pets"},
}, false)
tplinator.RangeExtensionNodeProcessor(divNode)

Expand All @@ -251,7 +251,7 @@ func TestNodeExtension_Range(t *testing.T) {
}

divNode = tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-range", Val: "pet]s"},
{Key: "go-range", Val: "pet]s"},
}, false)
tplinator.RangeExtensionNodeProcessor(divNode)

Expand All @@ -271,8 +271,8 @@ func TestNodeExtension_Range(t *testing.T) {
}

divNode = tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "go-range", Val: "pets"},
html.Attribute{Key: "value", Val: "{{go:name}}"},
{Key: "go-range", Val: "pets"},
{Key: "value", Val: "{{go:name}}"},
}, false)

tplinator.RangeExtensionNodeProcessor(divNode)
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestNodeExtension_StringInterpolation(t *testing.T) {
}

aNode := tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "href", Val: "/users/{{go:uid}}"},
{Key: "href", Val: "/users/{{go:uid}}"},
}, false)
tplinator.StringInterpolationNodeProcessor(aNode)

Expand All @@ -349,7 +349,7 @@ func TestNodeExtension_StringInterpolation(t *testing.T) {
}

aNode = tplinator.CreateNode(html.ElementNode, "h1", []html.Attribute{
html.Attribute{Key: "href", Val: "/users/{{go:uid}}"},
{Key: "href", Val: "/users/{{go:uid}}"},
}, false)
aNode.SetContextParams(tplinator.EvaluatorParams{
"uid": "41728897352322",
Expand Down
32 changes: 16 additions & 16 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestCreateNode(t *testing.T) {

func TestCopyNode(t *testing.T) {
divNode := tplinator.CreateNode(html.ElementNode, "div", []html.Attribute{
html.Attribute{Key: "class", Val: "animals"},
html.Attribute{Key: "go-if", Val: "hasAnimals"},
{Key: "class", Val: "animals"},
{Key: "go-if", Val: "hasAnimals"},
}, false)
divNodeCopy := tplinator.CopyNode(divNode)

Expand Down Expand Up @@ -356,15 +356,15 @@ func TestNode_NextSiblingsBreak(t *testing.T) {

func TestNode_Attributes(t *testing.T) {
node := tplinator.CreateNode(html.ElementNode, "img", []html.Attribute{
html.Attribute{Key: "src", Val: "/static/images/cat.png"},
html.Attribute{Key: "class", Val: "pictures animal"},
html.Attribute{Key: "hidden", Val: ""},
{Key: "src", Val: "/static/images/cat.png"},
{Key: "class", Val: "pictures animal"},
{Key: "hidden", Val: ""},
}, true)

attributes := []tplinator.Attribute{
tplinator.Attribute{Key: "src", Value: "/static/images/cat.png"},
tplinator.Attribute{Key: "class", Value: "pictures animal"},
tplinator.Attribute{Key: "hidden", Value: "", KeyOnly: true},
{Key: "src", Value: "/static/images/cat.png"},
{Key: "class", Value: "pictures animal"},
{Key: "hidden", Value: "", KeyOnly: true},
}
actualAttributes := node.Attributes()

Expand Down Expand Up @@ -413,7 +413,7 @@ func TestNode_HasAttribute(t *testing.T) {
}

node := tplinator.CreateNode(html.ElementNode, "img", []html.Attribute{
html.Attribute{Key: "src", Val: "/static/images/cat.png"},
{Key: "src", Val: "/static/images/cat.png"},
}, true)

for _, tc := range testCases {
Expand Down Expand Up @@ -446,10 +446,10 @@ func TestNode_HasAttributes(t *testing.T) {

nodeMaker: func() *tplinator.Node {
return tplinator.CreateNode(html.ElementNode, "img", []html.Attribute{
html.Attribute{Key: "id", Val: "#animal002"},
html.Attribute{Key: "src", Val: "/static/images/cat.png"},
html.Attribute{Key: "go-if", Val: "hasImage"},
html.Attribute{Key: "go-if-class-cat", Val: "isCat"},
{Key: "id", Val: "#animal002"},
{Key: "src", Val: "/static/images/cat.png"},
{Key: "go-if", Val: "hasImage"},
{Key: "go-if-class-cat", Val: "isCat"},
}, true)
},
testFunc: func(attr tplinator.Attribute) bool {
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestNode_AddAttribute(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
node := tplinator.CreateNode(html.ElementNode, "img", []html.Attribute{
html.Attribute{Key: "src", Val: "/static/images/cat.png"},
{Key: "src", Val: "/static/images/cat.png"},
}, true)

tc.modifyNodeFunc(node)
Expand Down Expand Up @@ -603,8 +603,8 @@ func TestNode_RemoveAttribute(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
node := tplinator.CreateNode(html.ElementNode, "img", []html.Attribute{
html.Attribute{Key: "src", Val: "/static/images/cat.png"},
html.Attribute{Key: "class", Val: "pictures animal"},
{Key: "src", Val: "/static/images/cat.png"},
{Key: "class", Val: "pictures animal"},
}, true)

tc.modifyNodeFunc(node)
Expand Down

0 comments on commit 2fb2212

Please sign in to comment.