public void Output_Of_String() { var so = new StringOutput(16); so.Write("text", null !); Assert.AreEqual("text", so.ToString()); }
public void StringOutputTest() { var so = new StringOutput(); so.Write("text", 0, 2, null); Assert.AreEqual("te", so.ToString()); }
public void Output_Of_ValueStringBuilder() { var so = new StringOutput(); using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder(); sb.Append("text"); so.Write(sb, null !); Assert.AreEqual("text", so.ToString()); }
/// <summary> /// Replaces one or more format items in a specified string with the string representation of a specific object. /// </summary> /// <param name="provider">The <see cref="IFormatProvider" /> to use.</param> /// <param name="format">A composite format string.</param> /// <param name="args">The object to format.</param> /// <returns>Returns the formatted input with items replaced with their string representation.</returns> public string Format(IFormatProvider?provider, string format, params object[] args) { var output = new StringOutput(format.Length + args.Length * 8); var formatParsed = Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames()); var current = args.Length > 0 ? args[0] : args; // The first item is the default. var formatDetails = new FormatDetails(this, formatParsed, args, null, provider, output); Format(formatDetails, formatParsed, current); return(output.ToString()); }
void StringOutput_uses_input_sb() { var sb = new System.Text.StringBuilder(); sb.Append("Text"); var output = new StringOutput(sb); output.Write("hello", FormatterTextKind.Text); Assert.Equal("Texthello", sb.ToString()); Assert.Equal("Texthello", output.ToString()); }
public void Format_WithCache_Into_StringOutput() { var data = new { Name = "Joe", City = "Melbourne" }; var formatter = GetSimpleFormatter(); var formatString = "{Name}, {City}"; var format = formatter.Parser.ParseFormat(formatString); var output = new StringOutput(); formatter.FormatInto(output, null, format, data); Assert.That(output.ToString(), Is.EqualTo($"{data.Name}, {data.City}")); }
/// <summary> /// Replaces one or more format items in a specified string with the string representation of a specific object, /// using the <see cref="FormatCache"/>. /// </summary> /// <param name="cache">The <see cref="FormatCache" /> to use.</param> /// <param name="format">A composite format string.</param> /// <param name="args">The objects to format.</param> /// <returns>Returns the formatted input with items replaced with their string representation.</returns> public string FormatWithCache(ref FormatCache?cache, string format, params object[] args) { var output = new StringOutput(format.Length + args.Length * 8); cache ??= new FormatCache(Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames())); var current = args.Length > 0 ? args[0] : args; // The first item is the default. var formatDetails = new FormatDetails(this, cache.Format, args, cache, null, output); Format(formatDetails, cache.Format, current); return(output.ToString()); }
internal static string Format(Instruction instruction, Formatter formatter, bool printInstructionAddresses, uint pointerSize) { var output = new StringOutput(); if (printInstructionAddresses) { FormatInstructionPointer(instruction, formatter, pointerSize, output); } formatter.Format(instruction, output); return(output.ToString()); }
public void ToString_StringInput_ReturnsString() { //arrange string input = "item1"; IOutput output = new StringOutput(input); //act string result = output.ToString(); //assert Assert.NotNull(output); Assert.NotNull(result); Assert.Equal("item1", result); }