public void InnerParsingRules() { CQ res = Dom.Select("script"); // bug found 10/31/11 Assert.AreEqual(0, res.Children().Length, "Script cannot have children"); }
public void StartsWithOrHyphen() { CQ res = Dom.Select("[lang|=en]"); Assert.AreEqual(2, res.Length); res = Dom.Select("[lang|=en-uk]"); Assert.AreEqual(1, res.Length); }
public void InputCheckbox() { string ids = String.Empty; var res = Dom.Select("input:checkbox").Each(delegate(IDomObject e) { ids += (ids == "" ? "" : ",") + e.Id; }); Assert.AreEqual(4, res.Length, "Test input:checkbox"); }
public void AdjacentMultiple() { var res = Dom.Select("a+*"); Assert.AreEqual(2, res.Length); Assert.AreEqual("reputation_link", res[0].Id); res = Dom.Select("a+span+span"); Assert.AreEqual(1, res.Length); Assert.AreEqual("13 bronze badges", res[0]["title"]); res = Dom.Select("a+*+span"); Assert.AreEqual(2, res.Length); }
public void SimpleClone() { CQ hlinks = Dom.Select("#hlinks-user"); int spanCount = hlinks.Find("span").Length; CQ clone = hlinks.Clone(); Assert.AreEqual(hlinks.Find("*").Length + 1, clone.Select("*").Length, "Clone has same total elements as original"); CQ newHome = Dom.Select("#hidden-div"); spanCount = newHome.Find("span").Length; int cloneSpanCount = clone.Select("span").Length; Assert.AreEqual(1, newHome.Children().Length, "Sanity check - target has 1 child"); newHome.Append(clone); Assert.AreEqual(2, newHome.Children().Length, "Target has 2 children after cloning"); Assert.AreEqual(spanCount + cloneSpanCount, newHome.Find("span").Length, "Same # of spans in the clone"); }
public void ChangingClones() { FixtureSetUp(); var hlinks = Dom.Select("#hlinks-user"); var cloneRoot = Dom["#test-show"].Append(hlinks.Clone()); Assert.AreEqual("jamietre", hlinks.Find(".profile-link").Text(), "Sanity check: got the correct text"); var profileLink = cloneRoot.Find(".profile-link"); Assert.AreEqual("jamietre", profileLink.Text(), "Clone had the correct text"); profileLink.Text("ChangedMyName"); Assert.AreEqual("ChangedMyName", profileLink.Text(), "Clone had the correct text after change"); Assert.AreEqual("jamietre", hlinks.Find(".profile-link").Text(), "Original still had the correct text"); profileLink.Append("<h2>A Header</h2><div class=\"newstuff\"><span>I'm new</span></div>"); Assert.AreEqual(2, profileLink.Children().Length, "Added to my clone"); Assert.AreEqual("ChangedMyNameA HeaderI'm new", profileLink.Text(), "Text was obtained correctly from the clone"); Assert.AreEqual("jamietre", hlinks.Find(".profile-link").Text(), "Original still had the correct text"); }
public void Element() { var all = Dom["*"]; Assert.IsTrue(all.Length >= 30, "Select all"); var good = true; for (int i = 0; i < all.Length; i++) { if (all[i].NodeType == (NodeType)8) { good = false; } } Assert.IsTrue(good, "Select all elements, no comment nodes"); t("Element Selector", "#qunit-fixture p", Arrays.Create <string>("firstp", "ap", "sndp", "en", "sap", "first")); t("Element Selector", "body", Arrays.Create <string>("body")); t("Element Selector", "html", Arrays.Create <string>("html")); t("Parent Element", "div p", Arrays.Create <string>("firstp", "ap", "sndp", "en", "sap", "first")); Assert.AreEqual(Dom.Select("param", document.GetElementById("object1")).Length, 2, "Object/param as context"); CollectionAssert.AreEqual(Dom["select", document.GetElementById("form")], q("select1", "select2", "select3", "select4", "select5"), "Finding selects with a context."); // Check for unique-ness and sort order CollectionAssert.AreEqual(Dom["p, div p"], Dom["p"], "Check for duplicates: p, div p"); t("Checking sort order", "h2, h1", Arrays.Create <string>("qunit-header", "qunit-banner", "qunit-userAgent")); t("Checking sort order", "h2:first, h1:first", Arrays.Create <string>("qunit-header", "qunit-banner")); t("Checking sort order", "#qunit-fixture p, #qunit-fixture p a", Arrays.Create <string>("firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first")); // Test Conflict ID var lengthtest = document.GetElementById("lengthtest"); CollectionAssert.AreEqual(Dom["#idTest", lengthtest], q("idTest"), "Finding element with id of ID."); CollectionAssert.AreEqual(Dom["[name='id']", lengthtest], q("idTest"), "Finding element with id of ID."); CollectionAssert.AreEqual(Dom["input[id='idTest']", lengthtest], q("idTest"), "Finding elements with id of ID."); }
protected CQ jQueryAny(object parm) { if (parm == null) { return(Dom.Select((string)null)); } else if (parm.GetType() == typeof(string)) { return(Dom.Select((string)parm)); } else if (typeof(IEnumerable <IDomObject>).IsAssignableFrom(parm.GetType())) { return(Dom.Select((IEnumerable <IDomObject>)parm)); } else if (typeof(IDomObject).IsAssignableFrom(parm.GetType())) { return(Dom.Select((IDomObject)parm)); } else { throw new ArgumentException("Invalid parameter"); } }
public void ComplexSelectors() { var res = Dom.Select("input:checkbox,li"); Assert.AreEqual(7, res.Length, "Multiple select (two queries appended)"); }
protected CQ jQuery(string parm, CQ context) { return(Dom.Select(parm, context)); }
public void ParseHTMLSpec() { string html; DateTime start = DateTime.Now; System.GC.Collect(); var GC_MemoryStart = System.GC.GetTotalMemory(true); html = Support.GetFile("csquery\\csquery.tests\\resources\\HTML Standard.htm"); for (int i = 0; i < iterationsLoad; i++) { Dom = CQ.Create(html); } var GC_MemoryEnd = System.GC.GetTotalMemory(true); DateTime loaded = DateTime.Now; int divSpan = 0; int randomLength = Dom.Select("p").Eq(22).RenderSelection().Length; var equation = Equations.CreateEquation <int>("2x+2"); for (int i = 0; i < iterationsSelect; i++) { // todo: cache equations once parsed - should speed this up immenseley CQ sel = Dom.Select("div:nth-child(2n+1)"); //CsQuery sel = Dom.Select("div span"); // get length to force it to iterate through everything int len = sel.Length; //equation.SetVariable("x", 12); // var y = equation.Value; } CQ selFinal = Dom.Select("div span"); divSpan = selFinal.Length; DateTime selected = DateTime.Now; for (int i = 0; i < iterationsClone; i++) { CQ c = Dom.Clone(); Assert.AreEqual(divSpan, Dom.Select("div span").Length, "Clone wasn't equal in # of elements"); string cloneContents = c.Select("p").Eq(22).RenderSelection(); Assert.AreEqual(randomLength, cloneContents.Length, "Some random text was right"); } DateTime done = DateTime.Now; TimeSpan loadTime = loaded - start; string result = Dom.Select("div").Length + " div elements"; result += ", " + Dom.Select("*").Length + " total elements"; result += ", " + loadTime.TotalSeconds / iterationsLoad + " seconds to load domain"; result += ", " + (selected - loaded).TotalSeconds / iterationsSelect + " seconds to perform select 'div span' - " + Dom.Select("div span").Length + " elements"; result += ", " + (done - selected).TotalSeconds / iterationsClone + " seconds to cloning"; result += ", " + (GC_MemoryEnd - GC_MemoryStart) + " bytes used by object"; //Debug.WriteLine(result); Assert.Pass(result); }