Пример #1
0
        public void CreateAttributeRegExTest()
        {
            string attributeName = "href"; // TODO: Initialize to an appropriate value
            var    actual        = HtmlUtils.CreateAttributeRegEx(attributeName);

            const string anchorHrefStandardDblQuote = "<p><a href=\"https://github.com/jamestharpe/Utilla\">Go to Utilla</a></p>";
            var          matchValue = actual.Match(anchorHrefStandardDblQuote).Value;

            Assert.AreEqual(" href=\"https://github.com/jamestharpe/Utilla\"", matchValue);

            const string anchorHrefStandardSnglQuote = "<p><a href='https://github.com/jamestharpe/Utilla'>Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefStandardSnglQuote).Value;
            Assert.AreEqual(" href='https://github.com/jamestharpe/Utilla'", matchValue);

            const string anchorHrefStandardNoQuote = "<p><a href=https://github.com/jamestharpe/Utilla>Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefStandardNoQuote).Value;
            Assert.AreEqual(" href=https://github.com/jamestharpe/Utilla", matchValue);

            const string anchorHrefMismatchDblSnglQuote = "<p><a href=\"https://github.com/jamestharpe/Utilla'>Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefMismatchDblSnglQuote).Value;
            Assert.AreEqual(" href=\"https://github.com/jamestharpe/Utilla'", matchValue);

            const string anchorHrefMismatchSnglDblQuote = "<p><a href='https://github.com/jamestharpe/Utilla\">Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefMismatchSnglDblQuote).Value;
            Assert.AreEqual(" href='https://github.com/jamestharpe/Utilla\"", matchValue);

            const string anchorHrefOpenDblQuote = "<p><a href=\"https://github.com/jamestharpe/Utilla>Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefOpenDblQuote).Value;
            Assert.AreEqual(" href=\"https://github.com/jamestharpe/Utilla", matchValue);

            const string anchorHrefOpenSnglQuote = "<p><a href='https://github.com/jamestharpe/Utilla>Go to Utilla</a></p>";

            matchValue = actual.Match(anchorHrefOpenSnglQuote).Value;
            Assert.AreEqual(" href='https://github.com/jamestharpe/Utilla", matchValue);
        }