public static async Task WriteTextAsync() { var writer = new ArrayBufferWriter <char>(); using var actual = writer.AsTextWriter(); using TextWriter expected = new StringWriter(InvariantCulture); await actual.WriteAsync("Hello, world!"); await expected.WriteAsync("Hello, world!"); await actual.WriteAsync("123".AsMemory()); await expected.WriteAsync("123".AsMemory()); await actual.WriteAsync('a'); await expected.WriteAsync('a'); await actual.WriteLineAsync(); await expected.WriteLineAsync(); await actual.FlushAsync(); Equal(expected.ToString(), writer.BuildString()); Equal(expected.ToString(), actual.ToString()); }
public static void ArrayBufferToString() { var writer = new ArrayBufferWriter<char>(); writer.Write("Hello, world"); writer.Write('!'); Equal("Hello, world!", writer.BuildString()); }
public static void LargePlaceholder() { var template = "Hello, world!".AsTemplate("{Very large placeholder}"); var writer = new ArrayBufferWriter<char>(); template.Render(writer, Rewrite); Equal("Hello, world!", writer.BuildString()); }
public static void EmptyPlaceholder() { var template = new MemoryTemplate<char>("Hello, world!".AsMemory(), default); var writer = new ArrayBufferWriter<char>(); template.Render(writer, Rewrite); Equal("Hello, world!", writer.BuildString()); }
public static void RenderToBuffer() { const string placeholder = "%s"; var template = "Hello, %s!%s".AsTemplate(placeholder); var writer = new ArrayBufferWriter<char>(); template.Render(writer, Rewrite); Equal("Hello, world!!", writer.BuildString()); writer.Clear(); template = "%s%s".AsTemplate(placeholder); template.Render(writer, Rewrite); Equal("world!", writer.BuildString()); writer.Clear(); template = "%s!!%s".AsTemplate(placeholder); template.Render(writer, Rewrite); Equal("world!!!", writer.BuildString()); }