<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AngleSharp.Parser.Css;
using AngleSharp.DOM.Css;

namespace UnitTests.Css
{
    [TestClass]
    public class CssMediaListTests
    {
        [TestMethod]
        public void SimpleScreenMediaList()
        {
            var source = @"@media screen {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("screen", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void SimpleScreenTvMediaList()
        {
            var source = @"@media screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void OnlyScreenTvMediaList()
        {
            var source = @"@media only screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("only screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void NotScreenTvMediaList()
        {
            var source = @"@media not screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("not screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void FeatureMinWidthMediaList()
        {
            var source = @"@media (min-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("(min-width: 30px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void OnlyFeatureWidthMediaList()
        {
            var source = @"@media only (width: 640px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("only (width: 640px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void NotFeatureDeviceWidthMediaList()
        {
            var source = @"@media not (device-width: 640px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("not (device-width: 640px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void AllFeatureMaxWidthMediaListMissingAnd()
        {
            var source = @"@media all (max-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(0, sheet.CssRules.Length);
        }

        [TestMethod]
        public void AllFeatureMaxWidthMediaListWithAndKeyword()
        {
            var source = @"@media all and (max-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("all and (max-width: 30px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);<commit_msg>More tests for error handling<commit_after>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AngleSharp.Parser.Css;
using AngleSharp.DOM.Css;

namespace UnitTests.Css
{
    [TestClass]
    public class CssMediaListTests
    {
        [TestMethod]
        public void SimpleScreenMediaList()
        {
            var source = @"@media screen {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("screen", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void SimpleScreenTvMediaList()
        {
            var source = @"@media screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void OnlyScreenTvMediaList()
        {
            var source = @"@media only screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("only screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void NotScreenTvMediaList()
        {
            var source = @"@media not screen,tv {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("not screen, tv", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(2, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void FeatureMinWidthMediaList()
        {
            var source = @"@media (min-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("(min-width: 30px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void OnlyFeatureWidthMediaList()
        {
            var source = @"@media only (width: 640px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("only (width: 640px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void NotFeatureDeviceWidthMediaList()
        {
            var source = @"@media not (device-width: 640px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("not (device-width: 640px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
        }

        [TestMethod]
        public void AllFeatureMaxWidthMediaListMissingAnd()
        {
            var source = @"@media all (max-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(0, sheet.CssRules.Length);
        }

        [TestMethod]
        public void FeatureMaxWidthMediaListMissingConnectedAnd()
        {
            var source = @"@media (max-width:30px) (min-width:10px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(0, sheet.CssRules.Length);
        }

        [TestMethod]
        public void TvScreenMediaListMissingComma()
        {
            var source = @"@media tv screen {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(0, sheet.CssRules.Length);
        }

        [TestMethod]
        public void AllFeatureMaxWidthMediaListWithAndKeyword()
        {
            var source = @"@media all and (max-width:30px) {
    h1 { color: green }
}";
            var sheet = CssParser.ParseStyleSheet(source);
            Assert.AreEqual(1, sheet.CssRules.Length);
            Assert.IsInstanceOfType(sheet.CssRules[0], typeof(CSSMediaRule));
            var media = (CSSMediaRule)sheet.CssRules[0];
            Assert.AreEqual("all and (max-width: 30px)", media.ConditionText);
            var list = media.Media;
            Assert.AreEqual(1, list.Length);
            Assert.AreEqual(1, media.CssRules.Length);
{'fraction_non_alphanumeric': 0.1165098374679213, 'fraction_numerical': 0.01300256629597947, 'mean_word_length': 2.1402095084609187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4899995', 'n_tokens_mistral': 3460, 'n_tokens_neox': 3377, 'n_words': 621}