示例#1
0
        public void SelectorSequence_WithThreeSelectors_Matches()
        {
            var selector = CssSelector.WithElement("h1", null)
                           .Add(CssSelector.WithId("chapter1"));

            var pseudoClassInfo = Substitute.For <XElementPseudoClassInfo>();

            pseudoClassInfo.IsTarget(Arg.Any <XElement>())
            .Returns(call => "true".Equals(call.Arg <XElement>().Attribute("istarget")?.Value, StringComparison.OrdinalIgnoreCase));

            var xdoc = XDocument.Parse(@"
				<html>
					<head />
					<body>
						<p id='chapter1' istarget='true' />
						<h1 id='chapter1' istarget='true' />
						<h1 id='ch2' istarget='true' />
						<h1 id='ch3' />
					</body>
				</html>"                );

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Name.LocalName + "." + e.Attribute("id").Value), Is.EquivalentTo(new[] { "h1.chapter1" }));
        }
示例#2
0
        public void SelectorSequence_WithTwoSelectors_ToString()
        {
            var selector = CssSelector.WithElement("h1", null)
                           .Add(CssSelector.WithId("chapter1"));

            Assert.That(selector.ToString(), Is.EqualTo("h1#chapter1"));
        }
示例#3
0
        public void SelectorSequence_WithThreeSelectors_ToString()
        {
            var selector = CssSelector.WithElement("h1", null)
                           .Add(CssSelector.WithId("chapter1"))
                           .Add(CssSelector.WithPseudoClass("target"));

            Assert.That(selector.ToString(), Is.EqualTo("h1#chapter1:target"));
        }
示例#4
0
        public void SelectorSequence_WithTwoSelectors()
        {
            var typeSelector  = CssSelector.WithElement("h1");
            var extraSelector = CssSelector.WithId("chapter1");
            var selector      = typeSelector.Add(extraSelector);

            Assert.Multiple(() =>
            {
                Assert.That(selector.TypeSelector, Is.SameAs(typeSelector), nameof(selector.TypeSelector));
                Assert.That(selector.OtherSelectors, Is.EquivalentTo(new[] { extraSelector }), nameof(selector.OtherSelectors));
                Assert.That(selector.Subject, Is.SameAs(selector), nameof(selector.Subject));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(1, 0, 1)), nameof(selector.Specificity));
            });
        }
示例#5
0
        public void SelectorSequence_WithTwoSelectors_Matches()
        {
            var selector = CssSelector.WithElement("h1", null)
                           .Add(CssSelector.WithId("chapter1"));

            var xdoc = XDocument.Parse(@"
				<html>
					<head />
					<body>
						<p id='chapter1' />
						<h1 id='chapter1' />
						<h1 id='ch2' />
						<h1 id='ch3' />
					</body>
				</html>"                );

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Name.LocalName + "." + e.Attribute("id").Value), Is.EquivalentTo(new[] { "h1.chapter1" }));
        }
示例#6
0
        public void IdSelector_Matches()
        {
            var selector = CssSelector.WithId("par1");
            var xdoc     = XDocument.Parse(@"
				<html>
					<head />
					<body>
						<p id='par1' />
						<p id='par2' />
						<p id='par1b' />
						<p id='PAR1' />
						<p id='' />
						<p />
					</body>
				</html>"                );

            var matchingElements = xdoc.Descendants().Where(e => selector.Matches(new XElementInfo(e))).ToList();

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "par1" }));
        }
示例#7
0
        public void SelectorSequence_WithThreeSelectors()
        {
            var typeSelector   = CssSelector.WithElement("h1", null);
            var extraSelectors = new CssSimpleSelector[]
            {
                CssSelector.WithId("chapter1"),
                CssSelector.WithPseudoClass("target")
            };

            var selector = typeSelector.Add(extraSelectors[0]);

            for (var i = 1; i < extraSelectors.Length; i++)
            {
                selector = selector.Add(extraSelectors[i]);
            }

            Assert.Multiple(() =>
            {
                Assert.That(selector.TypeSelector, Is.SameAs(typeSelector), nameof(selector.TypeSelector));
                Assert.That(selector.OtherSelectors, Is.EquivalentTo(extraSelectors), nameof(selector.OtherSelectors));
                Assert.That(selector.Subject, Is.SameAs(selector), nameof(selector.Subject));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(1, 1, 1)), nameof(selector.Specificity));
            });
        }
示例#8
0
 public void IdSelector_ToString()
 {
     Assert.That(CssSelector.WithId("par1").ToString(), Is.EqualTo("#par1"));
 }
示例#9
0
        public void IdSelector()
        {
            var selector = CssSelector.WithId("par1");

            Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(1, 0, 0)), nameof(selector.Specificity));
        }
 public void IdSelector()
 {
     VerifyRule(CssSelectorGrammar.IdSelector, "#id1", CssSelector.WithId("id1"));
 }