test eq
This commit is contained in:
parent
f61dbe8bcd
commit
c5d2eb8d60
11
eq.go
11
eq.go
@ -22,6 +22,15 @@ func eq2(t1, t2 Tag) bool {
|
||||
}
|
||||
}
|
||||
|
||||
var rgq renderGuidesQuery
|
||||
t1(&rgq)
|
||||
trg1 := mergeRenderingGuides(rgq.value)
|
||||
t2(&rgq)
|
||||
trg2 := mergeRenderingGuides(rgq.value)
|
||||
if trg1 != trg2 {
|
||||
return false
|
||||
}
|
||||
|
||||
c1, c2 := Children(t1), Children(t2)
|
||||
if len(c1) != len(c2) {
|
||||
return false
|
||||
@ -38,7 +47,7 @@ func eq2(t1, t2 Tag) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !ok1 {
|
||||
if ok1 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
135
eq_test.go
Normal file
135
eq_test.go
Normal file
@ -0,0 +1,135 @@
|
||||
package html_test
|
||||
|
||||
import (
|
||||
"code.squareroundforest.org/arpio/html"
|
||||
. "code.squareroundforest.org/arpio/html/tag"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEq(t *testing.T) {
|
||||
t.Run("zero operands", func(t *testing.T) {
|
||||
if !html.Eq() {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("one operand", func(t *testing.T) {
|
||||
if !html.Eq(Div) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands eq", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
if !html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different name", func(t *testing.T) {
|
||||
div := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
custom := html.Define("custom")(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
if html.Eq(div, custom) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different number of attributes", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar"), "qux", "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different attributes", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 84), "qux", "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different attribute names", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz2", 42), "qux", "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different render guides", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := html.Inline(Div)(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands eq with merged render guides", func(t *testing.T) {
|
||||
script0 := html.Inline(Script(Attr("foo", "bar"), "let foo = bar"))
|
||||
script1 := html.ScriptContent(html.Inline(Define("script"))(Attr("foo", "bar"), "let foo = bar"))
|
||||
if !html.Eq(script0, script1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different number of children", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands different children", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux", "garply")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands child tags eq", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", Br, "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux", Br, "quux")
|
||||
if !html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands child tags not eq", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", Br, "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux", html.SetClass(Br, "foo"), "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("two operands child tags at different position", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", Br, "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), Br, "qux", "quux")
|
||||
if html.Eq(div0, div1) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multiple operands eq", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div2 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
if !html.Eq(div0, div1, div2) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multiple operands not eq", func(t *testing.T) {
|
||||
div0 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
div1 := Div(Attr("foo", "bar", "baz", 84), "qux", "quux")
|
||||
div2 := Div(Attr("foo", "bar", "baz", 42), "qux", "quux")
|
||||
if html.Eq(div0, div1, div2) {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user