public void FourThousandAndNinetyFiveSelectorsIsFine()
        {
            var content = Enumerable.Range(0, 4095)
                          .Select(index => CSSFragmentBuilderSelector.New("div", CSSFragmentBuilderStyleProperty.New("width", "50%")).ToContainerFragment());

            LegacyIESelectorLimitMustBeRespected.Instance.EnsureRulesAreMet(content);
        }
        public void RepeatedSelectorAppearingInDifferentNestedMediaQueriesIsFine()
        {
            var content = new[]
            {
                CSSFragmentBuilderSelector.New(
                    "div.Header",
                    CSSFragmentBuilderStyleProperty.New("color", "red")
                    ).ToContainerFragment(),
                CSSFragmentBuilderSelector.New(
                    "@media screen and (max-width:70em)",
                    CSSFragmentBuilderSelector.New(
                        "div.Header",
                        CSSFragmentBuilderStyleProperty.New("color", "blue"),
                        CSSFragmentBuilderSelector.New(
                            "@media screen and (max-width:30em)",
                            CSSFragmentBuilderSelector.New(
                                "div.Header",
                                CSSFragmentBuilderStyleProperty.New("color", "yellow")
                                )
                            )
                        )
                    ).ToContainerFragment()
            };

            var ruleEnforcer = new NoSelectorMayBeRepeatedInTheRules(
                NoSelectorMayBeRepeatedInTheRules.ConformityOptions.AllowBareSelectorsToBeRepeated
                );

            ruleEnforcer.EnsureRulesAreMet(content);
        }
        public void LESSMixinWithMultipleArgumentsIsAllowed()
        {
            var content = CSSFragmentBuilderSelector.New(
                ".RoundedCorners (@topLeft, @topRight, @bottomRight, @bottomLeft)",
                CSSFragmentBuilderStyleProperty.New("border-radius", "@topLeft @topRight @bottomRight @bottomLeft")
                ).ToContainerFragment();

            (new OnlyBareSelectorsInResetsAndThemeSheets(OnlyBareSelectorsInResetsAndThemeSheets.ConformityOptions.AllowLessCssMixins)).EnsureRulesAreMet(new[] { content });
        }
コード例 #4
0
        public void PaddingFullyDefinedIsAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("padding", "16px")
                ).ToContainerFragment();

            PaddingMustBeFullySpecifiedIfSpecifiedAtAll.Instance.EnsureRulesAreMet(new[] { content });
        }
        public void LESSMixinWithNoArgumentsButWithBracketsIsAllowed()
        {
            var content = CSSFragmentBuilderSelector.New(
                ".RoundedCorners ()",
                CSSFragmentBuilderStyleProperty.New("border-radius", "4px")
                ).ToContainerFragment();

            (new OnlyBareSelectorsInResetsAndThemeSheets(OnlyBareSelectorsInResetsAndThemeSheets.ConformityOptions.AllowLessCssMixins)).EnsureRulesAreMet(new[] { content });
        }
        public void HtmlTagWithOnlyANestedDivIsAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New(
                "html",
                CSSFragmentBuilderSelector.New("div")
                ).ToContainerFragment();

            HtmlTagScopingMustBeAppliedToNonResetsOrThemesSheets.Instance.EnsureRulesAreMet(new[] { content });
        }
コード例 #7
0
        public void HtmlTagWithNoNestedContentIsNotAcceptable_ScopeRestrictingHtmlTagDisallowed()
        {
            var content = CSSFragmentBuilderSelector.New("html").ToContainerFragment();

            Assert.Throws <NoBareSelectorsInNonResetsOrThemeSheets.DisallowBareSelectorsEncounteredException>(() =>
            {
                (new NoBareSelectorsInNonResetsOrThemeSheets(NoBareSelectorsInNonResetsOrThemeSheets.ScopeRestrictingHtmlTagBehaviourOptions.Disallow)).EnsureRulesAreMet(new[] { content });
            });
        }
        public void FourThousandAndNinetySixSelectorsIsNotFine()
        {
            var content = Enumerable.Range(0, 4096)
                          .Select(index => CSSFragmentBuilderSelector.New("div", CSSFragmentBuilderStyleProperty.New("width", "50%")).ToContainerFragment());

            Assert.Throws <LegacyIESelectorLimitMustBeRespected.LegacyIESelectorLimitMustBeRespectedException>(() =>
            {
                LegacyIESelectorLimitMustBeRespected.Instance.EnsureRulesAreMet(content);
            });
        }
コード例 #9
0
        public void RecommendedConfigurationAllowsHundredPercentageWidthOnBackgroundPositionAndSizeAsMultiPartValue()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("background-size", "100% -20px"),
                CSSFragmentBuilderStyleProperty.New("background-position", "100% 19px")
                ).ToContainerFragment();

            AllMeasurementsMustBePixels.Recommended.EnsureRulesAreMet(new[] { content });
        }
コード例 #10
0
        public void HundredPercentWidthImportantIsAcceptedWhenAllowingAnyElementToBeHundredPercentWidth()
        {
            var content = CSSFragmentBuilderSelector.New(
                "a",
                CSSFragmentBuilderStyleProperty.New("width", "100% !important")
                ).ToContainerFragment();

            (new AllMeasurementsMustBePixels(
                 AllMeasurementsMustBePixels.ConformityOptions.AllowOneHundredPercentOnAnyElementAndProperty
                 )).EnsureRulesAreMet(new[] { content });
        }
コード例 #11
0
        public void HundredPercentWidthImportantReturnsNoErrorsWhenAllowingAnyElementToBeHundredPercentWidth()
        {
            var content = CSSFragmentBuilderSelector.New(
                "a",
                CSSFragmentBuilderStyleProperty.New("width", "100% !important")
                ).ToContainerFragment();

            Assert.Equal(0, (new AllMeasurementsMustBePixels(
                                 AllMeasurementsMustBePixels.ConformityOptions.AllowOneHundredPercentOnAnyElementAndProperty
                                 )).GetAnyBrokenRules(new[] { content }).Count());
        }
コード例 #12
0
        public void PaddingTopOnlyIsNotAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("padding-top", "16px")
                ).ToContainerFragment();

            Assert.Throws <PaddingMustBeFullySpecifiedIfSpecifiedAtAll.PaddingMustBeFullySpecifiedIfSpecifiedAtAllException>(() =>
            {
                PaddingMustBeFullySpecifiedIfSpecifiedAtAll.Instance.EnsureRulesAreMet(new[] { content });
            });
        }
        public void LESSMixinWithNoArgumentsAndNoBracketsIsNotAllowed()
        {
            var content = CSSFragmentBuilderSelector.New(
                ".RoundedCorners",
                CSSFragmentBuilderStyleProperty.New("border-radius", "4px")
                ).ToContainerFragment();

            Assert.Throws <OnlyBareSelectorsInResetsAndThemeSheets.OnlyAllowBareSelectorsEncounteredException>(() =>
            {
                (new OnlyBareSelectorsInResetsAndThemeSheets(OnlyBareSelectorsInResetsAndThemeSheets.ConformityOptions.AllowLessCssMixins)).EnsureRulesAreMet(new[] { content });
            });
        }
コード例 #14
0
        public void MarginAutoIsAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("margin", "0 auto")
                ).ToContainerFragment();

            (new AllMeasurementsMustBePixels(
                 AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                 AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                 )).EnsureRulesAreMet(new[] { content });
        }
        public void HtmlTagWithStylePropertiesIsNotAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New(
                "html",
                CSSFragmentBuilderStyleProperty.New("color", "black")
                ).ToContainerFragment();

            Assert.Throws <HtmlTagScopingMustBeAppliedToNonResetsOrThemesSheets.ScopeRestrictingHtmlTagNotAppliedException>(() =>
            {
                HtmlTagScopingMustBeAppliedToNonResetsOrThemesSheets.Instance.EnsureRulesAreMet(new[] { content });
            });
        }
コード例 #16
0
        public void SkipValidationOnKeyFramesAnimationContent()
        {
            var content = CSSFragmentBuilderSelector.New(
                "html",
                CSSFragmentBuilderSelector.New(
                    "@keyframes AnimateMe",
                    CSSFragmentBuilderSelector.New("0%", CSSFragmentBuilderStyleProperty.New("opacity", "0")),
                    CSSFragmentBuilderSelector.New("100%", CSSFragmentBuilderStyleProperty.New("opacity", "1"))
                    )
                ).ToContainerFragment();

            (new NoBareSelectorsInNonResetsOrThemeSheets(NoBareSelectorsInNonResetsOrThemeSheets.ScopeRestrictingHtmlTagBehaviourOptions.Allow)).EnsureRulesAreMet(new[] { content });
        }
コード例 #17
0
        public void BorderMayNotSpecifyWidthAsThick()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("border", "thick solid black")
                ).ToContainerFragment();

            Assert.Throws <AllMeasurementsMustBePixels.AllMeasurementsMustBePixelsNotAppliedException>(() =>
            {
                (new AllMeasurementsMustBePixels(
                     AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                     AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                     )).EnsureRulesAreMet(new[] { content });
            });
        }
コード例 #18
0
        public void HundredPercentageWidthImgsAreNotAcceptableIfNotNestedInPercentageWidthDivs()
        {
            var content = CSSFragmentBuilderSelector.New(
                "img",
                CSSFragmentBuilderStyleProperty.New("width", "100%")
                ).ToContainerFragment();

            Assert.Throws <AllMeasurementsMustBePixels.AllMeasurementsMustBePixelsNotAppliedException>(() =>
            {
                (new AllMeasurementsMustBePixels(
                     AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                     AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                     )).EnsureRulesAreMet(new[] { content });
            });
        }
コード例 #19
0
        public void PercentageKeywordWorkaroundIsCaught()
        {
            var content = CSSFragmentBuilderSelector.New(
                "p",
                CSSFragmentBuilderStyleProperty.New("width", "percentage(0.1)")
                ).ToContainerFragment();

            Assert.Throws <AllMeasurementsMustBePixels.AllMeasurementsMustBePixelsNotAppliedException>(() =>
            {
                (new AllMeasurementsMustBePixels(
                     AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                     AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                     )).EnsureRulesAreMet(new[] { content });
            });
        }
コード例 #20
0
        public void RecommendedConfigurationSkipsValidatingAnimationsSinceTheyAreOftenGeneric()
        {
            var content = CSSFragmentBuilderSelector.New(
                "@keyframes example",
                CSSFragmentBuilderSelector.New(
                    "0%",
                    CSSFragmentBuilderStyleProperty.New("top", "45%")
                    ),
                CSSFragmentBuilderSelector.New(
                    "100%",
                    CSSFragmentBuilderStyleProperty.New("top", "50%")
                    )
                ).ToContainerFragment();

            AllMeasurementsMustBePixels.Recommended.EnsureRulesAreMet(new[] { content });
        }
        public void SinglePropertyIsFine()
        {
            var content = new[]
            {
                CSSFragmentBuilderSelector.New(
                    "div.Header",
                    CSSFragmentBuilderStyleProperty.New("color", "red")
                    ).ToContainerFragment()
            };

            var ruleEnforcer = new NoSelectorMayBeRepeatedInTheRules(
                NoSelectorMayBeRepeatedInTheRules.ConformityOptions.AllowBareSelectorsToBeRepeated
                );

            ruleEnforcer.EnsureRulesAreMet(content);
        }
コード例 #22
0
        public void HundredPercentageWidthImgsMayBeAcceptableIfDeeplyNestedInPercentageWidthDivs()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("width", "50%"),
                CSSFragmentBuilderSelector.New(
                    "p",
                    CSSFragmentBuilderSelector.New(
                        "img",
                        CSSFragmentBuilderStyleProperty.New("width", "100%")
                        )
                    )
                ).ToContainerFragment();

            (new AllMeasurementsMustBePixels(
                 AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                 AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                 )).EnsureRulesAreMet(new[] { content });
        }
コード例 #23
0
        public void HundredPercentageWidthImgsMayBeAcceptableIfPercentageWidthAppliedToDivsInMediaQuery()
        {
            var content = CSSFragmentBuilderSelector.New(
                "div",
                CSSFragmentBuilderStyleProperty.New("width", "500px"),
                CSSFragmentBuilderSelector.New(
                    "@media screen and (max-width:70em)",
                    CSSFragmentBuilderStyleProperty.New("width", "50%"),
                    CSSFragmentBuilderSelector.New(
                        "img",
                        CSSFragmentBuilderStyleProperty.New("width", "100%")
                        )
                    )
                ).ToContainerFragment();

            (new AllMeasurementsMustBePixels(
                 AllMeasurementsMustBePixels.ConformityOptions.AllowPercentageWidthsOnSpecifiedElementTypes,
                 AllMeasurementsMustBePixels.RecommendedPercentageExceptions
                 )).EnsureRulesAreMet(new[] { content });
        }
        public void RepeatedSelectorsWithDifferentStylesIsNotAcceptable()
        {
            var content = new[]
            {
                CSSFragmentBuilderSelector.New(
                    "div.Header",
                    CSSFragmentBuilderStyleProperty.New("color", "red")
                    ).ToContainerFragment(),
                CSSFragmentBuilderSelector.New(
                    "div.Header",
                    CSSFragmentBuilderStyleProperty.New("color", "blue")
                    ).ToContainerFragment()
            };

            var ruleEnforcer = new NoSelectorMayBeRepeatedInTheRules(
                NoSelectorMayBeRepeatedInTheRules.ConformityOptions.AllowBareSelectorsToBeRepeated
                );

            Assert.Throws <NoSelectorMayBeRepeatedInTheRules.NoSelectorMayBeRepeatedInTheRulesException>(() =>
            {
                ruleEnforcer.EnsureRulesAreMet(content);
            });
        }
        public void SingleSelectorIsFine()
        {
            var content = CSSFragmentBuilderSelector.New("div", CSSFragmentBuilderStyleProperty.New("width", "50%")).ToContainerFragment();

            LegacyIESelectorLimitMustBeRespected.Instance.EnsureRulesAreMet(new[] { content });
        }
コード例 #26
0
        public void HtmlTagWithNoNestedContentIsAcceptable_ScopeRestrictingHtmlTagAllowed()
        {
            var content = CSSFragmentBuilderSelector.New("html").ToContainerFragment();

            (new NoBareSelectorsInNonResetsOrThemeSheets(NoBareSelectorsInNonResetsOrThemeSheets.ScopeRestrictingHtmlTagBehaviourOptions.Allow)).EnsureRulesAreMet(new[] { content });
        }
コード例 #27
0
        public void NoPaddingAtAllIsAcceptable()
        {
            var content = CSSFragmentBuilderSelector.New("div").ToContainerFragment();

            PaddingMustBeFullySpecifiedIfSpecifiedAtAll.Instance.EnsureRulesAreMet(new[] { content });
        }