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() } }) }