Beispiel #1
0
        public void TestMixinExpansion()
        {
            var lessFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(LessContentTypeDefinition.LessContentType));
            var lessCode    = @"a {
                                .myMixin(@p) {
                                    b, code {
                                    }
                                }
                            }";

            var lessDoc    = lessFactory.CreateParser().Parse(lessCode, false);
            var lessBlocks = new CssItemAggregator <RuleSet>(true)
            {
                (RuleSet rs) => rs
            }.Crawl(lessDoc).ToList();

            // Remove all but the deepest blocks
            while (0 < lessBlocks.RemoveAll(c => lessBlocks.Any(c.IsParentOf)))
            {
                ;
            }

            var literalExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Literal)).ToList();

            literalExpansions.Should().Equal(new[] { "a .myMixin(@p) b", "a .myMixin(@p) code" });

            var skipExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Skip)).ToList();

            skipExpansions.Should().BeEmpty();

            var nestedExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.NestedOnly)).ToList();

            nestedExpansions.Should().Equal(new[] { "«mixin .myMixin» b", "«mixin .myMixin» code" });
        }
Beispiel #2
0
        public void TestMixinExpansion()
        {
            var scssFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(ScssContentTypeDefinition.ScssContentType));
            var scssCode    = @"a {
                                @mixin myMixin($p) {
                                        b, code {
                                            width: $p+10+px;
                                        }
                                    }
                                    @include myMixin(1)
                                }
                            ";

            var scssDoc    = scssFactory.CreateParser().Parse(scssCode, false);
            var scssBlocks = new CssItemAggregator <RuleSet>(true)
            {
                (RuleSet rs) => rs
            }.Crawl(scssDoc).ToList();

            // Remove all but the deepest blocks
            while (0 < scssBlocks.RemoveAll(c => scssBlocks.Any(c.IsParentOf)))
            {
                ;
            }

            var literalExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Literal)).ToList();

            literalExpansions.Should().Equal(new[] { "a b", "a code" });

            var skipExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Skip)).ToList();

            skipExpansions.Should().BeEmpty();
        }
        public void TestMixinExpansion()
        {
            var lessFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(LessContentTypeDefinition.LessContentType));
            var lessCode = @"a {
                                .myMixin(@p) {
                                    b, code {
                                    }
                                }
                            }";

            var lessDoc = lessFactory.CreateParser().Parse(lessCode, false);
            var lessBlocks = new CssItemAggregator<RuleSet>(true) { (RuleSet rs) => rs }.Crawl(lessDoc).ToList();
            // Remove all but the deepest blocks
            while (0 < lessBlocks.RemoveAll(c => lessBlocks.Any(c.IsParentOf)))
                ;

            var literalExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Literal)).ToList();
            literalExpansions.Should().Equal(new[] { "a .myMixin(@p) b", "a .myMixin(@p) code" });

            var skipExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Skip)).ToList();
            skipExpansions.Should().BeEmpty();

            var nestedExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.NestedOnly)).ToList();
            nestedExpansions.Should().Equal(new[] { "«mixin .myMixin» b", "«mixin .myMixin» code" });
        }
        public void TestMixinExpansion()
        {
            var lessCode = @"
a {
    .myMixin(@p) {
        b, code {
        }
    }
}";

            var lessDoc = new LessParser().Parse(lessCode, false);
            var lessBlocks = new CssItemAggregator<RuleSet>(true) { (RuleSet rs) => rs }.Crawl(lessDoc).ToList();
            // Remove all but the deepest blocks
            while (0 < lessBlocks.RemoveAll(c => lessBlocks.Any(c.IsParentOf)))
                ;

            var literalExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Literal)).ToList();
            CollectionAssert.AreEqual(new[] { "a .myMixin(@p) b", "a .myMixin(@p) code" }, literalExpansions);

            var skipExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Skip)).ToList();
            CollectionAssert.AreEqual(new string[0], skipExpansions);

            var nestedExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.NestedOnly)).ToList();
            CollectionAssert.AreEqual(new[] { "«mixin .myMixin» b", "«mixin .myMixin» code" }, nestedExpansions);
        }
        public void TestMixinExpansion()
        {
            var scssFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(ScssContentTypeDefinition.ScssContentType));
            var scssCode = @"a {
                                @mixin myMixin($p) {
                                        b, code {
                                            width: $p+10+px;
                                        }
                                    }
                                    @include myMixin(1)
                                }
                            ";

            var scssDoc = scssFactory.CreateParser().Parse(scssCode, false);
            var scssBlocks = new CssItemAggregator<RuleSet>(true) { (RuleSet rs) => rs }.Crawl(scssDoc).ToList();
            // Remove all but the deepest blocks
            while (0 < scssBlocks.RemoveAll(c => scssBlocks.Any(c.IsParentOf)))
                ;

            var literalExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Literal)).ToList();
            literalExpansions.Should().Equal(new[] { "a b", "a code" });

            var skipExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Skip)).ToList();
            skipExpansions.Should().BeEmpty();
        }