<commit_before>﻿namespace AngleSharp.Core.Tests
{
    using AngleSharp;
    using AngleSharp.Core.Tests.Mocks;
    using AngleSharp.Parser.Css;
    using AngleSharp.Parser.Html;
    using NUnit.Framework;
    using System.Text;

    [TestFixture]
    public class AsyncParsingTests
    {
        [Test]
        public void TestAsyncCssParsingFromStream()
        {
            var text = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
            var source = new DelayedStream(Encoding.UTF8.GetBytes(text));
            var parser = new CssParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsFalse(task.IsCompleted);
                Assert.IsNotNull(parser.Result);
                task.Wait();
                Assert.IsTrue(task.IsCompleted);
                Assert.IsNotNull(parser.Result);

                Assert.AreEqual(4, parser.Result.Rules.Length);
            }
        }

        [Test]
        public void TestAsyncHtmlParsingFromStream()
        {
            var text = "<html><head><title>My test</title></head><body><p>Some text</p></body></html>";
            var source = new DelayedStream(Encoding.UTF8.GetBytes(text));
            var parser = new HtmlParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsFalse(task.IsCompleted);
                Assert.IsNotNull(parser.Result);
                task.Wait();
                Assert.IsTrue(task.IsCompleted);
                Assert.IsNotNull(parser.Result);

                Assert.AreEqual("My test", parser.Result.Title);
                Assert.AreEqual(1, parser.Result.Body.ChildElementCount);
                Assert.AreEqual("Some text", parser.Result.Body.Children[0].TextContent);
            }
        }

        [Test]
        public void TestAsyncCssParsingFromString()
        {
            var source = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
            var parser = new CssParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsTrue(task.IsCompleted);
                Assert.IsNotNull(parser.Result);

                Assert.AreEqual(4, parser.Result.Rules.Length);
            }
        }

        [Test]
        public void TestAsyncHtmlParsingFromString()
        {
            var source = "<html><head><title>My test</title></head><body><p>Some text</p></body></html>";
            var parser = new HtmlParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsTrue(task.IsCompleted);
                Assert.IsNotNull(parser.Result);

                Assert.AreEqual("My test", parser.Result.Title);
                Assert.AreEqual(1, parser.Result.Body.ChildElementCount);
                Assert.AreEqual("Some text", parser.Result.Body.Children[0].TextContent);
            }
        }
    }
}<commit_msg>Return a task and await running ones<commit_after>﻿namespace AngleSharp.Core.Tests
{
    using System.Text;
    using System.Threading.Tasks;
    using AngleSharp;
    using AngleSharp.Core.Tests.Mocks;
    using AngleSharp.Parser.Css;
    using AngleSharp.Parser.Html;
    using NUnit.Framework;

    [TestFixture]
    public class AsyncParsingTests
    {
        [Test]
        public async Task TestAsyncCssParsingFromStream()
        {
            var text = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
            var source = new DelayedStream(Encoding.UTF8.GetBytes(text));
            var parser = new CssParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsFalse(task.IsCompleted);
                Assert.IsNotNull(parser.Result);
                var result = await task;

                Assert.IsTrue(task.IsCompleted);
                Assert.AreEqual(parser.Result, result);
                Assert.AreEqual(4, result.Rules.Length);
            }
        }

        [Test]
        public async Task TestAsyncHtmlParsingFromStream()
        {
            var text = "<html><head><title>My test</title></head><body><p>Some text</p></body></html>";
            var source = new DelayedStream(Encoding.UTF8.GetBytes(text));
            var parser = new HtmlParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsFalse(task.IsCompleted);
                Assert.IsNotNull(parser.Result);
                var result = await task;

                Assert.IsTrue(task.IsCompleted);
                Assert.AreEqual(parser.Result, result);
                Assert.AreEqual("My test", result.Title);
                Assert.AreEqual(1, result.Body.ChildElementCount);
                Assert.AreEqual("Some text", result.Body.Children[0].TextContent);
            }
        }

        [Test]
        public async Task TestAsyncCssParsingFromString()
        {
            var source = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
            var parser = new CssParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsTrue(task.IsCompleted);
                var result = await task;

                Assert.AreEqual(parser.Result, result);
                Assert.AreEqual(4, result.Rules.Length);
            }
        }

        [Test]
        public async Task TestAsyncHtmlParsingFromString()
        {
            var source = "<html><head><title>My test</title></head><body><p>Some text</p></body></html>";
            var parser = new HtmlParser(source, Configuration.Default);

            using (var task = parser.ParseAsync())
            {
                Assert.IsTrue(task.IsCompleted);
                var result = await task;

                Assert.AreEqual(parser.Result, result);
                Assert.AreEqual("My test", parser.Result.Title);
                Assert.AreEqual(1, parser.Result.Body.ChildElementCount);
                Assert.AreEqual("Some text", parser.Result.Body.Children[0].TextContent);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11531190926275993, 'fraction_numerical': 0.005040957781978576, 'mean_word_length': 1.8318465655664584, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, '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': '2880671', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1659, 'n_words': 330}