<commit_before>﻿// Copyright (c) <NAME>. All rights reserved.
// This file is licensed under the BSD-Clause 2 license. 
// See the license.txt file in the project root for more information.
using System;
using System.Linq;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using NUnit.Framework;

namespace Markdig.Tests
{
    [TestFixture]
    public class TestPlayParser
    {
        [Test]
        public void TestSimple()
        {
            var text = @" *[HTML]: Hypertext Markup Language

Later in a text we are using HTML and it becomes an abbr tag HTML
";

            //            var reader = new StringReader(@"> > toto tata
            //> titi toto
            //");

            //var result = Markdown.ToHtml(text, new MarkdownPipeline().UseFootnotes().UseEmphasisExtras());
            var result = Markdown.ToHtml(text, new MarkdownPipelineBuilder().UseAbbreviations().Build());
            //File.WriteAllText("test.html", result, Encoding.UTF8);
            Console.WriteLine(result);
        }

        [Test]
        public void TestEmptyLiteral()
        {
            var text = @"> *some text* 
> some other text";
            var doc = Markdown.Parse(text);

            Assert.True(doc.Descendants().OfType<LiteralInline>().All(x => !x.Content.IsEmpty),
                "There should not have any empty literals");
        }

        [Test]
        public void TestSelfPipeline1()
        {
            var text = @" <!--markdig:pipetables-->

a | b
- | -
0 | 1
";
            TestParser.TestSpec(text, @"<!--markdig:pipetables-->
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
", "self");
        }

        [Test]
        public void TestListBug()
        {
            // TODO: Add this test back to the CommonMark specs
            var text = @"- item1
  - item2
    - item3
      - item4";
            TestParser.TestSpec(text, @"<ul>
<li>item1
<ul>
<li>item2
<ul>
<li>item3
<ul>
<li>item4</li>
</ul></li>
</ul></li>
</ul></li>
</ul>
");
        }


        [Test]
        public void TestHtmlBug()
        {
            TestParser.TestSpec(@" # header1

<pre class='copy'>
blabla
</pre>

# header2
", @"<h1>header1</h1>
<pre class='copy'>
blabla
</pre>
<h1>header2</h1>");
        }


        [Test]
        public void TestStandardUriEscape()
        {
            TestParser.TestSpec(@"![你好](你好.png)", "<p><img src=\"你好.png\" alt=\"你好\" /></p>", "nonascii-noescape");
        }


        [Test]
        public void TestBugAdvanced()
        {
            TestParser.TestSpec(@"`https://{domain}/callbacks`
#### HEADING
Paragraph
", "<p><code>https://{domain}/callbacks</code></p>\n<h4 id=\"heading\">HEADING</h4>\n<p>Paragraph</p>", "advanced");
        }


        [Test]
        public void TestBugEmphAttribute()
        {
            // https://github.com/lunet-io/markdig/issues/108
            TestParser.TestSpec(@"*test*{name=value}", "<p><em name=\"value\">test</em></p>", "advanced");
        }

        [Test]
        public void TestBugPipeTables()
        {
            // https://github.com/lunet-io/markdig/issues/73
            TestParser.TestSpec(@"| abc | def |
| --- | --- |
| 1 | ~3 |
", @"<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>~3</td>
</tr>
</tbody>
</table>", "advanced");
        }

        [Test]
        public void TestGridTableWithCustomAttributes() {

            var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

            var input = @"
{.table}
+---+---+
| a | b |
+===+===+
| 1 | 2 |
+---+---+
";

            var expected = @"<table class=""table"">
<col style=""width:50%"">
<col style=""width:50%"">
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
";
            var result = Markdown.ToHtml(input, pipeline);
            Assert.AreEqual(result, expected);
        }

        [Test]<commit_msg>Use TestParser.TestSpec instead to mitigate problem with \r<commit_after>﻿// Copyright (c) <NAME>. All rights reserved.
// This file is licensed under the BSD-Clause 2 license. 
// See the license.txt file in the project root for more information.
using System;
using System.Linq;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using NUnit.Framework;

namespace Markdig.Tests
{
    [TestFixture]
    public class TestPlayParser
    {
        [Test]
        public void TestSimple()
        {
            var text = @" *[HTML]: Hypertext Markup Language

Later in a text we are using HTML and it becomes an abbr tag HTML
";

            //            var reader = new StringReader(@"> > toto tata
            //> titi toto
            //");

            //var result = Markdown.ToHtml(text, new MarkdownPipeline().UseFootnotes().UseEmphasisExtras());
            var result = Markdown.ToHtml(text, new MarkdownPipelineBuilder().UseAbbreviations().Build());
            //File.WriteAllText("test.html", result, Encoding.UTF8);
            Console.WriteLine(result);
        }

        [Test]
        public void TestEmptyLiteral()
        {
            var text = @"> *some text* 
> some other text";
            var doc = Markdown.Parse(text);

            Assert.True(doc.Descendants().OfType<LiteralInline>().All(x => !x.Content.IsEmpty),
                "There should not have any empty literals");
        }

        [Test]
        public void TestSelfPipeline1()
        {
            var text = @" <!--markdig:pipetables-->

a | b
- | -
0 | 1
";
            TestParser.TestSpec(text, @"<!--markdig:pipetables-->
<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
", "self");
        }

        [Test]
        public void TestListBug()
        {
            // TODO: Add this test back to the CommonMark specs
            var text = @"- item1
  - item2
    - item3
      - item4";
            TestParser.TestSpec(text, @"<ul>
<li>item1
<ul>
<li>item2
<ul>
<li>item3
<ul>
<li>item4</li>
</ul></li>
</ul></li>
</ul></li>
</ul>
");
        }


        [Test]
        public void TestHtmlBug()
        {
            TestParser.TestSpec(@" # header1

<pre class='copy'>
blabla
</pre>

# header2
", @"<h1>header1</h1>
<pre class='copy'>
blabla
</pre>
<h1>header2</h1>");
        }


        [Test]
        public void TestStandardUriEscape()
        {
            TestParser.TestSpec(@"![你好](你好.png)", "<p><img src=\"你好.png\" alt=\"你好\" /></p>", "nonascii-noescape");
        }


        [Test]
        public void TestBugAdvanced()
        {
            TestParser.TestSpec(@"`https://{domain}/callbacks`
#### HEADING
Paragraph
", "<p><code>https://{domain}/callbacks</code></p>\n<h4 id=\"heading\">HEADING</h4>\n<p>Paragraph</p>", "advanced");
        }


        [Test]
        public void TestBugEmphAttribute()
        {
            // https://github.com/lunet-io/markdig/issues/108
            TestParser.TestSpec(@"*test*{name=value}", "<p><em name=\"value\">test</em></p>", "advanced");
        }

        [Test]
        public void TestBugPipeTables()
        {
            // https://github.com/lunet-io/markdig/issues/73
            TestParser.TestSpec(@"| abc | def |
| --- | --- |
| 1 | ~3 |
", @"<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>~3</td>
</tr>
</tbody>
</table>", "advanced");
        }

        [Test]
        public void TestGridTableWithCustomAttributes() {

            var input = @"
{.table}
+---+---+
| a | b |
+===+===+
| 1 | 2 |
+---+---+
";

            var expected = @"<table class=""table"">
<col style=""width:50%"">
<col style=""width:50%"">
<thead>
<tr>
<th>a</th>
<th>b</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
";
            TestParser.TestSpec(input, expected, "advanced");
        }

        [Test]
{'fraction_non_alphanumeric': 0.18872953420484834, 'fraction_numerical': 0.010661251427846173, 'mean_word_length': 2.0962671905697445, 'pattern_counts': {'":': 0, '<': 201, '<?xml version=': 0, '>': 213, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522119', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2633, 'n_words': 573}