예제 #1
0
func TestMarkupReconciliation(t *testing.T) {
	div := elems.Div(
		elems.Span(elems.Text("30")),
		elems.Text("20"),
	)

	divCl := elems.Div(
		elems.Span(elems.Text("30")),
		elems.Text("20"),
		elems.Text("400"),
	)

	//lets remove the span with its text child and the parents text child
	trees.ElementsWithTag(trees.ElementsWithTag(divCl, "span")[0], "text")[0].Remove()
	trees.ElementsWithTag(divCl, "text")[0].Remove()
	divCl.CleanRemoved()

	printer := trees.NewElementWriter(trees.SimpleAttrWriter, trees.SimpleStyleWriter, trees.SimpleTextWriter)
	printer.AllowRemoved()

	nrender := printer.Print(div)
	crender := printer.Print(divCl)

	if !strings.Contains(nrender, ">20") && !strings.Contains(nrender, ">30") {
		tests.FatalFailed(t, "Inaccurate rendering occured, has no '>20' or '>30' set", nrender)
	}

	if strings.Contains(crender, ">20") && strings.Contains(crender, ">30") {
		tests.FatalFailed(t, "Inaccurate rendering occured, has '>20' or '>30' and  set", crender)
	}

	//reconcile with the original div
	divCl.Reconcile(div)

	rcrender := printer.Print(divCl)

	if strings.Contains(rcrender, ">20") && strings.Contains(rcrender, ">30") && !strings.Contains(rcrender, ">400") {
		tests.FatalFailed(t, "Inaccurate rendering occured, has '>20' or '>30' and  set", rcrender)
	}

	tests.LogPassed(t, "Successfully reconciled dom markup!")
}
예제 #2
0
func TestMarkupRemoveRender(t *testing.T) {
	div := elems.Div(
		elems.Text("20"),
	)

	if len(div.Children()) <= 0 {
		tests.FatalFailed(t, "Inaccurate size of children, expected %d for %s", 1, len(div.Children()))
	}

	divCl := div.Clone().(*trees.Element)

	if len(divCl.Children()) <= 0 {
		tests.FatalFailed(t, "Inaccurate size of clone's children, expected %d for %s", 1, len(div.Children()))
	}

	printer := trees.NewElementWriter(trees.SimpleAttrWriter, trees.SimpleStyleWriter, trees.SimpleTextWriter)
	printer.AllowRemoved()

	if ds := printer.Print(div); len(ds) != len(normalRender) {
		tests.FatalFailed(t, "1 Renders produced unequal results between \n %s and \n %s", ds, normalRender)
	}

	trees.ElementsWithTag(divCl, "text")[0].Remove()

	if dl, dcl := len(div.Children()), len(divCl.Children()); dl != dcl {
		tests.FatalFailed(t, "Clone children size is inaccurate, expected %d but got %d", dl, dcl)
	}

	if ds := printer.Print(divCl); len(ds) != len(removedRender) {
		tests.FatalFailed(t, "2 Renders produced unequal results between \n %s and \n %s", ds, removedRender)
	}

	printer.DisallowRemoved()

	if ds := printer.Print(divCl); len(ds) != len(cleanRender) {
		tests.FatalFailed(t, "3 Renders produced unequal results between \n %s and \n %s", ds, cleanRender)
	}

	divCl.CleanRemoved()

	if dl, dcl := len(div.Children()), len(divCl.Children()); dl == dcl {
		tests.FatalFailed(t, "Clone children size is inaccurate, expected %d but got %d", dl, dcl)
	}

	tests.LogPassed(t, "Successfully asserted proper markup operation with .Remove()!")
}