Esempio n. 1
0
        public void GenerationOfSourceMapWithCustomSourceMapUrl()
        {
            // Arrange
            var sourceMapOptions = new ProcessingOptions
            {
                Browsers  = _targetBrowsers,
                SourceMap = true
            };

            const string inputPath     = "style.css";
            const string outputPath    = "style.out.css";
            const string sourceMapPath = "custom-style.out.css.map";
            string       content       = GetFileContent("content.css");

            string processedContent = GetFileContent("processed-content-with-custom-source-map-url.css");
            string sourceMap        = GetFileContent("source-map.css.map");

            // Act
            ProcessingResult result;

            using (var sourceMapAutoprefixer = new Autoprefixer(sourceMapOptions))
            {
                result = sourceMapAutoprefixer.Process(content, inputPath, outputPath, sourceMapPath);
            }

            // Assert
            Assert.AreEqual(processedContent, result.ProcessedContent);
            Assert.AreEqual(sourceMap, result.SourceMap);
        }
Esempio n. 2
0
        public void UsageOfCustomStatistics()
        {
            // Arrange
            var options = new ProcessingOptions
            {
                Browsers = new List <string> {
                    "cover 80% in my stats"
                },
                Stats = GetFileContent("custom-stats.json")
            };

            string input        = GetFileContent("content.css");
            string targetOutput = GetFileContent("processed-content-based-on-custom-statistics.css");

            // Act
            string output;

            using (var autoprefixer = new Autoprefixer(options))
            {
                output = autoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput, output);
        }
        public void GenerationOfSourceMapWithIncludingContents()
        {
            // Arrange
            var sourceMapWithoutContentsOptions = new ProcessingOptions
            {
                Browsers  = _targetBrowsers,
                SourceMap = true,
                SourceMapIncludeContents = false
            };
            var sourceMapWithContentsOptions = new ProcessingOptions
            {
                Browsers  = _targetBrowsers,
                SourceMap = true,
                SourceMapIncludeContents = true
            };

            const string inputPath  = "style.css";
            const string outputPath = "style.out.css";
            string       content    = GetFileContent("compiled-content.css");
            string       inputSourceMapWithContents = GetFileContent("source-map-from-compilation-with-contents.css.map");

            string processedContent1 = GetFileContent("processed-content-with-source-map-url.css");
            string sourceMap1        = GetFileContent("source-map-from-processing.css.map");

            string processedContent2 = GetFileContent("processed-content-with-source-map-url.css");
            string sourceMap2        = GetFileContent("source-map-from-processing-with-contents.css.map");

            // Act
            ProcessingResult result1;
            ProcessingResult result2;

            using (var sourceMapWithoutContentsAutoprefixer = new Autoprefixer(sourceMapWithoutContentsOptions))
            {
                result1 = sourceMapWithoutContentsAutoprefixer.Process(content, inputPath, outputPath, null,
                                                                       inputSourceMapWithContents);
            }

            using (var sourceMapWithContentsAutoprefixer = new Autoprefixer(sourceMapWithContentsOptions))
            {
                result2 = sourceMapWithContentsAutoprefixer.Process(content, inputPath, outputPath, null,
                                                                    inputSourceMapWithContents);
            }

            // Assert
            Assert.AreEqual(processedContent1, result1.ProcessedContent);
            Assert.AreEqual(sourceMap1, result1.SourceMap);

            Assert.AreEqual(processedContent2, result2.ProcessedContent);
            Assert.AreEqual(sourceMap2, result2.SourceMap);
        }
Esempio n. 4
0
        public void UsageOfSupportsProperty()
        {
            // Arrange
            var targetBrowsers = new List <string> {
                "last 4 versions"
            };
            var supportsDisabledOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Supports = false
            };
            var supportsEnabledOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Supports = true
            };

            const string input         = @"@supports (animation-name: test) {
    animation-name: test;
}";
            const string targetOutput1 = @"@supports (animation-name: test) {
    -webkit-animation-name: test;
            animation-name: test;
}";
            const string targetOutput2 = @"@supports ((-webkit-animation-name: test) or (animation-name: test)) {
    -webkit-animation-name: test;
            animation-name: test;
}";

            // Act
            string output1;
            string output2;

            using (var supportsDisabledAutoprefixer = new Autoprefixer(supportsDisabledOptions))
            {
                output1 = supportsDisabledAutoprefixer.Process(input).ProcessedContent;
            }

            using (var supportsEnabledAutoprefixer = new Autoprefixer(supportsEnabledOptions))
            {
                output2 = supportsEnabledAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
        }
        public void GenerationOfInlineSourceMap()
        {
            // Arrange
            var inlineSourceMapDisabledOptions = new ProcessingOptions
            {
                Browsers        = _targetBrowsers,
                SourceMap       = true,
                InlineSourceMap = false
            };
            var inlineSourceMapEnabledOptions = new ProcessingOptions
            {
                Browsers        = _targetBrowsers,
                SourceMap       = true,
                InlineSourceMap = true
            };

            const string inputPath  = "style.css";
            const string outputPath = "style.out.css";
            string       content    = GetFileContent("compiled-content-with-inline-source-map.css");

            string processedContent1 = GetFileContent("processed-content-with-source-map-url.css");
            string sourceMap1        = GetFileContent("source-map-from-processing.css.map");

            string processedContent2 = GetFileContent("processed-content-with-inline-source-map.css");
            string sourceMap2        = GetFileContent("source-map-from-processing.css.map");

            // Act
            ProcessingResult result1;
            ProcessingResult result2;

            using (var inlineSourceMapDisabledAutoprefixer = new Autoprefixer(inlineSourceMapDisabledOptions))
            {
                result1 = inlineSourceMapDisabledAutoprefixer.Process(content, inputPath, outputPath);
            }

            using (var inlineSourceMapEnabledAutoprefixer = new Autoprefixer(inlineSourceMapEnabledOptions))
            {
                result2 = inlineSourceMapEnabledAutoprefixer.Process(content, inputPath, outputPath);
            }

            // Assert
            Assert.AreEqual(processedContent1, result1.ProcessedContent);
            Assert.AreEqual(sourceMap1, result1.SourceMap);

            Assert.AreEqual(processedContent2, result2.ProcessedContent);
            Assert.AreEqual(sourceMap2, result2.SourceMap);
        }
Esempio n. 6
0
        public void GenerationOfSourceMapWithOmittingSourceMapUrl()
        {
            var sourceMapUrlIncludedOptions = new ProcessingOptions
            {
                Browsers         = _targetBrowsers,
                SourceMap        = true,
                OmitSourceMapUrl = false
            };
            var sourceMapUrlOmittedOptions = new ProcessingOptions
            {
                Browsers         = _targetBrowsers,
                SourceMap        = true,
                OmitSourceMapUrl = true
            };

            const string inputPath  = "style.css";
            const string outputPath = "style.out.css";
            string       content    = GetFileContent("content.css");

            string processedContent1 = GetFileContent("processed-content-with-source-map-url.css");
            string sourceMap1        = GetFileContent("source-map.css.map");

            string processedContent2 = GetFileContent("processed-content.css");
            string sourceMap2        = GetFileContent("source-map.css.map");

            // Act
            ProcessingResult result1;
            ProcessingResult result2;

            using (var sourceMapUrlIncludedAutoprefixer = new Autoprefixer(sourceMapUrlIncludedOptions))
            {
                result1 = sourceMapUrlIncludedAutoprefixer.Process(content, inputPath, outputPath);
            }

            using (var sourceMapUrlOmittedAutoprefixer = new Autoprefixer(sourceMapUrlOmittedOptions))
            {
                result2 = sourceMapUrlOmittedAutoprefixer.Process(content, inputPath, outputPath);
            }

            // Assert
            Assert.AreEqual(processedContent1, result1.ProcessedContent);
            Assert.AreEqual(sourceMap1, result1.SourceMap);

            Assert.AreEqual(processedContent2, result2.ProcessedContent);
            Assert.AreEqual(sourceMap2, result2.SourceMap);
        }
Esempio n. 7
0
        public void MappingBrowserslistError()
        {
            // Arrange
            var options = new ProcessingOptions {
                Browsers = new List <string> {
                    "> 5% in XX"
                }
            };

            const string input     = @".clipped-image {
    background-image: url(images/css3/toad.jpg);
    -moz-background-size: 120px 90px;
    -o-background-size: 120px 90px;
    -webkit-background-size: 120px 90px;
    background-size: 120px 90px;
}";
            const string inputPath = "/build/app.css";

            // Act
            string output;
            AutoprefixerProcessingException exception = null;

            try
            {
                using (var autoprefixer = new Autoprefixer(options))
                {
                    output = autoprefixer.Process(input, inputPath).ProcessedContent;
                }
            }
            catch (AutoprefixerProcessingException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual("Could not find the statistics for country code 'XX'.", exception.Message);
            Assert.AreEqual("Could not find the statistics for country code 'XX'.", exception.Description);
            Assert.AreEqual("BrowserslistError", exception.Type);
            Assert.AreEqual("/build/app.css", exception.File);
            Assert.AreEqual(0, exception.LineNumber);
            Assert.AreEqual(0, exception.ColumnNumber);
            Assert.IsEmpty(exception.SourceFragment);
        }
Esempio n. 8
0
        public void MappingPostCssError()
        {
            // Arrange
            const string input     = @".example {
    display: grid;
    transition: all .5s
    user-select: none;
    background: linear-gradient(to bottom, white, black);
}";
            const string inputPath = "/build/app.css";

            // Act
            string output;
            AutoprefixerProcessingException exception = null;

            try
            {
                using (var autoprefixer = new Autoprefixer())
                {
                    output = autoprefixer.Process(input, inputPath).ProcessedContent;
                }
            }
            catch (AutoprefixerProcessingException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual("/build/app.css:3:21: Missed semicolon", exception.Message);
            Assert.AreEqual("Missed semicolon", exception.Description);
            Assert.AreEqual("CssSyntaxError", exception.Type);
            Assert.AreEqual("/build/app.css", exception.File);
            Assert.AreEqual(3, exception.LineNumber);
            Assert.AreEqual(21, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 2:     display: grid;" + Environment.NewLine +
                "Line 3:     transition: all .5s" + Environment.NewLine +
                "----------------------------^" + Environment.NewLine +
                "Line 4:     user-select: none;",
                exception.SourceFragment
                );
        }
Esempio n. 9
0
        public void UsageOfRemoveProperty()
        {
            // Arrange
            var removeDisabledOptions = new ProcessingOptions {
                Remove = false
            };
            var removeEnabledOptions = new ProcessingOptions {
                Remove = true
            };

            const string input         = @".rounded-box {
    -webkit-border-radius: 5px;
       -moz-border-radius: 5px;
            border-radius: 5px;
    border: 1px solid #73AD21;
    padding: 10px;
}";
            const string targetOutput1 = input;
            const string targetOutput2 = @".rounded-box {
    border-radius: 5px;
    border: 1px solid #73AD21;
    padding: 10px;
}";

            // Act
            string output1;
            string output2;

            using (var removeDisabledAutoprefixer = new Autoprefixer(removeDisabledOptions))
            {
                output1 = removeDisabledAutoprefixer.Process(input).ProcessedContent;
            }

            using (var removeEnabledAutoprefixer = new Autoprefixer(removeEnabledOptions))
            {
                output2 = removeEnabledAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
        }
Esempio n. 10
0
        public void UsageOfCascadeProperty()
        {
            // Arrange
            var cascadeDisabledOptions = new ProcessingOptions {
                Cascade = false
            };
            var cascadeEnabledOptions = new ProcessingOptions {
                Cascade = true
            };

            const string input         = @".target {
    mask: url(resources.svg#c1) luminance;
}";
            const string targetOutput1 = @".target {
    -webkit-mask: url(resources.svg#c1) luminance;
    mask: url(resources.svg#c1) luminance;
}";
            const string targetOutput2 = @".target {
    -webkit-mask: url(resources.svg#c1) luminance;
            mask: url(resources.svg#c1) luminance;
}";

            // Act
            string output1;
            string output2;

            using (var cascadeDisabledAutoprefixer = new Autoprefixer(cascadeDisabledOptions))
            {
                output1 = cascadeDisabledAutoprefixer.Process(input).ProcessedContent;
            }

            using (var cascadeEnabledAutoprefixer = new Autoprefixer(cascadeEnabledOptions))
            {
                output2 = cascadeEnabledAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
        }
Esempio n. 11
0
        public void UsageOfAddProperty()
        {
            // Arrange
            var addDisabledOptions = new ProcessingOptions {
                Add = false
            };
            var addEnabledOptions = new ProcessingOptions {
                Add = true
            };

            const string input         = @".enable {
    user-select: all;
}";
            const string targetOutput1 = input;
            const string targetOutput2 = @".enable {
    -webkit-user-select: all;
       -moz-user-select: all;
        -ms-user-select: all;
            user-select: all;
}";

            // Act
            string output1;
            string output2;

            using (var addDisabledAutoprefixer = new Autoprefixer(addDisabledOptions))
            {
                output1 = addDisabledAutoprefixer.Process(input).ProcessedContent;
            }

            using (var addEnabledAutoprefixer = new Autoprefixer(addEnabledOptions))
            {
                output2 = addEnabledAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
        }
Esempio n. 12
0
        public void MappingJsonError()
        {
            // Arrange
            var options = new ProcessingOptions
            {
                Browsers = new List <string> {
                    "> 5% in my stats"
                },
                Stats = @"{
  ""ie"": {
    ""6"": 0.01,
    ""7"": 0.4,
    ""8"": 1.5
  },
  ""chrome"": {
    …
  },
  …
}"
            };

            // Act
            AutoprefixerLoadException exception = null;

            try
            {
                using (var autoprefixer = new Autoprefixer(options))
                { }
            }
            catch (AutoprefixerLoadException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual("The value of 'Stats' property has an incorrect format.", exception.Message);
            Assert.AreEqual("The value of 'Stats' property has an incorrect format.", exception.Description);
        }
Esempio n. 13
0
        public void MappingJavaScriptError()
        {
            // Arrange
            IJsEngineFactory jsEngineFactory = new JintJsEngineFactory();
            const string     input           = @".some-class {
    border-image: linear-gradient(black, white) 20% fill stretch stretch;
}";

            // Act
            string output;
            AutoprefixerLoadException exception = null;

            try
            {
                using (var autoprefixer = new Autoprefixer(jsEngineFactory))
                {
                    output = autoprefixer.Process(input).ProcessedContent;
                }
            }
            catch (AutoprefixerLoadException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "During loading of the Autoprefixer error has occurred. " +
                "See the original error message: \"ReferenceError: Uint8Array is not defined" + Environment.NewLine +
                "   at AutoprefixerHost.Resources.autoprefixer-combined.min.js:46:9781\".",
                exception.Message
                );
            Assert.AreEqual(
                "ReferenceError: Uint8Array is not defined" + Environment.NewLine +
                "   at AutoprefixerHost.Resources.autoprefixer-combined.min.js:46:9781",
                exception.Description
                );
        }
Esempio n. 14
0
        public static void ProcessCssBundles(CssConfig cssConfig)
        {
            var workingDirectory = Environment.CurrentDirectory;

            foreach (var bundle in cssConfig.Bundles)
            {
                try
                {
                    List <string> filesToAdd = GetInputFiles(bundle);

                    var commentPrefix = string.Empty;
                    var builder       = new StringBuilder();
                    if (!bundle.Minify && !string.IsNullOrWhiteSpace(bundle.CommentPrefix))
                    {
                        builder.AppendLine(commentPrefix = "/* " + bundle.CommentPrefix + " */");
                        builder.AppendLine();
                    }

                    foreach (var fileToAdd in filesToAdd)
                    {
                        try
                        {
                            var directory = Path.GetDirectoryName(fileToAdd);
                            var fileName  = Path.GetFileName(fileToAdd);
                            Directory.SetCurrentDirectory(directory);

                            var    extension = Path.GetExtension(fileName).ToLower();
                            var    content   = File.ReadAllText(fileName);
                            string compiledContent;
                            switch (extension)
                            {
                            case ".scss":
                                var options = new CompilationOptions
                                {
                                    IndentType      = IndentType.Space,
                                    IndentWidth     = 2,
                                    LineFeedType    = LineFeedType.Lf,
                                    OutputStyle     = OutputStyle.Nested,
                                    Precision       = 5,
                                    SourceMap       = true,
                                    InlineSourceMap = false
                                };
                                if (bundle.Minify)
                                {
                                    options.OutputStyle = OutputStyle.Compressed;
                                }

                                var compiledResult = SassCompiler.Compile(content, options: options);
                                compiledContent = compiledResult.CompiledContent;
                                break;

                            case ".css":
                                compiledContent = content;
                                break;

                            default:
                                throw new Exception($"File format not supported '{extension}' ('{fileToAdd}')");
                            }

                            var autoPrefixer = new Autoprefixer(new ChakraCoreJsEngineFactory(), new ProcessingOptions
                            {
                            });
                            var processedResult  = autoPrefixer.Process(compiledContent);
                            var processedContent = processedResult.ProcessedContent.Trim();
                            if (bundle.Minify)
                            {
                                builder.Append(processedContent);
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(processedContent))
                                {
                                    if (bundle.AddSourceFilePathComments)
                                    {
                                        builder.AppendLine($"/* BEGIN {fileName} */");
                                    }
                                    builder.AppendLine(processedContent);
                                    if (bundle.AddSourceFilePathComments)
                                    {
                                        builder.AppendLine($"/* END {fileName} */");
                                    }
                                    builder.AppendLine();
                                }
                            }
                            Utilities.WriteLine($"[SUCCESS] - Processed file: '{fileToAdd}'.", ConsoleColor.Yellow);
                        }
                        catch (Exception ex)
                        {
                            Utilities.WriteErrorLine($"[FAILURE] - Failed to process file: '{fileToAdd}'.", ConsoleColor.Red);
                            Console.Error.WriteLine(ex.Message);
                        }
                    }

                    Directory.SetCurrentDirectory(workingDirectory);

                    var destFilePath = Path.GetFullPath(bundle.DestinationFilePath);
                    try
                    {
                        if (File.Exists(destFilePath))
                        {
                            File.Delete(destFilePath);
                        }

                        var destinationFolder = Path.GetDirectoryName(destFilePath);
                        if (!Directory.Exists(destinationFolder))
                        {
                            Directory.CreateDirectory(destinationFolder);
                        }
                        File.WriteAllText(destFilePath, builder.ToString());
                        Utilities.WriteLine($"[SUCCESS] - Created bundle file: '{destFilePath}'.", ConsoleColor.Green);
                    }
                    catch (Exception ex)
                    {
                        Utilities.WriteErrorLine($"[FAILURE] - Failed to create bundle file: '{bundle.DestinationFilePath}' [{destFilePath}].", ConsoleColor.Red);
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                finally
                {
                    Directory.SetCurrentDirectory(workingDirectory);
                    Console.WriteLine();
                }
            }
        }
Esempio n. 15
0
        public void MappingAutoprefixerWarnings()
        {
            // Arrange
            var options = new ProcessingOptions {
                Browsers = new List <string> {
                    "last 4 version"
                },
                Grid = GridMode.Autoplace
            };

            const string content   = @".some-class {
    /* autoprefixer: off */
    -webkit-box-shadow: 0 0 20px #555;
       -moz-box-shadow: 0 0 20px #555;
            box-shadow: 0 0 20px #555;
    /* autoprefixer: on */
    mask: none;
}

.grid-conflict {
    display: grid;
    grid-gap: 10px;
    grid-template:
        ""g   g"" 100px
        ""g   g"" 100px
        ""h   h"" 100px /
        1fr  1fr;
}";
            const string inputPath = "/build/app.css";
            const string targetProcessedContent = @".some-class {
    /* autoprefixer: off */
    -webkit-box-shadow: 0 0 20px #555;
       -moz-box-shadow: 0 0 20px #555;
            box-shadow: 0 0 20px #555;
    /* autoprefixer: on */
    mask: none;
}

.grid-conflict {
    display: -ms-grid;
    display: grid;
    grid-gap: 10px;
    -ms-grid-rows: 100px 10px 100px 10px 100px;
    -ms-grid-columns: 1fr 10px 1fr;
        grid-template:
        ""g   g"" 100px
        ""g   g"" 100px
        ""h   h"" 100px /
        1fr  1fr;
}";

            // Act
            string processedContent;
            IList <ProblemInfo> warnings;

            using (var autoprefixer = new Autoprefixer(options))
            {
                ProcessingResult result = autoprefixer.Process(content, inputPath);
                processedContent = result.ProcessedContent;
                warnings         = result.Warnings;
            }

            // Assert
            Assert.AreEqual(targetProcessedContent, processedContent);

            Assert.AreEqual(2, warnings.Count);

            Assert.AreEqual(
                "autoprefixer: /build/app.css:6:5: " +
                "Second Autoprefixer control comment was ignored. " +
                "Autoprefixer applies control comment to whole block, not to next rules.",
                warnings[0].Message
                );
            Assert.AreEqual(
                "Second Autoprefixer control comment was ignored. " +
                "Autoprefixer applies control comment to whole block, not to next rules.",
                warnings[0].Description
                );
            Assert.AreEqual("/build/app.css", warnings[0].File);
            Assert.AreEqual(6, warnings[0].LineNumber);
            Assert.AreEqual(5, warnings[0].ColumnNumber);
            Assert.AreEqual(
                "Line 5:             box-shadow: 0 0 20px #555;" + Environment.NewLine +
                "Line 6:     /* autoprefixer: on */" + Environment.NewLine +
                "------------^" + Environment.NewLine +
                "Line 7:     mask: none;",
                warnings[0].SourceFragment
                );

            Assert.AreEqual(
                "autoprefixer: /build/app.css:13:5: " +
                "Can not find grid areas: g, h",
                warnings[1].Message
                );
            Assert.AreEqual("Can not find grid areas: g, h", warnings[1].Description);
            Assert.AreEqual("/build/app.css", warnings[1].File);
            Assert.AreEqual(13, warnings[1].LineNumber);
            Assert.AreEqual(5, warnings[1].ColumnNumber);
            Assert.AreEqual(
                "Line 12:     grid-gap: 10px;" + Environment.NewLine +
                "Line 13:     grid-template:" + Environment.NewLine +
                "-------------^" + Environment.NewLine +
                "Line 14:         \"g   g\" 100px",
                warnings[1].SourceFragment
                );
        }
Esempio n. 16
0
        public void UsageOfGridProperty()
        {
            // Arrange
            var targetBrowsers = new List <string> {
                "Edge 12", "IE 10"
            };
            var gridNoneOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Grid     = GridMode.None
            };
            var gridAutoplaceOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Grid     = GridMode.Autoplace
            };
            var gridNoAutoplaceOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Grid     = GridMode.NoAutoplace
            };

            const string input         = @".grid-template-areas {
    display: grid;
    grid-template-areas:
        ""a-conflict a-conflict""
        ""b-conflict b-conflict"";
}

.grid-autoplace {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto;
    grid-gap: 30px;
}";
            const string targetOutput1 = input;
            const string targetOutput2 = @".grid-template-areas {
    display: -ms-grid;
    display: grid;
        grid-template-areas:
        ""a-conflict a-conflict""
        ""b-conflict b-conflict"";
}

.grid-autoplace {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 1fr 30px 1fr 30px 1fr;
    grid-template-columns: 1fr 1fr 1fr;
    -ms-grid-rows: auto;
    grid-template-rows: auto;
    grid-gap: 30px;
}

.grid-autoplace > *:nth-child(1) {
    -ms-grid-row: 1;
    -ms-grid-column: 1;
}

.grid-autoplace > *:nth-child(2) {
    -ms-grid-row: 1;
    -ms-grid-column: 3;
}

.grid-autoplace > *:nth-child(3) {
    -ms-grid-row: 1;
    -ms-grid-column: 5;
}";
            const string targetOutput3 = @".grid-template-areas {
    display: -ms-grid;
    display: grid;
        grid-template-areas:
        ""a-conflict a-conflict""
        ""b-conflict b-conflict"";
}

.grid-autoplace {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 1fr 1fr 1fr;
    grid-template-columns: 1fr 1fr 1fr;
    -ms-grid-rows: auto;
    grid-template-rows: auto;
    grid-gap: 30px;
}";

            // Act
            string output1;
            string output2;
            string output3;

            using (var gridNoneAutoprefixer = new Autoprefixer(gridNoneOptions))
            {
                output1 = gridNoneAutoprefixer.Process(input).ProcessedContent;
            }

            using (var gridAutoplaceAutoprefixer = new Autoprefixer(gridAutoplaceOptions))
            {
                output2 = gridAutoplaceAutoprefixer.Process(input).ProcessedContent;
            }

            using (var gridNoAutoplaceAutoprefixer = new Autoprefixer(gridNoAutoplaceOptions))
            {
                output3 = gridNoAutoplaceAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
            Assert.AreEqual(targetOutput3, output3);
        }
Esempio n. 17
0
        public void UsageOfFlexboxProperty()
        {
            // Arrange
            var targetBrowsers = new List <string> {
                "Chrome > 19"
            };
            var flexboxNoneOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Flexbox  = FlexboxMode.None
            };
            var flexboxAllOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Flexbox  = FlexboxMode.All
            };
            var flexboxNo2009Options = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                Flexbox  = FlexboxMode.No2009
            };

            const string input         = @"A {
    flex: 1;
    transition: flex;
}";
            const string targetOutput1 = @"A {
    flex: 1;
    -webkit-transition: flex;
    transition: flex;
}";
            const string targetOutput2 = @"A {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
            flex: 1;
    -webkit-transition: -webkit-box-flex, -webkit-flex;
    transition: -webkit-box-flex, -webkit-flex;
    transition: flex;
    transition: flex, -webkit-box-flex, -webkit-flex;
}";
            const string targetOutput3 = @"A {
    -webkit-flex: 1;
            flex: 1;
    -webkit-transition: -webkit-flex;
    transition: -webkit-flex;
    transition: flex;
    transition: flex, -webkit-flex;
}";

            // Act
            string output1;
            string output2;
            string output3;

            using (var flexboxNoneAutoprefixer = new Autoprefixer(flexboxNoneOptions))
            {
                output1 = flexboxNoneAutoprefixer.Process(input).ProcessedContent;
            }

            using (var flexboxAllAutoprefixer = new Autoprefixer(flexboxAllOptions))
            {
                output2 = flexboxAllAutoprefixer.Process(input).ProcessedContent;
            }

            using (var flexboxNo2009Autoprefixer = new Autoprefixer(flexboxNo2009Options))
            {
                output3 = flexboxNo2009Autoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
            Assert.AreEqual(targetOutput3, output3);
        }
Esempio n. 18
0
        public void IgnoringUnknownVersionError()
        {
            // Arrange
            var targetBrowsers = new List <string> {
                "IE 38"
            };
            var noIgnoreErrorsOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                IgnoreUnknownVersions = false
            };
            var ignoreErrorsOptions = new ProcessingOptions
            {
                Browsers = targetBrowsers,
                IgnoreUnknownVersions = true
            };

            const string input         = @".bordered-image {
    border-width: 27px;
    -moz-border-image: url(""images/css3/border.png"") 27 round round;
    -o-border-image: url(""images/css3/border.png"") 27 round round;
    -webkit-border-image: url(""images/css3/border.png"") 27 round round;
    border-image: url(images/css3/border.png) 27 round round;
}";
            const string inputPath     = "/build/app.css";
            const string targetOutput1 = "";
            const string targetOutput2 = @".bordered-image {
    border-width: 27px;
    border-image: url(images/css3/border.png) 27 round round;
}";

            // Act
            string output1 = string.Empty;
            AutoprefixerProcessingException exception1 = null;
            string output2;

            using (var noIgnoreErrorsAutoprefixer = new Autoprefixer(noIgnoreErrorsOptions))
            {
                try
                {
                    output1 = noIgnoreErrorsAutoprefixer.Process(input, inputPath).ProcessedContent;
                }
                catch (AutoprefixerProcessingException e)
                {
                    exception1 = e;
                }
            }

            using (var ignoreErrorsAutoprefixer = new Autoprefixer(ignoreErrorsOptions))
            {
                output2 = ignoreErrorsAutoprefixer.Process(input, inputPath).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.NotNull(exception1);
            Assert.AreEqual("Unknown version 38 of IE", exception1.Message);
            Assert.AreEqual("Unknown version 38 of IE", exception1.Description);
            Assert.AreEqual("BrowserslistError", exception1.Type);
            Assert.AreEqual("/build/app.css", exception1.File);
            Assert.AreEqual(0, exception1.LineNumber);
            Assert.AreEqual(0, exception1.ColumnNumber);
            Assert.IsEmpty(exception1.SourceFragment);

            Assert.AreEqual(targetOutput2, output2);
        }
Esempio n. 19
0
        public void UsageOfBrowsersProperty()
        {
            // Arrange
            var defaultBrowsersOptions = new ProcessingOptions();
            var nullBrowsersOptions    = new ProcessingOptions {
                Browsers = null
            };
            var emptyBrowsersOptions = new ProcessingOptions {
                Browsers = new List <string>()
            };
            var customBrowsersOptions = new ProcessingOptions {
                Browsers = new List <string> {
                    "last 4 version"
                }
            };

            const string input         = @".example {
    display: grid;
    transition: all .5s;
    user-select: none;
    background: linear-gradient(to bottom, white, black);
}";
            const string targetOutput1 = @".example {
    display: grid;
    transition: all .5s;
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
    background: linear-gradient(to bottom, white, black);
}";
            const string targetOutput2 = targetOutput1;
            const string targetOutput3 = input;
            const string targetOutput4 = @".example {
    display: grid;
    -webkit-transition: all .5s;
    -o-transition: all .5s;
    transition: all .5s;
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
    background: -webkit-gradient(linear, left top, left bottom, from(white), to(black));
    background: -o-linear-gradient(top, white, black);
    background: linear-gradient(to bottom, white, black);
}";

            // Act
            string output1;
            string output2;
            string output3;
            string output4;

            using (var defaultBrowsersAutoprefixer = new Autoprefixer(defaultBrowsersOptions))
            {
                output1 = defaultBrowsersAutoprefixer.Process(input).ProcessedContent;
            }

            using (var nullBrowsersAutoprefixer = new Autoprefixer(nullBrowsersOptions))
            {
                output2 = nullBrowsersAutoprefixer.Process(input).ProcessedContent;
            }

            using (var emptyBrowsersAutoprefixer = new Autoprefixer(emptyBrowsersOptions))
            {
                output3 = emptyBrowsersAutoprefixer.Process(input).ProcessedContent;
            }

            using (var customBrowsersAutoprefixer = new Autoprefixer(customBrowsersOptions))
            {
                output4 = customBrowsersAutoprefixer.Process(input).ProcessedContent;
            }

            // Assert
            Assert.AreEqual(targetOutput1, output1);
            Assert.AreEqual(targetOutput2, output2);
            Assert.AreEqual(targetOutput3, output3);
            Assert.AreEqual(targetOutput4, output4);
        }