Exemplo n.º 1
0
 public void FormatStrong_should_not_replace_digits_between_double_underscore()
 {
     string text = "__123__";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatDoubleUnderscore(text);
     Assert.AreEqual("__123__", result);
 }
Exemplo n.º 2
0
 public void IsOnlyDigitsBetweenTokens_on_digits_should_give_true()
 {
     string text = "Token123Token";
     var htmlFormatter = new HtmlFormatter();
     bool result = htmlFormatter.IsOnlyDigitsBetweenTokens(text, "Token");
     Assert.AreEqual(true, result);
 }
Exemplo n.º 3
0
 public void FormatHtmlStrong_should_replace_double_underscores_to_strong_tags()
 {
     string text = "__A__";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatDoubleUnderscore(text);
     Assert.AreEqual("<strong>A</strong>", result);
 }
Exemplo n.º 4
0
 public void FormatParagaraph_on_text_should_give_text_inside_p_tags_with_enter_on_the_end()
 {
     string text = "text";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatParagraph(text);
     Assert.AreEqual("<p>text</p>\r\n", result);
 }
Exemplo n.º 5
0
 public void FormatHtmlEm_should_not_replace_underscores_around_text_containing_only_digits()
 {
     string text = "_123_";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatUnderscore(text);
     Assert.AreEqual("_123_", result);
 }
Exemplo n.º 6
0
 public void FormatHtmlEm_should_replace_underscores_to_em_tags()
 {
     string text = "_A_";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatUnderscore(text);
     Assert.AreEqual("<em>A</em>", result);
 }
Exemplo n.º 7
0
 public void FormatGreateAndLesser_should_replace_more_sign_to_amp_gt()
 {
     string text = "\\>";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatMoreLess(text);
     Assert.AreEqual("&gt;", result);
 }
Exemplo n.º 8
0
 public void FormatCode_should_replace_backticks_around_text_to_code_tags()
 {
     string text = "`A`";
     var htmlFormatter = new HtmlFormatter();
     string result = htmlFormatter.FormatBacktick(text);
     Assert.AreEqual("<code>A</code>", result);
 }
Exemplo n.º 9
0
		public void Format_DefaultNamespaceTag_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("root", String.Empty, "http://example.com/schema")),
			        MarkupGrammar.TokenElementEnd,
			    };
			const string expected = @"<root xmlns=""http://example.com/schema""></root>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 10
0
		public void Format_SingleOpenCloseTag_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("root")),
			        MarkupGrammar.TokenElementEnd
			    };
			const string expected = @"<root></root>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 11
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // Specific - this good because result is exact string
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            // More general - this could test true for bug because too general (need both)
            // for string its better to be a bit more general unless you need
            //Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            //Assert.That(result, Does.EndWith("</strong>"));
            //Assert.That(result, Does.Contain("abc"));
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            //Specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase); //vhodne ak chceme overit presny vystup z metody (pozor na zmeny vystupu testovanej metody)
            //je mozne pridat metodu "IgnoreCase" pre ignorovanie malych/velkych pismen

            //more generic
            Assert.That(result, Does.StartWith("<strong>"));
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // Specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);
            // hence can also append IgnoreCase as EqualTo is by default Case Sensitive

            // More general
            Assert.That(result, Does.StartWith("<strong>"));
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 14
0
        public void FormatAsBold_WhenCalled_EncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            //Specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            //More General

            //Assert.That(result, Does.StartWith("<strong>"));
            //Assert.That(result, Does.EndWith("</strong>"));
            //Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 15
0
            public void ReadOnlyMemory_of_int_is_formatted_like_a_int_array()
            {
                var formatter = HtmlFormatter.GetBestFormatterFor <ReadOnlyMemory <int> >();

                var writer = new StringWriter();

                var readOnlyMemory = new ReadOnlyMemory <int>(new[] { 7, 8, 9 });

                formatter.Format(readOnlyMemory, writer);

                writer.ToString()
                .Should()
                .BeEquivalentHtmlTo(
                    "<table><thead><tr><th><i>index</i></th><th>value</th></tr></thead><tbody><tr><td>0</td><td>7</td></tr><tr><td>1</td><td>8</td></tr><tr><td>2</td><td>9</td></tr></tbody></table>");
            }
Exemplo n.º 16
0
            public void It_formats_tuples_as_tables_having_properties_on_the_y_axis()
            {
                var writer = new StringWriter();

                var instance = (123, "hello");

                var formatter = HtmlFormatter.GetPreferredFormatterFor(instance.GetType());

                formatter.Format(instance, writer);

                writer.ToString()
                .Should()
                .BeEquivalentHtmlTo($@"<table><thead><tr><th>Item1</th><th>Item2</th></tr></thead>
<tbody><tr><td>{PlainTextBegin}123{PlainTextEnd}</td><td>{PlainTextBegin}hello{PlainTextEnd}</td></tr></tbody></table>");
            }
Exemplo n.º 17
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Conversion();

            // Instantiate a Presentation object that represents a presentation file
            using (Presentation presentation = new Presentation(dataDir + "Convert_HTML.pptx"))
            {
                HtmlOptions htmlOpt = new HtmlOptions();
                htmlOpt.HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("", false);

                // Saving the presentation to HTML
                presentation.Save(dataDir + "ConvertWholePresentationToHTML_out.html", SaveFormat.Html, htmlOpt);
            }
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var actual = formatter.FormatAsBold("abc");

            // Specific, good but not flexible enough for changes that don't affect this test case
            // ie, adding a period, excalamation mark etc.
            // This is a good choice for simple tests tho
            Assert.That(actual, Is.EqualTo("<strong>abc</strong>"));

            // just right
            Assert.That(actual, Does.StartWith("<strong>").IgnoreCase); // assertion ignores case sensitivity
            Assert.That(actual, Does.EndWith("</strong>"));
            Assert.That(actual, Does.Contain("abc"));
        }
        public void  FormatAsBold_WhenCalled_ReturnStringEnclosedInStrongElement()
        {
            //Arrange
            var htmlFormatter = new HtmlFormatter();

            //Act
            var result = htmlFormatter.FormatAsBold("abc");

            //Assert - specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>"));

            //Assert - general
            Assert.That(result, Does.StartWith("<strong>"));
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            string FilePath     = @"..\..\..\Sample Files\";
            string srcFileName  = FilePath + "Conversion.pptx";
            string destFileName = FilePath + "Converting to HTML.html";

            //Instantiate a Presentation object that represents a presentation file
            Presentation pres = new Presentation(srcFileName);

            HtmlOptions htmlOpt = new HtmlOptions();

            htmlOpt.HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("", false);

            //Saving the presentation to HTML
            pres.Save(destFileName, Aspose.Slides.Export.SaveFormat.Html, htmlOpt);
        }
Exemplo n.º 21
0
        public void FormatBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            //Arrange
            var formatter = new HtmlFormatter();

            //Act.
            var result = formatter.FormatAsBold("abc");

            //Assertion.
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            /* More general assertion
             * Assert.That(result, Does.StartWith("<strong>"));
             * Assert.That(result, Does.EndWith("</strong>"));
             * Assert.That(result, Does.Contain("abc"));*/
        }
Exemplo n.º 22
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (!(validationContext.ObjectInstance is BannerModel model))
            {
                throw new ArgumentException("Attribute not applied on Employee");
            }

            string htmlMessage;

            if (!HtmlFormatter.IsValidHtml(model.Html, out htmlMessage))
            {
                return(new ValidationResult($"html is invalid:{Environment.NewLine}{htmlMessage}"));
            }

            return(ValidationResult.Success);
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElelemnt()
        {
            var    formatter = new HtmlFormatter();
            string value     = "abc";
            var    result    = formatter.FormatAsBold("abc");

            //specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>"));

            //more general
            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));

            Assert.That(result, Is.EqualTo($"<strong>{value}</strong>").IgnoreCase);
        }
Exemplo n.º 24
0
        public void FomatAsBold_WhenCalled_ReturnStringStrong()
        {
            var formatter = new HtmlFormatter();
            var result    = formatter.FormatAsBold("abc");

            //Specific - better in this case
            //ctrl k ctrl c - komentowanie
            //ctrl k ctrl u - odkomentowanie
            Assert.That(result, Is.EqualTo("<strong>abc</strong>"));


            //too general
            //Assert.That(result, Does.StartWith("<strong>"));
            //Assert.That(result, Does.EndWith("</strong>"));
            //Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 25
0
        public void FormatAsBold_WhenCalled_ShouldEncloseWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // Strings are casesensitive. Use .ignorecase if not required to be casesensitive

            // Specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>"));

            // More General
//            Assert.That(result, Does.StartWith("<strong>"));
//            Assert.That(result, Does.EndWith("</strong>"));
//            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 26
0
        //ExStart:ConvertIndividualSlide
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Conversion();

            using (Presentation presentation = new Presentation(dataDir + "Individual-Slide.pptx"))
            {
                HtmlOptions htmlOptions = new HtmlOptions();
                htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(new CustomFormattingController());

                // Saving File
                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    presentation.Save(dataDir + "Individual Slide" + (i + 1) + "_out.html", new[] { i + 1 }, SaveFormat.Html, htmlOptions);
                }
            }
        }
Exemplo n.º 27
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // too specific assertion // lw 3mlt bold b ay 7aga tanya 8er el strong tag 7b2a fail
            //Assert.That(result, Is.EqualTo("<strong>abc</strong>"));

            // too general // kda lw 3mlt return "<strong>" will pass w dh msh s7
            //Assert.That(result, Does.StartWith("<strong>"));

            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Get the article and format the html content.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="html"></param>
        /// <returns></returns>
        public static Article GetArticleAndFormatter(string url, string html = null)
        {
            if (string.IsNullOrWhiteSpace(html))
            {
                html = HttpHelper.GetHttpContent(url);
            }

            Article article = HtmlToArticle.GetArticle(html);

            if (article != null && !string.IsNullOrWhiteSpace(article.HtmlContent))
            {
                article.HtmlContent = HtmlFormatter.FormatHtml(article.HtmlContent, url);
            }

            return(article);
        }
Exemplo n.º 29
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWIthStrongElement()
        {
            var formatter = new HtmlFormatter();

            string testString = "hello";

            var result = formatter.FormatAsBold(testString);

            //Specfic Assetion
            //Assert.That(result, Is.EqualTo("<strong>hello</strong>"));

            //More general
            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("hello"));
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // Specific -
            // future iterations can break tests so don't make them too specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            // General -
            // likewise if too general tests can pass while code is broken ie just test for first strong
            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>").IgnoreCase);
            Assert.That(result, Does.Contain("abc").IgnoreCase);
        }
Exemplo n.º 31
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement(string content)
        {
            var htmlFormatter = new HtmlFormatter();

            var result = htmlFormatter.FormatAsBold(content);

            // Specific
            // Assert.That(result, Contains.Substring("</strong>"));
            // Assert.That(result, Contains.Substring("<strong>Test</strong>"));
            Assert.That(result, Is.EqualTo($"<strong>{content}</strong>").IgnoreCase);

            // More general
            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>").IgnoreCase);
            Assert.That(result, Does.Contain(content).IgnoreCase);
        }
Exemplo n.º 32
0
        public void FormattersShouldNotThrowOnFormatting()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name = "TestBuildGroup";
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "DefaultConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name = "Mock";
            mockRule.type = typeof(MockRule).AssemblyQualifiedName;
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);
            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);

            // Execute the known formatters.
            BaseFormatter formatter;

            formatter = new ConsoleFormatter(null);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement htmlFileConfiguration = new formatterElement();

            htmlFileConfiguration.output.fileName   = "TestFormatterOutput.html";
            htmlFileConfiguration.output.launch     = false;
            htmlFileConfiguration.output.stylesheet = string.Empty;
            formatter = new HtmlFormatter(htmlFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement xmlFileConfiguration = new formatterElement();

            xmlFileConfiguration.output.fileName   = "TestFormatterOutput.xml";
            xmlFileConfiguration.output.launch     = false;
            xmlFileConfiguration.output.stylesheet = string.Empty;
            formatter = new XmlFormatter(xmlFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement csvFileConfiguration = new formatterElement();

            csvFileConfiguration.output.fileName = "TestFormatterOutput.csv";
            csvFileConfiguration.output.launch   = false;
            formatter = new CsvFormatter(csvFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
        }
Exemplo n.º 33
0
            public void Collection_properties_are_formatted_using_plain_text_formatting()
            {
                var writer = new StringWriter();

                var instance = new
                {
                    PropertyA = Enumerable.Range(1, 3)
                };

                var formatter = HtmlFormatter.GetBestFormatterFor(instance.GetType());

                formatter.Format(instance, writer);

                writer.ToString()
                .Should()
                .Contain("[ 1, 2, 3 ]");
            }
Exemplo n.º 34
0
        public void GivenAnHtmlFormatter_WhenFormattingAnAction_ThenFormatIsRespected()
        {
            var action = new Action()
            {
                name = "Touch",
                desc =
                    "Melee Weapon Attack: +4 to hit, reach 5 ft., one target. Hit: 7 (2d6) fire damage. If the target is a creature or a flammable object, it ignites. " +
                    "Until a creature takes an action to douse the fire, the creature takes 3 (1d6) fire damage at the end of each of its turns."
            };
            var expected =
                $"<p class=\"RWDefault\"><span class=\"RWSnippet\"><b><i>{action.name}.</i></b> <i>Melee Weapon Attack:</i> +4 to hit, reach 5 ft., one target. <i>Hit:</i> 7 (2d6) fire damage. If the target is a creature or a flammable object, it ignites. " +
                "Until a creature takes an action to douse the fire, the creature takes 3 (1d6) fire damage at the end of each of its turns.</span></p>";

            var actual = HtmlFormatter.Format(action);

            actual.Should().Be(expected);
        }
        private static HtmlTextBox CreateHtmlTextBoxFromDataTable(DataTable dataTable)
        {
            var fileName = Path.GetTempFileName();
            var fileStream = new FileStream(fileName, FileMode.OpenOrCreate);
            using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
            {
                var columnIndexes = new int[dataTable.Columns.Count];
                for (var i = 0; i < columnIndexes.Length; i++)
                    columnIndexes[i] = i;
                HtmlFormatter.Write(dataTable.DefaultView, columnIndexes, streamWriter);
            }

            var htmlTextBox = new HtmlTextBox();
            htmlTextBox.Navigate(fileName);

            return htmlTextBox;
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseStringWithStrongTag()
        {
            /* Testando String */
            var formater = new HtmlFormatter();
            var result   = formater.FormatAsBold("abc");

            // specific
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            //more general

            /*
             * Assert.That(result, Does.StartWith("<strong>"));
             * Assert.That(result, Does.EndWith("</strong>"));
             * Assert.That(result, Does.Contain("abc"));
             */
        }
Exemplo n.º 37
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            //Too Specific test is not mantainable
            //Assert.That(result, Is.EqualTo("<strong>abc</strong>"));

            //Too General, it pass by the bugs, all the tests will succeed
            //Assert.That(result, Does.StartWith("<strong>"));

            //Equilibrated
            Assert.That(result, Does.StartWith("<strong>"));
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 38
0
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement(string text)
        {
            //Arange
            var formatter = new HtmlFormatter();
            //Act
            var result = formatter.FormatAsBold("alabala");

            //Asert

            //Specific
            Assert.That(result, Is.EqualTo($"<strong>{text}</strong>").IgnoreCase);

            //General
            Assert.That(result, Does.StartWith("<strong>"));
            Assert.That(result, Does.EndWith("</strong>"));
            Assert.That(result, Does.Contain(text));
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();
            var result    = formatter.FormatAsBold("abc");

            //Specific assertion - veryfing the exact string we should get from the method (tests can break easily this way):
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            //More general

            /*Assert.That(result, Does.StartWith("<strong>"));
             *
             * //Better solution:
             * Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
             * Assert.That(result, Does.EndWith("</strong>"));
             * Assert.That(result, Does.Contain("abc"));*/
        }
        public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement()
        {
            var formatter = new HtmlFormatter();

            var result = formatter.FormatAsBold("abc");

            // Too specific - not good
            Assert.That(result, Is.EqualTo("<strong>abc</strong>").IgnoreCase);

            // Too general - not good
            // Assert.That(result, Does.StartWith("<strong>"));

            // Good test
            Assert.That(result, Does.StartWith("<strong>").IgnoreCase);
            Assert.That(result, Does.EndWith("</strong>").IgnoreCase);
            Assert.That(result, Does.Contain("abc"));
        }
Exemplo n.º 41
0
		public void Format_MixedEntities_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive(@"there should <b>e decoded chars & inside this text")
			    };
			const string expected = @"there should &lt;b&gt;e decoded chars &amp; inside this text";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 42
0
		public void Format_HtmlContentPrettyPrinted_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("div")),
			        MarkupGrammar.TokenAttribute(new DataName("class")),
			        MarkupGrammar.TokenPrimitive("content"),
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("p")),
			        MarkupGrammar.TokenAttribute(new DataName("style")),
			        MarkupGrammar.TokenPrimitive("color:red"),
			        MarkupGrammar.TokenPrimitive("\r\n\t\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("strong")),
			        MarkupGrammar.TokenPrimitive("Lorem ipsum"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive(" dolor sit amet, "),
			        MarkupGrammar.TokenElementBegin(new DataName("i")),
			        MarkupGrammar.TokenPrimitive("consectetur"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive(" adipiscing elit.\r\n\t"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n"),
					MarkupGrammar.TokenElementEnd,
			    };
			const string expected =
@"<div class=""content"">
	<p style=""color:red"">
		<strong>Lorem ipsum</strong> dolor sit amet, <i>consectetur</i> adipiscing elit.
	</p>
</div>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 43
0
		public void Format_UnopenedCloseTag_ReturnsMarkup()
		{
			var input = new []
				{
					MarkupGrammar.TokenElementEnd
				};
			const string expected = @"";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 44
0
		public void Format_OverlappingTagsAutoBalanced_ReturnsMarkupAsIs()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("odd")),
			        MarkupGrammar.TokenElementBegin(new DataName("auto-closed")),
			        MarkupGrammar.TokenElementBegin(new DataName("even")),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenElementEnd
			    };
			const string expected = @"<odd><auto-closed><even></even></auto-closed></odd>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 45
0
		public void Format_XmlDocTypeExternal_ReturnsUnparsed()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("!", "",
@"DOCTYPE html PUBLIC
	""-//W3C//DTD XHTML 1.1//EN""
	""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd""")
			    };
			const string expected =
@"<!DOCTYPE html PUBLIC
	""-//W3C//DTD XHTML 1.1//EN""
	""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 46
0
		public void Format_XmlEntityHex_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive("\uABCD")
			    };
			const string expected = "\uABCD";

			var formatter = new HtmlFormatter(new DataWriterSettings()) { EncodeNonAscii=false };
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 47
0
		public void Format_EmptyInput_ReturnsEmptySequence()
		{
			var input = new Token<MarkupTokenType>[0];
			const string expected = "";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 48
0
		public void Format_EntityWithTrailingText_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive("&"),
			        MarkupGrammar.TokenPrimitive("trailing")
			    };
			const string expected = @"&amp;trailing";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 49
0
		public void Format_IncompleteTag_ReturnsEmptyAttrib()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("div")),
			        MarkupGrammar.TokenAttribute(new DataName("test")),
			    };
			const string expected = @"<div test>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 50
0
		public void Format_XmlDeclaration_ReturnsUnparsed()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("?", "?", @"xml version=""1.0""")
			    };
			const string expected = @"<?xml version=""1.0""?>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 51
0
		//[Fact(Skip="Embedded DOCTYPE not supported")]
		public void Format_XmlDocTypeLocal_ReturnsUnparsed()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("!", "",
@"DOCTYPE doc [
	<!ATTLIST normId id ID #IMPLIED>
	<!ATTLIST normNames attr NMTOKENS #IMPLIED>
]")
			    };
			const string expected =
@"<!DOCTYPE doc [
	<!ATTLIST normId id ID #IMPLIED>
	<!ATTLIST normNames attr NMTOKENS #IMPLIED>
]>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 52
0
		public void Format_MarkupLikeText_ReturnsTextValue()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive(@"value>""0"" && value<""10"" ?""valid"":""error""")
			    };
			const string expected = @"value&gt;""0"" &amp;&amp; value&lt;""10"" ?""valid"":""error""";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 53
0
		public void Format_XmlEntityB_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive("B")
			    };
			const string expected = @"B";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 54
0
		public void Format_MathML_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("p")),
			        MarkupGrammar.TokenPrimitive(@"You can add a string to a number, but this stringifies the number:"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n"),
			        MarkupGrammar.TokenElementBegin(new DataName("math")),
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("ms")),
			        MarkupGrammar.TokenPrimitive(@"x<y"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("mo")),
			        MarkupGrammar.TokenPrimitive(@"+"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("mn")),
			        MarkupGrammar.TokenPrimitive(@"3"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("mo")),
			        MarkupGrammar.TokenPrimitive(@"="),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("ms")),
			        MarkupGrammar.TokenPrimitive(@"x<y3"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n"),
			        MarkupGrammar.TokenElementEnd,
			    };
			const string expected =
@"<p>You can add a string to a number, but this stringifies the number:</p>
<math>
	<ms>x&lt;y</ms>
	<mo>+</mo>
	<mn>3</mn>
	<mo>=</mo>
	<ms>x&lt;y3</ms>
</math>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 55
0
		public void Format_AspNetPageDeclaration_ReturnsUnparsed()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("%@", "%", @" Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""Default.aspx.cs"" Inherits=""Foo._Default"" ")
			    };
			const string expected = @"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""Default.aspx.cs"" Inherits=""Foo._Default"" %>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 56
0
		public void Format_XmlComment_ReturnsUnparsed()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("!--", "--", @" a quick note ")
			    };
			const string expected = @"<!-- a quick note -->";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 57
0
		public void Format_PhpHelloWorld_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("html")),
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("head")),
			        MarkupGrammar.TokenPrimitive("\r\n\t\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("title")),
			        MarkupGrammar.TokenPrimitive("PHP Test"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementBegin(new DataName("body")),
			        MarkupGrammar.TokenPrimitive("\r\n\t\t"),
			        MarkupGrammar.TokenUnparsed("?", "?", @"php echo '<p>Hello World</p>'; "),
			        MarkupGrammar.TokenPrimitive("\r\n\t"),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenPrimitive("\r\n"),
			        MarkupGrammar.TokenElementEnd,
			    };
			const string expected =
@"<html>
	<head>
		<title>PHP Test</title>
	</head>
	<body>
		<?php echo '<p>Hello World</p>'; ?>
	</body>
</html>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 58
0
		public void Format_CodeCommentAroundMarkup_ReturnsSingleUnparsedBlock()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenUnparsed("%--", "--%",
@"
<html>
	<body style=""color:lime"">
		<!-- not much to say here -->
	</body>
</html>
")
			    };
			const string expected =
@"<%--
<html>
	<body style=""color:lime"">
		<!-- not much to say here -->
	</body>
</html>
--%>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 59
0
		public void Format_OverlappingNamespacedTagsErrorRecovery_ReturnsAutoBalanced()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenElementBegin(new DataName("odd", "a", "http://example.com/odd/a")),
			        MarkupGrammar.TokenElementBegin(new DataName("auto-closed", "b", "http://example.com/auto-closed/b")),
			        MarkupGrammar.TokenElementBegin(new DataName("even", "c", "http://example.com/even/c")),
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenElementEnd,
			        MarkupGrammar.TokenElementEnd,
			    };
			const string expected = @"<a:odd xmlns:a=""http://example.com/odd/a""><b:auto-closed xmlns:b=""http://example.com/auto-closed/b""><c:even xmlns:c=""http://example.com/even/c""></c:even></b:auto-closed></a:odd>";

			var formatter = new HtmlFormatter(new DataWriterSettings());
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}
Exemplo n.º 60
0
		public void Format_HtmlEntityEuroEncodeNonAscii_ReturnsMarkup()
		{
			var input = new[]
			    {
			        MarkupGrammar.TokenPrimitive("€")
			    };
			const string expected = @"&#x20AC;";

			var formatter = new HtmlFormatter(new DataWriterSettings()) { EncodeNonAscii=true };
			var actual = formatter.Format(input);

			Assert.Equal(expected, actual);
		}