public void TestHtmlImplicitClosing ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse(@"
<html>
	<body>
		<li><li>$
		<dt><img><dd>$</dd>
		<tr><tr>$</tr></li>
		<p>
		<table>$</table>
		<td><th><td>$
	</body>
</html>
",
				delegate {
					parser.AssertPath ("//html/body/li");
				},
				delegate {
					parser.AssertPath ("//html/body/li/dd");
				},
				delegate {
					parser.AssertPath ("//html/body/li/tr");
				},
				delegate {
					parser.AssertPath ("//html/body/table");
				},
				delegate {
					parser.AssertPath ("//html/body/td");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (1);

		}
            public static Tuple<Library, IEnumerable<ParseError>> Parse(XmlReader reader)
            {
                var parser = new TestParser(reader);
                var library = parser.Library();

                return Tuple.Create(library, parser.Context.Errors.AsEnumerable());
            }
		public void TestAutoClosing ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<html>
	<body>
		<p><img>$
		<p><div> $ </div>
		<p>
		<p><a href =""http://mono-project.com/"" ><b>foo $ </a>
		<p>
		<p>$
		<div><div>$</div></div>
	</body>
</html>
",
				delegate {
					parser.AssertPath ("//html/body/p");
				},
				delegate {
					parser.AssertPath ("//html/body/div");
				},
				delegate {
					parser.AssertPath ("//html/body/p/a/b");
				},
				delegate {
					parser.AssertPath ("//html/body/p");
				},
				delegate {
					parser.AssertPath ("//html/body/div/div");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (8);
		}
    public void TestBufferOverflowSingleRun() {
      TestParser parser = new TestParser(128);

      Assert.Throws<Exceptions.RequestEntityTooLargeException>(
        delegate() { parser.AddBytes(createWhiteSpaceArray(129), 0, 129); }
      );
    }
 private TestParser GetTestParser(string input)
 {
     var lexer = new TestLexer2(input);
     var tokens = lexer.Tokens().ToList();
     var parser = new TestParser();
     parser.Initialize(tokens, lexer);
     return parser;
 }
		public void Attributes ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<tag.a name=""foo"" arg=5 wibble = 6 bar.baz = 'y.ff7]' $ />
</doc>
",
				delegate {
					parser.AssertStateIs<XmlTagState> ();
					parser.AssertAttributes ("name", "foo", "arg", "5", "wibble", "6", "bar.baz", "y.ff7]");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (0);
		}
		public void Directives ()
		{
			var parser = new TestParser (CreateRootState (), true);
			parser.Parse (@"<%@ Page Language=""C#"" Inherits=""SomeGenericType<int>"" %>");
			parser.AssertNoErrors ();
			var doc = (XDocument) parser.Nodes.Peek ();
			var directive = doc.Nodes.First () as AspNetDirective;
			Assert.NotNull (directive);
			Assert.AreEqual ("Page", directive.Name.FullName);
			Assert.AreEqual (2, directive.Attributes.Count ());
			var att = directive.Attributes[0];
			Assert.AreEqual ("Language", att.Name.FullName);
			Assert.AreEqual ("C#", att.Value);
			att = directive.Attributes[1];
			Assert.AreEqual ("Inherits", att.Name.FullName);
			Assert.AreEqual ("SomeGenericType<int>", att.Value);
		}
        public void OptionalElement_ParsesCorrectly()
        {
            string comment = "No book lending here!!!";

            var xml = BuildValidXml();

            xml.Add(new XElement("comment", comment));

            var r = XmlReader.Create(new StringReader(xml.ToString()));

            var results = TestParser.Parse(r);

            AssertErrorCount(0, results.Item2);

            var library = results.Item1;

            Assert.AreEqual(comment, library.Comment);
        }
        public void OptionalAttribute_ParsesCorrectly()
        {
            var lastUpdated = DateTime.Parse("01/28/2011");

            var xml = BuildValidXml();

            xml.Add(new XAttribute("lastUpdated", lastUpdated.ToString()));

            var r = XmlReader.Create(new StringReader(xml.ToString()));

            var results = TestParser.Parse(r);

            AssertErrorCount(0, results.Item2);

            var library = results.Item1;

            Assert.AreEqual(lastUpdated, library.LastUpdated.Value);
        }
        public void ExtensionsOrderedListWithAlphaLetter_Example003()
        {
            // Example 3
            // Section: Extensions / Ordered list with alpha letter
            //
            // The following Markdown:
            //     b. First item
            //     c. Second item
            //
            // Should be rendered as:
            //     <ol type="a" start="2">
            //     <li>First item</li>
            //     <li>Second item</li>
            //     </ol>

            Console.WriteLine("Example 3\nSection Extensions / Ordered list with alpha letter\n");
            TestParser.TestSpec("b. First item\nc. Second item", "<ol type=\"a\" start=\"2\">\n<li>First item</li>\n<li>Second item</li>\n</ol>", "listextras|advanced");
        }
Exemple #11
0
        public void UnexpectedElement_CanBeIgnoredAndParsingContinues()
        {
            var ignoredElement = new XElement("misc", "Here lies misc extra stuff!");

            var xml       = BuildValidXml();
            var firstBook = xml.Element("category")
                            .Element("book");

            firstBook.AddFirst(ignoredElement);

            var r       = XmlReader.Create(new StringReader(xml.ToString()));
            var results = TestParser.Parse(r);
            var library = results.Item1;

            Assert.AreEqual(firstBook.Attribute("title").Value, library.Categories[0].Books[0].Title);

            AssertErrorCount(0, results.Item2);
        }
        public void ExtensionsEmphasisOnHtmlEntities_Example006()
        {
            // Example 6
            // Section: Extensions / Emphasis on Html Entities
            //
            // The following Markdown:
            //     This is text MyBrand ^&reg;^ and MyTrademark ^&trade;^
            //     This is text MyBrand^&reg;^ and MyTrademark^&trade;^
            //     This is text MyBrand~&reg;~ and MyCopyright^&copy;^
            //
            // Should be rendered as:
            //     <p>This is text MyBrand <sup>®</sup> and MyTrademark <sup>TM</sup>
            //     This is text MyBrand<sup>®</sup> and MyTrademark<sup>TM</sup>
            //     This is text MyBrand<sub>®</sub> and MyCopyright<sup>©</sup></p>

            Console.WriteLine("Example 6\nSection Extensions / Emphasis on Html Entities\n");
            TestParser.TestSpec("This is text MyBrand ^&reg;^ and MyTrademark ^&trade;^\nThis is text MyBrand^&reg;^ and MyTrademark^&trade;^\nThis is text MyBrand~&reg;~ and MyCopyright^&copy;^", "<p>This is text MyBrand <sup>®</sup> and MyTrademark <sup>TM</sup>\nThis is text MyBrand<sup>®</sup> and MyTrademark<sup>TM</sup>\nThis is text MyBrand<sub>®</sub> and MyCopyright<sup>©</sup></p>", "emphasisextras|advanced");
        }
Exemple #13
0
        public void ExtensionsDefinitionLists_Example005()
        {
            // Example 5
            // Section: Extensions / Definition lists
            //
            // The following Markdown:
            //     Term 1
            //
            //         : Not valid
            //
            // Should be rendered as:
            //     <p>Term 1</p>
            //     <pre><code>: Not valid
            //     </code></pre>

            Console.WriteLine("Example 5\nSection Extensions / Definition lists\n");
            TestParser.TestSpec("Term 1\n\n    : Not valid", "<p>Term 1</p>\n<pre><code>: Not valid\n</code></pre>", "definitionlists+attributes|advanced");
        }
        public void ExtensionsBootstrap_Example003()
        {
            // Example 3
            // Section: Extensions / Bootstrap
            //
            // The following Markdown:
            //     ^^^
            //     This is a text in a caption
            //     ^^^ This is the caption
            //
            // Should be rendered as:
            //     <figure class="figure">
            //     <p>This is a text in a caption</p>
            //     <figcaption class="figure-caption">This is the caption</figcaption>
            //     </figure>

            TestParser.TestSpec("^^^\nThis is a text in a caption\n^^^ This is the caption", "<figure class=\"figure\">\n<p>This is a text in a caption</p>\n<figcaption class=\"figure-caption\">This is the caption</figcaption>\n</figure>", "bootstrap+pipetables+figures+attributes", context: "Example 3\nSection Extensions / Bootstrap\n");
        }
Exemple #15
0
        public void ExtensionsYAMLFrontmatterDiscard_Example004()
        {
            // Example 4
            // Section: Extensions / YAML frontmatter discard
            //
            // The following Markdown:
            //     ---
            //     this: is a frontmatter
            //
            //     ...
            //     This is a text
            //
            // Should be rendered as:
            //     <p>This is a text</p>

            Console.WriteLine("Example 4\nSection Extensions / YAML frontmatter discard\n");
            TestParser.TestSpec("---\nthis: is a frontmatter\n\n...\nThis is a text", "<p>This is a text</p>", "yaml");
        }
		public void AttributeName ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<tag.a>
		<tag.b id=""$foo"" />
	</tag.a>
</doc>
",
				delegate {
					parser.AssertStateIs<XmlDoubleQuotedAttributeValueState> ();
					parser.AssertPath ("//doc/tag.a/tag.b/@id");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (0);
		}
Exemple #17
0
        public void ExtensionsGenericAttributes_Example002()
        {
            // Example 2
            // Section: Extensions / Generic Attributes
            //
            // The following Markdown:
            //     {#fenced-id .fenced-class}
            //     ~~~
            //     This is a fenced with attached attributes
            //     ~~~
            //
            // Should be rendered as:
            //     <pre><code id="fenced-id" class="fenced-class">This is a fenced with attached attributes
            //     </code></pre>

            Console.WriteLine("Example 2\nSection Extensions / Generic Attributes\n");
            TestParser.TestSpec("{#fenced-id .fenced-class}\n~~~\nThis is a fenced with attached attributes\n~~~ ", "<pre><code id=\"fenced-id\" class=\"fenced-class\">This is a fenced with attached attributes\n</code></pre>", "attributes|advanced");
        }
        public void ExtensionsFigures_Example001()
        {
            // Example 1
            // Section: Extensions / Figures
            //
            // The following Markdown:
            //     ^^^
            //     This is a figure
            //     ^^^ This is a *caption*
            //
            // Should be rendered as:
            //     <figure>
            //     <p>This is a figure</p>
            //     <figcaption>This is a <em>caption</em></figcaption>
            //     </figure>

            TestParser.TestSpec("^^^\nThis is a figure\n^^^ This is a *caption*", "<figure>\n<p>This is a figure</p>\n<figcaption>This is a <em>caption</em></figcaption>\n</figure>", "figures+footers+citations|advanced", context: "Example 1\nSection Extensions / Figures\n");
        }
Exemple #19
0
        public void ExtensionsPipeTable_Example005()
        {
            // Example 5
            // Section: Extensions / Pipe Table
            //
            // The following Markdown:
            //     a b
            //     c | d
            //     e | f
            //
            // Should be rendered as:
            //     <p>a b
            //     c | d
            //     e | f</p>

            Console.WriteLine("Example 5\nSection Extensions / Pipe Table\n");
            TestParser.TestSpec("a b\nc | d\ne | f", "<p>a b\nc | d\ne | f</p>", "pipetables|advanced");
        }
Exemple #20
0
        public void ExtensionsDefinitionLists_Example004()
        {
            // Example 4
            // Section: Extensions / Definition lists
            //
            // The following Markdown:
            //     Term 1
            //        : Valid even if `:` starts at most 3 spaces
            //
            // Should be rendered as:
            //     <dl>
            //     <dt>Term 1</dt>
            //     <dd>Valid even if <code>:</code> starts at most 3 spaces</dd>
            //     </dl>

            Console.WriteLine("Example 4\nSection Extensions / Definition lists\n");
            TestParser.TestSpec("Term 1\n   : Valid even if `:` starts at most 3 spaces", "<dl>\n<dt>Term 1</dt>\n<dd>Valid even if <code>:</code> starts at most 3 spaces</dd>\n</dl>", "definitionlists+attributes|advanced");
        }
Exemple #21
0
        public void TestShouldNotRunOnBlacklistedPlatforms(string[] currentPlatforms, string[] platformBlacklist, bool expectedToRun)
        {
            TestParser      parser = new TestParser();
            SystemUnderTest system = new SystemUnderTest(
                runtimeVersion: Version.Parse("2.1"),
                sdkVersion: null,
                platformIds: currentPlatforms.ToList());
            TestDescriptor test = new TestDescriptor()
            {
                Enabled           = true,
                Version           = "2.1",
                PlatformBlacklist = platformBlacklist.ToList(),
            };

            var shouldRun = parser.ShouldRunTest(system, test);

            Assert.Equal(expectedToRun, shouldRun);
        }
        public void ExtensionsNoHTML_Example002()
        {
            // Example 2
            // Section: Extensions / NoHTML
            //
            // The following Markdown:
            //     <div>
            //     this is some text
            //     </div>
            //
            // Should be rendered as:
            //     <p>&lt;div&gt;
            //     this is some text
            //     &lt;/div&gt;</p>

            Console.WriteLine("Example 2\nSection Extensions / NoHTML\n");
            TestParser.TestSpec("<div>\nthis is some text\n</div>", "<p>&lt;div&gt;\nthis is some text\n&lt;/div&gt;</p>", "nohtml");
        }
Exemple #23
0
        public void VersionSpecificTestShouldBeRunForSameMajorMinorVersion(string version, bool expectedToRun)
        {
            TestParser      parser = new TestParser();
            SystemUnderTest system = new SystemUnderTest(
                runtimeVersion: Version.Parse(version),
                sdkVersion: null,
                platformIds: new List <string>());
            TestDescriptor test = new TestDescriptor()
            {
                Enabled         = true,
                VersionSpecific = true,
                Version         = "2.1",
            };

            var shouldRun = parser.ShouldRunTest(system, test);

            Assert.Equal(expectedToRun, shouldRun);
        }
Exemple #24
0
        public void ExtensionsAbbreviation_Example005()
        {
            // Example 5
            // Section: Extensions / Abbreviation
            //
            // The following Markdown:
            //     *[1A]: First
            //     *[1A1]: Second
            //     *[1A2]: Third
            //
            //     We can abbreviate 1A, 1A1 and 1A2!
            //
            // Should be rendered as:
            //     <p>We can abbreviate <abbr title="First">1A</abbr>, <abbr title="Second">1A1</abbr> and <abbr title="Third">1A2</abbr>!</p>

            Console.WriteLine("Example 5\nSection Extensions / Abbreviation\n");
            TestParser.TestSpec("*[1A]: First\n*[1A1]: Second\n*[1A2]: Third\n\nWe can abbreviate 1A, 1A1 and 1A2!", "<p>We can abbreviate <abbr title=\"First\">1A</abbr>, <abbr title=\"Second\">1A1</abbr> and <abbr title=\"Third\">1A2</abbr>!</p>", "abbreviations|advanced");
        }
        public void ExtensionsOrderedListWithRomanLetter_Example007()
        {
            // Example 7
            // Section: Extensions / Ordered list with roman letter
            //
            // The following Markdown:
            //     ii. First item
            //     iii. Second item
            //
            // Should be rendered as:
            //     <ol type="i" start="2">
            //     <li>First item</li>
            //     <li>Second item</li>
            //     </ol>

            Console.WriteLine("Example 7\nSection Extensions / Ordered list with roman letter\n");
            TestParser.TestSpec("ii. First item\niii. Second item", "<ol type=\"i\" start=\"2\">\n<li>First item</li>\n<li>Second item</li>\n</ol>", "listextras|advanced");
        }
Exemple #26
0
        public void ExtraElement_GeneratesErrorWhilePreservingFirstComment()
        {
            string comment = "No book lending here!!!";

            var xml = BuildValidXml();

            xml.Add(new XElement("comment", comment));
            xml.Add(new XElement("comment", "This should cause an error!!!"));

            var r = XmlReader.Create(new StringReader(xml.ToString()));

            var results = TestParser.Parse(r);
            var library = results.Item1;

            Assert.AreEqual(comment, library.Comment);

            AssertErrorCount(1, results.Item2);
        }
Exemple #27
0
        public void ExtensionsYAMLFrontmatterDiscard_Example003()
        {
            // Example 3
            // Section: Extensions / YAML frontmatter discard
            //
            // The following Markdown:
            //     ----
            //     this: is a frontmatter
            //     ----
            //     This is a text
            //
            // Should be rendered as:
            //     <hr />
            //     <h2>this: is a frontmatter</h2>
            //     <p>This is a text</p>

            TestParser.TestSpec("----\nthis: is a frontmatter\n----\nThis is a text", "<hr />\n<h2>this: is a frontmatter</h2>\n<p>This is a text</p>", "yaml", context: "Example 3\nSection Extensions / YAML frontmatter discard\n");
        }
        public void ExtensionsPipeTable_Example024()
        {
            // Example 24
            // Section: Extensions / Pipe Table
            //
            // The following Markdown:
            //     | abc | def |
            //     |---|---|
            //     | cde| ddd|
            //     | eee| fff|
            //     | fff | fffff   |
            //     |gggg  | ffff |
            //
            // Should be rendered as:
            //     <table>
            //     <thead>
            //     <tr>
            //     <th>abc</th>
            //     <th>def</th>
            //     </tr>
            //     </thead>
            //     <tbody>
            //     <tr>
            //     <td>cde</td>
            //     <td>ddd</td>
            //     </tr>
            //     <tr>
            //     <td>eee</td>
            //     <td>fff</td>
            //     </tr>
            //     <tr>
            //     <td>fff</td>
            //     <td>fffff</td>
            //     </tr>
            //     <tr>
            //     <td>gggg</td>
            //     <td>ffff</td>
            //     </tr>
            //     </tbody>
            //     </table>

            Console.WriteLine("Example 24\nSection Extensions / Pipe Table\n");
            TestParser.TestSpec("| abc | def | \n|---|---|\n| cde| ddd| \n| eee| fff|\n| fff | fffff   | \n|gggg  | ffff | ", "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>cde</td>\n<td>ddd</td>\n</tr>\n<tr>\n<td>eee</td>\n<td>fff</td>\n</tr>\n<tr>\n<td>fff</td>\n<td>fffff</td>\n</tr>\n<tr>\n<td>gggg</td>\n<td>ffff</td>\n</tr>\n</tbody>\n</table>", "pipetables|advanced");
        }
Exemple #29
0
        public void ExtensionsGlobalization_Example004()
        {
            // Example 4
            // Section: Extensions / Globalization
            //
            // The following Markdown:
            //     Foo میوە
            //
            //     میوە bar
            //
            //     Baz میوە
            //
            // Should be rendered as:
            //     <p>Foo میوە</p>
            //     <p dir="rtl">میوە bar</p>
            //     <p>Baz میوە</p>

            TestParser.TestSpec("Foo میوە\n\nمیوە bar\n\nBaz میوە", "<p>Foo میوە</p>\n<p dir=\"rtl\">میوە bar</p>\n<p>Baz میوە</p>", "globalization+advanced+emojis", context: "Example 4\nSection Extensions / Globalization\n");
        }
Exemple #30
0
        public void SingleTestParser()
        {
            IImpliedModelParser modelParser = new TestParser();
            IModel model = new CobolModel("Parent", "NAME SHOULD SEPARATE TEST DATA 1", "This is test data");

            Assert.That(modelParser.Matches(model), Is.True);

            IModel child = modelParser.Parse(model);

            Assert.That(child, Is.Not.Null);
            Assert.That(child, Is.Not.SameAs(model));

            IModel expected = new HierarchyModel(new CobolModel("Parent", "NAME SHOULD SEPARATE", "This is test data"), new IModel[]
            {
                new CobolModel("Test", "TEST DATA 1", "Implied")
            });

            AssertModelIsSame(child, expected, true);
        }
Exemple #31
0
        public void UnexpectedElement_GeneratesErrorAndParsingContinues()
        {
            var badElement = new XElement("bad",
                                          new XAttribute("message", "I am not expected!"),
                                          new XElement("additionalMessages",
                                                       new XElement("message", "Mwwwahahahaha!")));

            var xml = BuildValidXml();

            xml.AddFirst(badElement);

            var r       = XmlReader.Create(new StringReader(xml.ToString()));
            var results = TestParser.Parse(r);
            var library = results.Item1;

            Assert.AreEqual(xml.Elements("category").Count(), library.Categories.Count);

            AssertErrorCount(1, results.Item2);
        }
        public void ExtensionsPipeTable_Example007()
        {
            // Example 7
            // Section: Extensions / Pipe Table
            //
            // The following Markdown:
            //     a  | b
            //     -- | --
            //     0  | 1 | 2
            //     3  | 4
            //     5  |
            //
            // Should be rendered as:
            //     <table>
            //     <thead>
            //     <tr>
            //     <th>a</th>
            //     <th>b</th>
            //     <th></th>
            //     </tr>
            //     </thead>
            //     <tbody>
            //     <tr>
            //     <td>0</td>
            //     <td>1</td>
            //     <td>2</td>
            //     </tr>
            //     <tr>
            //     <td>3</td>
            //     <td>4</td>
            //     <td></td>
            //     </tr>
            //     <tr>
            //     <td>5</td>
            //     <td></td>
            //     <td></td>
            //     </tr>
            //     </tbody>
            //     </table>

            Console.WriteLine("Example 7\nSection Extensions / Pipe Table\n");
            TestParser.TestSpec("a  | b \n-- | --\n0  | 1 | 2\n3  | 4\n5  |", "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0</td>\n<td>1</td>\n<td>2</td>\n</tr>\n<tr>\n<td>3</td>\n<td>4</td>\n<td></td>\n</tr>\n<tr>\n<td>5</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>", "pipetables|advanced");
        }
Exemple #33
0
        public void Calculate_NoPreprocessorDirectoryWhenRequired_ThrowsInvalidOperationException()
        {
            // Setup
            var parser     = new TestParser();
            var settings   = new HydraRingCalculationSettings("D:\\hlcd.sqlite", string.Empty, false);
            var calculator = new TestHydraRingCalculator(settings, parser);
            var hydraRingCalculationInput = new TestHydraRingCalculationInput
            {
                PreprocessorSetting = new PreprocessorSetting(1, 2, new NumericsSetting(1, 4, 50, 0.15, 0.05, 0.01, 0.01, 0, 2, 20000, 100000, 0.1, -6, 6))
            };

            // Call
            void Call() => calculator.PublicCalculate(hydraRingCalculationInput);

            // Assert
            string message = Assert.Throws <InvalidOperationException>(Call).Message;

            Assert.AreEqual("Preprocessor directory required but not specified.", message);
        }
Exemple #34
0
        public void ExtensionsGenericAttributes_Example003()
        {
            // Example 3
            // Section: Extensions / Generic Attributes
            //
            // The following Markdown:
            //     [Foo](url){data-x=1}
            //
            //     [Foo](url){data-x='1'}
            //
            //     [Foo](url){data-x=11}
            //
            // Should be rendered as:
            //     <p><a href="url" data-x="1">Foo</a></p>
            //     <p><a href="url" data-x="1">Foo</a></p>
            //     <p><a href="url" data-x="11">Foo</a></p>

            TestParser.TestSpec("[Foo](url){data-x=1}\n\n[Foo](url){data-x='1'}\n\n[Foo](url){data-x=11}", "<p><a href=\"url\" data-x=\"1\">Foo</a></p>\n<p><a href=\"url\" data-x=\"1\">Foo</a></p>\n<p><a href=\"url\" data-x=\"11\">Foo</a></p>", "attributes|advanced", context: "Example 3\nSection Extensions / Generic Attributes\n");
        }
Exemple #35
0
        public void ExtensionsPipeTable_Example017()
        {
            // Example 17
            // Section: Extensions / Pipe Table
            //
            // The following Markdown:
            //      a     | b
            //     -------|---x---
            //      0     | 1
            //      2     | 3
            //
            // Should be rendered as:
            //     <p>a     | b
            //     -------|---x---
            //     0     | 1
            //     2     | 3</p>

            TestParser.TestSpec(" a     | b\n-------|---x---\n 0     | 1\n 2     | 3 ", "<p>a     | b\n-------|---x---\n0     | 1\n2     | 3</p> ", "pipetables|advanced", context: "Example 17\nSection Extensions / Pipe Table\n");
        }
Exemple #36
0
        public void ExtensionsForms_Example003()
        {
            // Example 3
            // Section: Extensions / Forms
            //
            // The following Markdown:
            //     city = {BOS, SFO, (NYC)}
            //
            // Should be rendered as:
            //     <label for="city">City:</label>
            //     <select id="city" name="city">
            //       <option value="BOS">BOS</option>
            //       <option value="SFO">SFO</option>
            //       <option value="NYC" selected="selected">NYC</option>
            //     </select>

            Console.WriteLine("Example 3\nSection Extensions / Forms\n");
            TestParser.TestSpec("city = {BOS, SFO, (NYC)}", "<label for=\"city\">City:</label>\n<select id=\"city\" name=\"city\">\n  <option value=\"BOS\">BOS</option>\n  <option value=\"SFO\">SFO</option>\n  <option value=\"NYC\" selected=\"selected\">NYC</option>\n</select>", "forms|advanced");
        }
Exemple #37
0
        public void ExtensionsAutoLinksGFMSupport_Example015()
        {
            // Example 15
            // Section: Extensions / AutoLinks / GFM Support
            //
            // The following Markdown:
            //     http://commonmark.org
            //
            //     (Visit https://encrypted.google.com/search?q=Markup+(business))
            //
            //     Anonymous FTP is available at ftp://foo.bar.baz.
            //
            // Should be rendered as:
            //     <p><a href="http://commonmark.org">http://commonmark.org</a></p>
            //     <p>(Visit <a href="https://encrypted.google.com/search?q=Markup+(business)">https://encrypted.google.com/search?q=Markup+(business)</a>)</p>
            //     <p>Anonymous FTP is available at <a href="ftp://foo.bar.baz">ftp://foo.bar.baz</a>.</p>

            TestParser.TestSpec("http://commonmark.org\n\n(Visit https://encrypted.google.com/search?q=Markup+(business))\n\nAnonymous FTP is available at ftp://foo.bar.baz.", "<p><a href=\"http://commonmark.org\">http://commonmark.org</a></p>\n<p>(Visit <a href=\"https://encrypted.google.com/search?q=Markup+(business)\">https://encrypted.google.com/search?q=Markup+(business)</a>)</p>\n<p>Anonymous FTP is available at <a href=\"ftp://foo.bar.baz\">ftp://foo.bar.baz</a>.</p>", "autolinks|advanced", context: "Example 15\nSection Extensions / AutoLinks / GFM Support\n");
        }
Exemple #38
0
        public void SdkTestsShouldRunOnlyWithSdk(string sdkVersion, bool requiresSdk, bool expectedToRun)
        {
            TestParser      parser = new TestParser();
            SystemUnderTest system = new SystemUnderTest(
                runtimeVersion: Version.Parse("3.1"),
                sdkVersion: Version.Parse(sdkVersion),
                platformIds: new List <string>());
            TestDescriptor test = new TestDescriptor()
            {
                Enabled         = true,
                RequiresSdk     = requiresSdk,
                VersionSpecific = false,
                Version         = "2.1",
            };

            var shouldRun = parser.ShouldRunTest(system, test);

            Assert.Equal(expectedToRun, shouldRun);
        }
		public void AttributeWithExpression ()
		{
			var parser = new TestParser (CreateRootState (), true);
			parser.Parse (@"<tag
foo='<%=5$%>'
bar=""<%$$5$%><%--$--%>""
baz='<%#5$%>=<%:fhfjhf %0 $%>'
quux = <% 5 $%>  />", delegate {
				parser.AssertNodeIs<AspNetRenderExpression> ();
			}, delegate {
				parser.AssertNodeIs<AspNetResourceExpression> ();
			}, delegate {
				parser.AssertNodeIs<AspNetServerComment> ();
			}, delegate {
				parser.AssertNodeIs<AspNetDataBindingExpression> ();
			}, delegate {
				parser.AssertNodeIs<AspNetHtmlEncodedExpression> ();
			}, delegate {
				parser.AssertNodeIs<AspNetRenderBlock> ();
			});
			parser.AssertNoErrors ();
			var doc = (XDocument) parser.Nodes.Peek ();
		}
    public void TestExampleRequestWithStartIndex() {
      TestParser parser = new TestParser(512);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);
      byte[] paddedRequestData = createWhiteSpaceArray(requestData.Length + 512);
      Array.Copy(requestData, 0, paddedRequestData, 512, requestData.Length);

      parser.AddBytes(paddedRequestData, 512, requestData.Length);
    }
    public void TestSplitLineEndRecognition() {
      TestParser parser = new TestParser(128);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);
      int crIndex = Array.IndexOf<byte>(requestData, 13);
      System.Diagnostics.Trace.Assert(crIndex != -1);

      parser.AddBytes(requestData, 0, crIndex + 1);
      Assert.Throws<Exceptions.RequestEntityTooLargeException>(
        delegate() {
          parser.AddBytes(requestData, crIndex + 1, requestData.Length - crIndex);
        }
      );
    }
		public void Misc ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<!DOCTYPE $  >
	<![CDATA[ ]  $ ]  ]]>
	<!--   <foo> <bar arg=""> $  -->
</doc>
",
				delegate {
					parser.AssertStateIs<XmlDocTypeState> ();
					parser.AssertNodeDepth (3);
					parser.AssertPath ("//doc/<!DOCTYPE>");
				},
				delegate {
					parser.AssertStateIs<XmlCDataState> ();
					parser.AssertNodeDepth (3);
					parser.AssertPath ("//doc/<![CDATA[ ]]>");
				},
				delegate {
					parser.AssertStateIs<XmlCommentState> ();
					parser.AssertNodeDepth (3);
					parser.AssertPath ("//doc/<!-- -->");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (0);
		}
		public void DocTypeCapture ()
		{
			TestParser parser = new TestParser (CreateRootState (), true);
			parser.Parse (@"
		<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN""
""DTD/xhtml1-strict.dtd""
[
<!-- foo -->
<!bar #baz>
]>
<doc><foo/></doc>");
			parser.AssertEmpty ();
			XDocument doc = (XDocument)parser.Nodes.Peek ();
			Assert.IsTrue (doc.FirstChild is XDocType);
			XDocType dt = (XDocType) doc.FirstChild;
			Assert.AreEqual ("html", dt.RootElement.FullName);
			Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", dt.PublicFpi);
			Assert.AreEqual ("DTD/xhtml1-strict.dtd", dt.Uri);
			Assert.AreEqual (dt.InternalDeclarationRegion.Start.Line, 4);
			Assert.AreEqual (dt.InternalDeclarationRegion.End.Line, 7);
			parser.AssertNoErrors ();
		}
    public void TestIncompleteLineParsing() {
      TestParser parser = new TestParser(128);

      byte[] requestData = Encoding.ASCII.GetBytes("This is a boring test string");
      parser.ProcessBytes(requestData, 0, requestData.Length);

      Assert.AreEqual(0, parser.ParsedLineCount);
    }
		public void Unclosed ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<tag.a>
		<tag.b><tag.b>$
	</tag.a>$
</doc>
",
				delegate {
					parser.AssertStateIs<XmlFreeState> ();
					parser.AssertNodeDepth (5);
					parser.AssertPath ("//doc/tag.a/tag.b/tag.b");
				},
				delegate {
					parser.AssertStateIs<XmlFreeState> ();
					parser.AssertNodeDepth (2);
					parser.AssertPath ("//doc");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (2);
		}
    public void TestExampleRequest() {
      TestParser parser = new TestParser(512);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);

      parser.AddBytes(requestData, 0, requestData.Length);
    }
    public void TestReset() {
      byte[] beginning = Encoding.ASCII.GetBytes("This is a test\r");
      byte[] ending = Encoding.ASCII.GetBytes("\nA real test\r\n");

      TestParser parser = new TestParser(128);
      parser.SetReceivedData(beginning, 0, beginning.Length);

      Assert.IsNull(parser.ParseLine());
      parser.Reset();

      // If the Reset() didn't work, the parser would now complain that it discovered
      // a lone carriage return inmidst of the data stream
      parser.SetReceivedData(beginning, 0, beginning.Length);
      Assert.IsNull(parser.ParseLine());

      parser.SetReceivedData(ending, 0, ending.Length);
      Assert.AreEqual("This is a test", parser.ParseLine());
      Assert.AreEqual("A real test", parser.ParseLine());
      Assert.IsNull(parser.ParseLine());
    }
    public void TestSlightlyTooLargeSplitMessage() {
      byte[] slightlyTooLargeData = Encoding.ASCII.GetBytes(
        new string(' ', 30) + "\r\n" +
        new string(' ', 30) + "\r\n" +
        new string(' ', 31) + "\r\n"
      );

      TestParser parser = new TestParser(96);
      parser.SetReceivedData(slightlyTooLargeData, 0, slightlyTooLargeData.Length);

      Assert.AreEqual(new string(' ', 30), parser.ParseLine());
      Assert.AreEqual(new string(' ', 30), parser.ParseLine());
      Assert.Throws<InsufficientMemoryException>(
        delegate() { Console.WriteLine(parser.ParseLine()); }
      );
    }
		public void NamespacedAttributes ()
		{
			var parser = new TestParser (CreateRootState (), true);
			parser.Parse (@"<tag foo:bar='1' foo:bar:baz='2' foo='3' />");
			parser.AssertEmpty ();
			var doc = (XDocument) parser.Nodes.Peek ();
			var el = (XElement) doc.FirstChild;
			Assert.AreEqual (3, el.Attributes.Count ());
			Assert.AreEqual ("foo", el.Attributes.ElementAt (0).Name.Prefix);
			Assert.AreEqual ("bar", el.Attributes.ElementAt (0).Name.Name);
			Assert.AreEqual ("foo", el.Attributes.ElementAt (1).Name.Prefix);
			Assert.AreEqual ("bar:baz", el.Attributes.ElementAt (1).Name.Name);
			Assert.IsNull (el.Attributes.ElementAt (2).Name.Prefix);
			Assert.AreEqual ("foo", el.Attributes.ElementAt (2).Name.Name);
			Assert.AreEqual (3, el.Attributes.Count ());
			parser.AssertErrorCount (1);
			Assert.AreEqual (1, parser.Errors [0].Region.BeginLine);
			Assert.AreEqual (25, parser.Errors [0].Region.BeginColumn);
		}
    public void TestSplitLine() {
      byte[] firstPart = Encoding.ASCII.GetBytes("This ");
      byte[] secondPart = Encoding.ASCII.GetBytes("is a ");
      byte[] thirdPart = Encoding.ASCII.GetBytes("test\r\n");

      TestParser parser = new TestParser(64);

      parser.SetReceivedData(firstPart, 0, firstPart.Length);
      Assert.IsNull(parser.ParseLine());

      parser.SetReceivedData(secondPart, 0, secondPart.Length);
      Assert.IsNull(parser.ParseLine());

      parser.SetReceivedData(thirdPart, 0, thirdPart.Length);
      Assert.AreEqual("This is a test", parser.ParseLine());
      Assert.IsNull(parser.ParseLine());
    }
    public void TestLargeMessage() {
      byte[] firstPart = Encoding.ASCII.GetBytes(new string(' ', 128));
      byte[] secondPart = Encoding.ASCII.GetBytes("This is a test\r\n");

      TestParser parser = new TestParser(192);

      parser.SetReceivedData(firstPart, 0, firstPart.Length);
      Assert.IsNull(parser.ParseLine());

      parser.SetReceivedData(secondPart, 0, secondPart.Length);
      Assert.AreEqual(new string(' ', 128) + "This is a test", parser.ParseLine());
      Assert.IsNull(parser.ParseLine());
    }
    public void TestRemainingDataRetrieval() {
      byte[] binaryData = new byte[9] {
        0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
      };

      byte[] requestData = Encoding.ASCII.GetBytes("This is a test\r\n123456789");
      for(int index = 0; index < 9; ++index) {
        requestData[index + 16] = binaryData[index];
      }

      TestParser parser = new TestParser(128);
      parser.SetReceivedData(requestData, 0, requestData.Length);

      Assert.AreEqual("This is a test", parser.ParseLine());
      Assert.IsTrue(
        arraySegmentContentsAreEqual(
          new ArraySegment<byte>(binaryData, 0, 9),
          parser.GetRemainingData()
        )
      );
    }
		public void AttributeRecovery ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<tag.a>
		<tag.b arg='fff' sdd = sdsds= 'foo' ff $ />
	</tag.a>
<a><b valid/></a>
</doc>
",
				delegate {
					parser.AssertStateIs<XmlTagState> ();
					parser.AssertAttributes ("arg", "fff", "sdd", "", "sdsds", "foo", "ff", "");
					parser.AssertErrorCount (1);
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (1);
		}
    public void TestLoneCarriageReturn() {
      byte[] badData = Encoding.ASCII.GetBytes("First line\r\nThis is a \r test");

      TestParser parser = new TestParser(64);
      parser.SetReceivedData(badData, 0, badData.Length);

      Assert.AreEqual("First line", parser.ParseLine());
      Assert.Throws<FormatException>(
        delegate() { parser.ParseLine(); }
      );
    }
    public void TestBarelyFittingMessage() {
      byte[] barelyFittingData = Encoding.ASCII.GetBytes(
        new string(' ', 62) + "\r\n"
      );

      TestParser parser = new TestParser(64);
      parser.SetReceivedData(barelyFittingData, 0, barelyFittingData.Length);
      Assert.AreEqual(new string(' ', 62), parser.ParseLine());
      Assert.IsNull(parser.ParseLine());
    }
		public void IncompleteTags ()
		{
			TestParser parser = new TestParser (CreateRootState ());
			parser.Parse (@"
<doc>
	<tag.a att1 >
		<tag.b att2="" >
			<tag.c att3 = ' 
				<tag.d att4 = >
					<tag.e att5='' att6=' att7 = >
						<tag.f id='$foo' />
					</tag.e>
				</tag.d>
			</tag.c>
		</tag.b>
	</tag.a>
</doc>
",
				delegate {
					parser.AssertStateIs<XmlSingleQuotedAttributeValueState> ();
					parser.AssertNodeDepth (9);
					parser.AssertPath ("//doc/tag.a/tag.b/tag.c/tag.d/tag.e/tag.f/@id");
				}
			);
			parser.AssertEmpty ();
			parser.AssertErrorCount (3, x => x.ErrorType == ErrorType.Error);
			parser.AssertErrorCount (2, x => x.ErrorType == ErrorType.Warning);
		}
    public void TestInvalidCharactersInRequest() {
      TestParser parser = new TestParser(128);

      byte[] requestData = Encoding.ASCII.GetBytes("GET /something HTTP/1.1\r\n");
      requestData[6] = 10;
      requestData[9] = 13;

      Assert.Throws<Exceptions.BadRequestException>(
        delegate() { parser.AddBytes(requestData, 0, requestData.Length); }
      );
    }
		public void Init ()
		{
			parser = new TestParser (new RazorTestFreeState ());
		}
    public void TestFarTooLargeSplitMessage() {
      byte[] farTooLargeData = Encoding.ASCII.GetBytes(new string(' ', 128));

      TestParser parser = new TestParser(64);
      parser.SetReceivedData(farTooLargeData, 0, farTooLargeData.Length);

      Assert.Throws<InsufficientMemoryException>(
        delegate() { Console.WriteLine(parser.ParseLine()); }
      );
    }
    public void TestLoneCarriageReturnInSplitStream() {
      byte[] badData = Encoding.ASCII.GetBytes("This is a test\r");

      TestParser parser = new TestParser(128);

      // Parse a chunk of data that leaves an open-ended carriage return. No exception
      // should be thrown here because the next chunk the parser get might start
      // with a line feed, thus forming a valid line.
      try {
        parser.SetReceivedData(badData, 0, badData.Length);
        Assert.IsNull(parser.ParseLine());
      }
      catch(FormatException) {
        Assert.Fail("Line parser complained about what could yet become a valid line");
      }

      // Parse the same thing again. Now the parser should notice that the carriage
      // return wasn't followed by a line feed and legitimately complain.
      parser.SetReceivedData(badData, 0, badData.Length);
      Assert.Throws<FormatException>(
        delegate() { parser.ParseLine(); }
      );
    }