/// <summary> /// Executes the unit test while providing console input. /// </summary> /// <param name="givenInput">Input which will be given</param> /// <param name="expectedOutput">The expected output</param> /// <param name="action">Action to be tested</param> /// <param name="areEquivalentOperator">delegate for comparing the expected from actual output.</param> /// <param name="normalizeOptions">Options to normalize input and expected output</param> /// <param name="equivalentOperatorErrorMessage">A textual description of the message if the <paramref name="areEquivalentOperator"/> returns false</param> private static string Execute(string givenInput, string expectedOutput, Action action, Func <string, string, bool> areEquivalentOperator, NormalizeOptions normalizeOptions = NormalizeOptions.Default, string equivalentOperatorErrorMessage = "Values are not equal" ) { string output = Execute(givenInput, action); if ((normalizeOptions & NormalizeOptions.NormalizeLineEndings) != 0) { output = NormalizeLineEndings(output, true); expectedOutput = NormalizeLineEndings(expectedOutput, true); } if ((normalizeOptions & NormalizeOptions.StripAnsiEscapeCodes) != 0) { output = StripAnsiEscapeCodes(output); expectedOutput = StripAnsiEscapeCodes(expectedOutput); } AssertExpectation(expectedOutput, output, areEquivalentOperator, equivalentOperatorErrorMessage); return(output); }
/// <summary> /// Normalizes the specified markdown to a normalized markdown text. /// </summary> /// <param name="markdown">The markdown.</param> /// <param name="options">The normalize options</param> /// <param name="pipeline">The pipeline.</param> /// <param name="context">A parser context used for the parsing.</param> /// <returns>A normalized markdown text.</returns> public static string Normalize(string markdown, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null) { var writer = new StringWriter(); Normalize(markdown, writer, options, pipeline, context); return(writer.ToString()); }
private static void Render(MarkdownDocument doc, string fileName) { Console.WriteLine("Creating {0}", fileName); string directoryName = Path.GetDirectoryName(fileName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } var options = new NormalizeOptions(); using (var writer = new StreamWriter(fileName)) { var renderer = new NormalizeRenderer(writer, options); renderer.ObjectRenderers.Add(new NormalizeTableRenderer()); var linkReferenceDefinitionRenderer = renderer.ObjectRenderers.Find <LinkReferenceDefinitionRenderer>(); if (linkReferenceDefinitionRenderer != null) { renderer.ObjectRenderers.Remove(linkReferenceDefinitionRenderer); } renderer.Render(doc); } }
internal void Normalize(NormalizeOptions normalizeOptions, bool allowUTF8 = false) { this.ThrowIfDisposed(); this.ThrowIfReadOnly("Normalize"); using (ThreadAccessGuard.EnterPublic(this.accessToken)) { this.message.Normalize(normalizeOptions, allowUTF8); } }
/// <summary> /// Performs a unit test on a console-based method. A "view" of /// what a user would see in their console is provided as a string, /// where their input (including line-breaks) is surrounded by double /// less-than/greater-than signs, like so: "Input please: <<Input>>" /// </summary> /// <param name="expected">Expected "view" to be seen on the console, /// including both input and output</param> /// <param name="action">Method to be run</param> /// <param name="normalizeOptions">Options to normalize input and expected output</param> public static string Expect(string expected, Action action, NormalizeOptions normalizeOptions = NormalizeOptions.Default) { return(Expect(expected, action, (left, right) => left == right, normalizeOptions)); }
/// <summary> /// <para> /// Performs a unit test on a console-based method. A "view" of /// what a user would see in their console is provided as a string, /// where their input (including line-breaks) is surrounded by double /// less-than/greater-than signs, like so: "Input please: <<Input>>" /// </para> /// </summary> /// <param name="expected">Expected "view" to be seen on the console, /// including both input and output</param> /// <param name="action">Method to be run</param> /// <param name="args">Args to pass to the function.</param> /// <param name="normalizeOptions">Options to normalize input and expected output</param> public static string Expect(string expected, Action <string[]> action, NormalizeOptions normalizeOptions = NormalizeOptions.Default, params string[] args) { return(Expect(expected, () => action(args), (left, right) => left == right, normalizeOptions)); }
/// <summary> /// Performs a unit test on a console-based method. A "view" of /// what a user would see in their console is provided as a string, /// where their input (including line-breaks) is surrounded by double /// less-than/greater-than signs, like so: "Input please: <<Input>>" /// </summary> /// <param name="expected">Expected "view" to be seen on the console, /// including both input and output</param> /// <param name="action">Method to be run</param> /// <param name="comparisonOperator"></param> /// <param name="normalizeOptions">Options to normalize input and expected output</param> /// <param name="equivalentOperatorErrorMessage">A textual description of the message if the result of <paramref name="action"/> does not match the <paramref name="expected"/> value</param> private static string Expect( string expected, Action action, Func <string, string, bool> comparisonOperator, NormalizeOptions normalizeOptions = NormalizeOptions.Default, string equivalentOperatorErrorMessage = "Values are not equal") { (string input, string output) = Parse(expected); return(Execute(input, output, action, (left, right) => comparisonOperator(left, right), normalizeOptions, equivalentOperatorErrorMessage)); }
/// <summary> /// Performs a unit test on a console-based method. A "view" of /// what a user would see in their console is provided as a string, /// where their input (including line-breaks) is surrounded by double /// less-than/greater-than signs, like so: "Input please: <<Input>>" /// </summary> /// <param name="expected">Expected "view" to be seen on the console, /// including both input and output</param> /// <param name="action">Method to be run</param> /// <param name="normalizeLineEndings">Whether differences in line ending styles should be ignored.</param> /// <param name="escapeCharacter">The escape character for the wildcard caracters. Default is '\'.</param> public static string ExpectLike(string expected, Action action, NormalizeOptions normalizeLineEndings = NormalizeOptions.Default, char escapeCharacter = '\\') { return(Expect(expected, action, (pattern, output) => output.IsLike(pattern, escapeCharacter), normalizeLineEndings, "The values are not like (using wildcards) each other")); }
public static String Normalize(string name, NormalizeOptions options) { string value = name.Trim(); if (IsSet(options, NormalizeOptions.TrimSpaces)) { value = Regex.Replace(value, "[ ]+", " "); // remove value = Regex.Replace(value, "[ ]+\\^[ ]+|\\^[ ]+|[ ]+\\^", "^"); } if (IsSet(options, NormalizeOptions.TrimEmptyEndingComponents)) { value = Regex.Replace(value, "[\\^]*$", ""); // remove} } return value; }
public static String Normalize(string name, NormalizeOptions options) { string value = name.Trim(); if (IsSet(options, NormalizeOptions.TrimSpaces)) { value = Regex.Replace(value, "[ ]+", " "); // remove value = Regex.Replace(value, "[ ]+\\^[ ]+|\\^[ ]+|[ ]+\\^", "^"); } if (IsSet(options, NormalizeOptions.TrimEmptyEndingComponents)) { value = Regex.Replace(value, "[\\^]*$", ""); // remove} } return(value); }
/// <summary> /// Normalizes the specified markdown to a normalized markdown text. /// </summary> /// <param name="markdown">The markdown.</param> /// <param name="writer">The destination <see cref="TextWriter"/> that will receive the result of the conversion.</param> /// <param name="options">The normalize options</param> /// <param name="pipeline">The pipeline.</param> /// <param name="context">A parser context used for the parsing.</param> /// <returns>A normalized markdown text.</returns> public static MarkdownDocument Normalize(string markdown, TextWriter writer, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null) { pipeline = pipeline ?? new MarkdownPipelineBuilder().Build(); pipeline = CheckForSelfPipeline(pipeline, markdown); // We override the renderer with our own writer var renderer = new NormalizeRenderer(writer, options); pipeline.Setup(renderer); var document = Parse(markdown, pipeline, context); renderer.Render(document); writer.Flush(); return(document); }
static bool IsSet(NormalizeOptions value, NormalizeOptions flag) { return (value & flag) == flag; }
public static void AssertNormalize(string input, string expected = null, bool trim = true, NormalizeOptions options = null, MarkdownPipeline pipeline = null) { expected = expected ?? input; input = NormText(input, trim); expected = NormText(expected, trim); pipeline = pipeline ?? new MarkdownPipelineBuilder() .UseAutoLinks() .UseJiraLinks(new Extensions.JiraLinks.JiraLinkOptions("https://jira.example.com")) .UseTaskLists() .Build(); var result = Markdown.Normalize(input, options, pipeline: pipeline); result = NormText(result, trim); TestParser.PrintAssertExpected(input, result, expected); }
internal abstract void Normalize(NormalizeOptions normalizeOptions, bool allowUTF8);
static bool IsSet(NormalizeOptions value, NormalizeOptions flag) { return((value & flag) == flag); }
public void AssertNormalize(string input, string expected = null, bool trim = true, NormalizeOptions options = null) { expected = expected ?? input; input = NormText(input, trim); expected = NormText(expected, trim); var pipeline = new MarkdownPipelineBuilder() .UseTaskLists() .Build(); var result = Markdown.Normalize(input, options, pipeline: pipeline); result = NormText(result, trim); Console.WriteLine("```````````````````Source"); Console.WriteLine(TestParser.DisplaySpaceAndTabs(input)); Console.WriteLine("```````````````````Result"); Console.WriteLine(TestParser.DisplaySpaceAndTabs(result)); Console.WriteLine("```````````````````Expected"); Console.WriteLine(TestParser.DisplaySpaceAndTabs(expected)); Console.WriteLine("```````````````````"); Console.WriteLine(); TextAssert.AreEqual(expected, result); }
public void AssertNormalizeNoTrim(string input, string expected = null, NormalizeOptions options = null) => AssertNormalize(input, expected, false, options);