diff --git a/bench_array_test.go b/bench_array_test.go index 6d5581e..29c7e20 100644 --- a/bench_array_test.go +++ b/bench_array_test.go @@ -70,7 +70,9 @@ func BenchmarkIndex(b *testing.B) { for i := 0; i < b.N; i++ { j = sel.Index() } - b.Logf("Index=%d", j) + if j != 3 { + b.Fatalf("want 3, got %d", j) + } } func BenchmarkIndexSelector(b *testing.B) { @@ -82,7 +84,9 @@ func BenchmarkIndexSelector(b *testing.B) { for i := 0; i < b.N; i++ { j = sel.IndexSelector("dd") } - b.Logf("IndexSelector=%d", j) + if j != 4 { + b.Fatalf("want 4, got %d", j) + } } func BenchmarkIndexOfNode(b *testing.B) { @@ -96,7 +100,9 @@ func BenchmarkIndexOfNode(b *testing.B) { for i := 0; i < b.N; i++ { j = sel.IndexOfNode(n) } - b.Logf("IndexOfNode=%d", j) + if j != 2 { + b.Fatalf("want 2, got %d", j) + } } func BenchmarkIndexOfSelection(b *testing.B) { @@ -108,5 +114,7 @@ func BenchmarkIndexOfSelection(b *testing.B) { for i := 0; i < b.N; i++ { j = sel.IndexOfSelection(sel2) } - b.Logf("IndexOfSelection=%d", j) + if j != 2 { + b.Fatalf("want 2, got %d", j) + } } diff --git a/bench_example_test.go b/bench_example_test.go index a547431..ba9ebe5 100644 --- a/bench_example_test.go +++ b/bench_example_test.go @@ -37,6 +37,4 @@ func BenchmarkMetalReviewExample(b *testing.B) { } }) } - b.Log(buf.String()) - b.Logf("MetalReviewExample=%d", n) } diff --git a/bench_expand_test.go b/bench_expand_test.go index aee7d81..d0eb2b3 100644 --- a/bench_expand_test.go +++ b/bench_expand_test.go @@ -17,7 +17,9 @@ func BenchmarkAdd(b *testing.B) { sel.Add("h2[title]") } } - b.Logf("Add=%d", n) + if n != 43 { + b.Fatalf("want 43, got %d", n) + } } func BenchmarkAddSelection(b *testing.B) { @@ -34,7 +36,9 @@ func BenchmarkAddSelection(b *testing.B) { sel.AddSelection(sel2) } } - b.Logf("AddSelection=%d", n) + if n != 43 { + b.Fatalf("want 43, got %d", n) + } } func BenchmarkAddNodes(b *testing.B) { @@ -52,7 +56,9 @@ func BenchmarkAddNodes(b *testing.B) { sel.AddNodes(nodes...) } } - b.Logf("AddNodes=%d", n) + if n != 43 { + b.Fatalf("want 43, got %d", n) + } } func BenchmarkAndSelf(b *testing.B) { @@ -68,5 +74,7 @@ func BenchmarkAndSelf(b *testing.B) { sel.AndSelf() } } - b.Logf("AndSelf=%d", n) + if n != 44 { + b.Fatalf("want 44, got %d", n) + } } diff --git a/bench_filter_test.go b/bench_filter_test.go index 05ffaaa..61641c8 100644 --- a/bench_filter_test.go +++ b/bench_filter_test.go @@ -17,7 +17,9 @@ func BenchmarkFilter(b *testing.B) { sel.Filter(".toclevel-1") } } - b.Logf("Filter=%d", n) + if n != 13 { + b.Fatalf("want 13, got %d", n) + } } func BenchmarkNot(b *testing.B) { @@ -33,7 +35,9 @@ func BenchmarkNot(b *testing.B) { sel.Filter(".toclevel-2") } } - b.Logf("Not=%d", n) + if n != 371 { + b.Fatalf("want 371, got %d", n) + } } func BenchmarkFilterFunction(b *testing.B) { @@ -52,7 +56,9 @@ func BenchmarkFilterFunction(b *testing.B) { sel.FilterFunction(f) } } - b.Logf("FilterFunction=%d", n) + if n != 112 { + b.Fatalf("want 112, got %d", n) + } } func BenchmarkNotFunction(b *testing.B) { @@ -71,7 +77,9 @@ func BenchmarkNotFunction(b *testing.B) { sel.NotFunction(f) } } - b.Logf("NotFunction=%d", n) + if n != 261 { + b.Fatalf("want 261, got %d", n) + } } func BenchmarkFilterNodes(b *testing.B) { @@ -89,7 +97,9 @@ func BenchmarkFilterNodes(b *testing.B) { sel.FilterNodes(nodes...) } } - b.Logf("FilterNodes=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkNotNodes(b *testing.B) { @@ -107,7 +117,9 @@ func BenchmarkNotNodes(b *testing.B) { sel.NotNodes(nodes...) } } - b.Logf("NotNodes=%d", n) + if n != 360 { + b.Fatalf("want 360, got %d", n) + } } func BenchmarkFilterSelection(b *testing.B) { @@ -124,7 +136,9 @@ func BenchmarkFilterSelection(b *testing.B) { sel.FilterSelection(sel2) } } - b.Logf("FilterSelection=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkNotSelection(b *testing.B) { @@ -141,7 +155,9 @@ func BenchmarkNotSelection(b *testing.B) { sel.NotSelection(sel2) } } - b.Logf("NotSelection=%d", n) + if n != 360 { + b.Fatalf("want 360, got %d", n) + } } func BenchmarkHas(b *testing.B) { @@ -157,7 +173,9 @@ func BenchmarkHas(b *testing.B) { sel.Has(".editsection") } } - b.Logf("Has=%d", n) + if n != 13 { + b.Fatalf("want 13, got %d", n) + } } func BenchmarkHasNodes(b *testing.B) { @@ -175,7 +193,9 @@ func BenchmarkHasNodes(b *testing.B) { sel.HasNodes(nodes...) } } - b.Logf("HasNodes=%d", n) + if n != 15 { + b.Fatalf("want 15, got %d", n) + } } func BenchmarkHasSelection(b *testing.B) { @@ -192,7 +212,9 @@ func BenchmarkHasSelection(b *testing.B) { sel.HasSelection(sel2) } } - b.Logf("HasSelection=%d", n) + if n != 15 { + b.Fatalf("want 15, got %d", n) + } } func BenchmarkEnd(b *testing.B) { @@ -208,5 +230,7 @@ func BenchmarkEnd(b *testing.B) { sel.End() } } - b.Logf("End=%d", n) + if n != 373 { + b.Fatalf("wnat 373, got %d", n) + } } diff --git a/bench_iteration_test.go b/bench_iteration_test.go index f1b5530..39445b0 100644 --- a/bench_iteration_test.go +++ b/bench_iteration_test.go @@ -19,7 +19,9 @@ func BenchmarkEach(b *testing.B) { n = tmp } } - b.Logf("Each=%d", n) + if n != 59 { + b.Fatalf("want 59, got %d", n) + } } func BenchmarkMap(b *testing.B) { @@ -38,7 +40,9 @@ func BenchmarkMap(b *testing.B) { n = tmp } } - b.Logf("Map=%d", n) + if n != 59 { + b.Fatalf("want 59, got %d", n) + } } func BenchmarkEachWithBreak(b *testing.B) { @@ -58,5 +62,7 @@ func BenchmarkEachWithBreak(b *testing.B) { n = tmp } } - b.Logf("Each=%d", n) + if n != 10 { + b.Fatalf("want 10, got %d", n) + } } diff --git a/bench_property_test.go b/bench_property_test.go index 0e61603..8acf5bf 100644 --- a/bench_property_test.go +++ b/bench_property_test.go @@ -13,7 +13,9 @@ func BenchmarkAttr(b *testing.B) { for i := 0; i < b.N; i++ { s, _ = sel.Attr("id") } - b.Logf("Attr=%s", s) + if s != "firstHeading" { + b.Fatalf("want firstHeading, got %q", s) + } } func BenchmarkText(b *testing.B) { @@ -34,7 +36,9 @@ func BenchmarkLength(b *testing.B) { for i := 0; i < b.N; i++ { n = sel.Length() } - b.Logf("Length=%d", n) + if n != 14 { + b.Fatalf("want 14, got %d", n) + } } func BenchmarkHtml(b *testing.B) { diff --git a/bench_query_test.go b/bench_query_test.go index 3d3a98f..64fdbc4 100644 --- a/bench_query_test.go +++ b/bench_query_test.go @@ -13,7 +13,9 @@ func BenchmarkIs(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.Is(".toclevel-2") } - b.Logf("Is=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkIsPositional(b *testing.B) { @@ -25,7 +27,9 @@ func BenchmarkIsPositional(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.Is("li:nth-child(2)") } - b.Logf("IsPositional=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkIsFunction(b *testing.B) { @@ -40,7 +44,9 @@ func BenchmarkIsFunction(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.IsFunction(f) } - b.Logf("IsFunction=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkIsSelection(b *testing.B) { @@ -53,7 +59,9 @@ func BenchmarkIsSelection(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.IsSelection(sel2) } - b.Logf("IsSelection=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkIsNodes(b *testing.B) { @@ -67,7 +75,9 @@ func BenchmarkIsNodes(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.IsNodes(nodes...) } - b.Logf("IsNodes=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkHasClass(b *testing.B) { @@ -79,7 +89,9 @@ func BenchmarkHasClass(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.HasClass("official") } - b.Logf("HasClass=%v", y) + if !y { + b.Fatal("want true") + } } func BenchmarkContains(b *testing.B) { @@ -93,5 +105,7 @@ func BenchmarkContains(b *testing.B) { for i := 0; i < b.N; i++ { y = sel.Contains(node) } - b.Logf("Contains=%v", y) + if !y { + b.Fatal("want true") + } } diff --git a/bench_traversal_test.go b/bench_traversal_test.go index 43610f6..de84bcd 100644 --- a/bench_traversal_test.go +++ b/bench_traversal_test.go @@ -15,7 +15,9 @@ func BenchmarkFind(b *testing.B) { DocB().Find("dd") } } - b.Logf("Find=%d", n) + if n != 41 { + b.Fatalf("want 41, got %d", n) + } } func BenchmarkFindWithinSelection(b *testing.B) { @@ -31,7 +33,9 @@ func BenchmarkFindWithinSelection(b *testing.B) { sel.Find("a[class]") } } - b.Logf("FindWithinSelection=%d", n) + if n != 39 { + b.Fatalf("want 39, got %d", n) + } } func BenchmarkFindSelection(b *testing.B) { @@ -48,7 +52,9 @@ func BenchmarkFindSelection(b *testing.B) { sel.FindSelection(sel2) } } - b.Logf("FindSelection=%d", n) + if n != 73 { + b.Fatalf("want 73, got %d", n) + } } func BenchmarkFindNodes(b *testing.B) { @@ -66,7 +72,9 @@ func BenchmarkFindNodes(b *testing.B) { sel.FindNodes(nodes...) } } - b.Logf("FindNodes=%d", n) + if n != 73 { + b.Fatalf("want 73, got %d", n) + } } func BenchmarkContents(b *testing.B) { @@ -82,7 +90,9 @@ func BenchmarkContents(b *testing.B) { sel.Contents() } } - b.Logf("Contents=%d", n) + if n != 16 { + b.Fatalf("want 16, got %d", n) + } } func BenchmarkContentsFiltered(b *testing.B) { @@ -98,7 +108,9 @@ func BenchmarkContentsFiltered(b *testing.B) { sel.ContentsFiltered("a[href=\"#Examples\"]") } } - b.Logf("ContentsFiltered=%d", n) + if n != 1 { + b.Fatalf("want 1, got %d", n) + } } func BenchmarkChildren(b *testing.B) { @@ -114,7 +126,9 @@ func BenchmarkChildren(b *testing.B) { sel.Children() } } - b.Logf("Children=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkChildrenFiltered(b *testing.B) { @@ -130,7 +144,9 @@ func BenchmarkChildrenFiltered(b *testing.B) { sel.ChildrenFiltered(".editsection") } } - b.Logf("ChildrenFiltered=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkParent(b *testing.B) { @@ -146,7 +162,9 @@ func BenchmarkParent(b *testing.B) { sel.Parent() } } - b.Logf("Parent=%d", n) + if n != 55 { + b.Fatalf("want 55, got %d", n) + } } func BenchmarkParentFiltered(b *testing.B) { @@ -162,7 +180,9 @@ func BenchmarkParentFiltered(b *testing.B) { sel.ParentFiltered("ul[id]") } } - b.Logf("ParentFiltered=%d", n) + if n != 4 { + b.Fatalf("want 4, got %d", n) + } } func BenchmarkParents(b *testing.B) { @@ -178,7 +198,9 @@ func BenchmarkParents(b *testing.B) { sel.Parents() } } - b.Logf("Parents=%d", n) + if n != 73 { + b.Fatalf("want 73, got %d", n) + } } func BenchmarkParentsFiltered(b *testing.B) { @@ -194,7 +216,9 @@ func BenchmarkParentsFiltered(b *testing.B) { sel.ParentsFiltered("tr") } } - b.Logf("ParentsFiltered=%d", n) + if n != 18 { + b.Fatalf("want 18, got %d", n) + } } func BenchmarkParentsUntil(b *testing.B) { @@ -210,7 +234,9 @@ func BenchmarkParentsUntil(b *testing.B) { sel.ParentsUntil("table") } } - b.Logf("ParentsUntil=%d", n) + if n != 52 { + b.Fatalf("want 52, got %d", n) + } } func BenchmarkParentsUntilSelection(b *testing.B) { @@ -227,7 +253,9 @@ func BenchmarkParentsUntilSelection(b *testing.B) { sel.ParentsUntilSelection(sel2) } } - b.Logf("ParentsUntilSelection=%d", n) + if n != 70 { + b.Fatalf("want 70, got %d", n) + } } func BenchmarkParentsUntilNodes(b *testing.B) { @@ -245,7 +273,9 @@ func BenchmarkParentsUntilNodes(b *testing.B) { sel.ParentsUntilNodes(nodes...) } } - b.Logf("ParentsUntilNodes=%d", n) + if n != 70 { + b.Fatalf("want 70, got %d", n) + } } func BenchmarkParentsFilteredUntil(b *testing.B) { @@ -261,7 +291,9 @@ func BenchmarkParentsFilteredUntil(b *testing.B) { sel.ParentsFilteredUntil(":nth-child(1)", "ul") } } - b.Logf("ParentsFilteredUntil=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkParentsFilteredUntilSelection(b *testing.B) { @@ -278,7 +310,9 @@ func BenchmarkParentsFilteredUntilSelection(b *testing.B) { sel.ParentsFilteredUntilSelection(":nth-child(1)", sel2) } } - b.Logf("ParentsFilteredUntilSelection=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkParentsFilteredUntilNodes(b *testing.B) { @@ -296,7 +330,9 @@ func BenchmarkParentsFilteredUntilNodes(b *testing.B) { sel.ParentsFilteredUntilNodes(":nth-child(1)", nodes...) } } - b.Logf("ParentsFilteredUntilNodes=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkSiblings(b *testing.B) { @@ -312,7 +348,9 @@ func BenchmarkSiblings(b *testing.B) { sel.Siblings() } } - b.Logf("Siblings=%d", n) + if n != 293 { + b.Fatalf("want 293, got %d", n) + } } func BenchmarkSiblingsFiltered(b *testing.B) { @@ -328,7 +366,9 @@ func BenchmarkSiblingsFiltered(b *testing.B) { sel.SiblingsFiltered("[class]") } } - b.Logf("SiblingsFiltered=%d", n) + if n != 46 { + b.Fatalf("want 46, got %d", n) + } } func BenchmarkNext(b *testing.B) { @@ -344,7 +384,9 @@ func BenchmarkNext(b *testing.B) { sel.Next() } } - b.Logf("Next=%d", n) + if n != 49 { + b.Fatalf("want 49, got %d", n) + } } func BenchmarkNextFiltered(b *testing.B) { @@ -360,7 +402,9 @@ func BenchmarkNextFiltered(b *testing.B) { sel.NextFiltered("[class]") } } - b.Logf("NextFiltered=%d", n) + if n != 6 { + b.Fatalf("want 6, got %d", n) + } } func BenchmarkNextAll(b *testing.B) { @@ -376,7 +420,9 @@ func BenchmarkNextAll(b *testing.B) { sel.NextAll() } } - b.Logf("NextAll=%d", n) + if n != 234 { + b.Fatalf("want 234, got %d", n) + } } func BenchmarkNextAllFiltered(b *testing.B) { @@ -392,7 +438,9 @@ func BenchmarkNextAllFiltered(b *testing.B) { sel.NextAllFiltered("[class]") } } - b.Logf("NextAllFiltered=%d", n) + if n != 33 { + b.Fatalf("want 33, got %d", n) + } } func BenchmarkPrev(b *testing.B) { @@ -408,7 +456,9 @@ func BenchmarkPrev(b *testing.B) { sel.Prev() } } - b.Logf("Prev=%d", n) + if n != 49 { + b.Fatalf("want 49, got %d", n) + } } func BenchmarkPrevFiltered(b *testing.B) { @@ -426,7 +476,9 @@ func BenchmarkPrevFiltered(b *testing.B) { } // There is one more Prev li with a class, compared to Next li with a class // (confirmed by looking at the HTML, this is ok) - b.Logf("PrevFiltered=%d", n) + if n != 7 { + b.Fatalf("want 7, got %d", n) + } } func BenchmarkPrevAll(b *testing.B) { @@ -442,7 +494,9 @@ func BenchmarkPrevAll(b *testing.B) { sel.PrevAll() } } - b.Logf("PrevAll=%d", n) + if n != 78 { + b.Fatalf("want 78, got %d", n) + } } func BenchmarkPrevAllFiltered(b *testing.B) { @@ -458,7 +512,9 @@ func BenchmarkPrevAllFiltered(b *testing.B) { sel.PrevAllFiltered("[class]") } } - b.Logf("PrevAllFiltered=%d", n) + if n != 6 { + b.Fatalf("want 6, got %d", n) + } } func BenchmarkNextUntil(b *testing.B) { @@ -474,7 +530,9 @@ func BenchmarkNextUntil(b *testing.B) { sel.NextUntil(":nth-child(4)") } } - b.Logf("NextUntil=%d", n) + if n != 84 { + b.Fatalf("want 84, got %d", n) + } } func BenchmarkNextUntilSelection(b *testing.B) { @@ -491,7 +549,9 @@ func BenchmarkNextUntilSelection(b *testing.B) { sel.NextUntilSelection(sel2) } } - b.Logf("NextUntilSelection=%d", n) + if n != 42 { + b.Fatalf("want 42, got %d", n) + } } func BenchmarkNextUntilNodes(b *testing.B) { @@ -509,7 +569,9 @@ func BenchmarkNextUntilNodes(b *testing.B) { sel.NextUntilNodes(nodes...) } } - b.Logf("NextUntilNodes=%d", n) + if n != 12 { + b.Fatalf("want 12, got %d", n) + } } func BenchmarkPrevUntil(b *testing.B) { @@ -525,7 +587,9 @@ func BenchmarkPrevUntil(b *testing.B) { sel.PrevUntil(":nth-child(4)") } } - b.Logf("PrevUntil=%d", n) + if n != 238 { + b.Fatalf("want 238, got %d", n) + } } func BenchmarkPrevUntilSelection(b *testing.B) { @@ -542,7 +606,9 @@ func BenchmarkPrevUntilSelection(b *testing.B) { sel.PrevUntilSelection(sel2) } } - b.Logf("PrevUntilSelection=%d", n) + if n != 49 { + b.Fatalf("want 49, got %d", n) + } } func BenchmarkPrevUntilNodes(b *testing.B) { @@ -560,7 +626,9 @@ func BenchmarkPrevUntilNodes(b *testing.B) { sel.PrevUntilNodes(nodes...) } } - b.Logf("PrevUntilNodes=%d", n) + if n != 11 { + b.Fatalf("want 11, got %d", n) + } } func BenchmarkNextFilteredUntil(b *testing.B) { @@ -576,7 +644,9 @@ func BenchmarkNextFilteredUntil(b *testing.B) { sel.NextFilteredUntil("p", "div") } } - b.Logf("NextFilteredUntil=%d", n) + if n != 22 { + b.Fatalf("want 22, got %d", n) + } } func BenchmarkNextFilteredUntilSelection(b *testing.B) { @@ -593,7 +663,9 @@ func BenchmarkNextFilteredUntilSelection(b *testing.B) { sel.NextFilteredUntilSelection("p", sel2) } } - b.Logf("NextFilteredUntilSelection=%d", n) + if n != 22 { + b.Fatalf("want 22, got %d", n) + } } func BenchmarkNextFilteredUntilNodes(b *testing.B) { @@ -611,7 +683,9 @@ func BenchmarkNextFilteredUntilNodes(b *testing.B) { sel.NextFilteredUntilNodes("p", nodes...) } } - b.Logf("NextFilteredUntilNodes=%d", n) + if n != 22 { + b.Fatalf("want 22, got %d", n) + } } func BenchmarkPrevFilteredUntil(b *testing.B) { @@ -627,7 +701,9 @@ func BenchmarkPrevFilteredUntil(b *testing.B) { sel.PrevFilteredUntil("p", "div") } } - b.Logf("PrevFilteredUntil=%d", n) + if n != 20 { + b.Fatalf("want 20, got %d", n) + } } func BenchmarkPrevFilteredUntilSelection(b *testing.B) { @@ -644,7 +720,9 @@ func BenchmarkPrevFilteredUntilSelection(b *testing.B) { sel.PrevFilteredUntilSelection("p", sel2) } } - b.Logf("PrevFilteredUntilSelection=%d", n) + if n != 20 { + b.Fatalf("want 20, got %d", n) + } } func BenchmarkPrevFilteredUntilNodes(b *testing.B) { @@ -662,7 +740,9 @@ func BenchmarkPrevFilteredUntilNodes(b *testing.B) { sel.PrevFilteredUntilNodes("p", nodes...) } } - b.Logf("PrevFilteredUntilNodes=%d", n) + if n != 20 { + b.Fatalf("want 20, got %d", n) + } } func BenchmarkClosest(b *testing.B) { @@ -678,7 +758,9 @@ func BenchmarkClosest(b *testing.B) { sel.Closest(".pvk-content") } } - b.Logf("Closest=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkClosestSelection(b *testing.B) { @@ -695,7 +777,9 @@ func BenchmarkClosestSelection(b *testing.B) { sel.ClosestSelection(sel2) } } - b.Logf("ClosestSelection=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } } func BenchmarkClosestNodes(b *testing.B) { @@ -712,5 +796,7 @@ func BenchmarkClosestNodes(b *testing.B) { sel.ClosestNodes(nodes...) } } - b.Logf("ClosestNodes=%d", n) + if n != 2 { + b.Fatalf("want 2, got %d", n) + } }