/// <summary> /// Writes a detailed error message to the buffer /// </summary> /// <param name="buffer">Instance of <see cref="StringBuilder"/></param> /// <param name="autoprefixerProcessingException">Autoprefixer processing exception</param> private static void WriteProcessingErrorDetails(StringBuilder buffer, AutoprefixerProcessingException autoprefixerProcessingException) { if (!string.IsNullOrWhiteSpace(autoprefixerProcessingException.Type)) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Type, autoprefixerProcessingException.Type); } buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Description, autoprefixerProcessingException.Description); if (!string.IsNullOrWhiteSpace(autoprefixerProcessingException.File)) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_File, autoprefixerProcessingException.File); } if (autoprefixerProcessingException.LineNumber > 0) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber, autoprefixerProcessingException.LineNumber.ToString(CultureInfo.InvariantCulture)); } if (autoprefixerProcessingException.ColumnNumber > 0) { buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber, autoprefixerProcessingException.ColumnNumber.ToString(CultureInfo.InvariantCulture)); } if (!string.IsNullOrWhiteSpace(autoprefixerProcessingException.SourceFragment)) { buffer.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine, Strings.ErrorDetails_SourceFragment, autoprefixerProcessingException.SourceFragment); } }
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); }
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 ); }
/// <summary> /// Generates a detailed error message /// </summary> /// <param name="autoprefixerProcessingException">Autoprefixer processing exception</param> /// <param name="omitMessage">Flag for whether to omit message</param> /// <returns>Detailed error message</returns> public static string GenerateErrorDetails(AutoprefixerProcessingException autoprefixerProcessingException, bool omitMessage = false) { if (autoprefixerProcessingException == null) { throw new ArgumentNullException(nameof(autoprefixerProcessingException)); } var stringBuilderPool = StringBuilderPool.Shared; StringBuilder detailsBuilder = stringBuilderPool.Rent(); WriteCommonErrorDetails(detailsBuilder, autoprefixerProcessingException, omitMessage); WriteProcessingErrorDetails(detailsBuilder, autoprefixerProcessingException); detailsBuilder.TrimEnd(); string errorDetails = detailsBuilder.ToString(); stringBuilderPool.Return(detailsBuilder); return(errorDetails); }
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); }