feat(print) add Print, Printf, Fprint, and Fprintf functions

This commit is contained in:
2021-02-20 14:42:05 +00:00
parent 4ded03bd72
commit 5cae4bc420
5 changed files with 156 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package undent_test
import (
"bytes"
"fmt"
"github.com/jimeh/undent"
@@ -60,3 +61,57 @@ func ExampleStringf() {
// "hello": "world"
// }
}
func ExamplePrint() {
undent.Print(`
{
"hello": "world"
}`,
)
// Output:
// {
// "hello": "world"
// }
}
func ExamplePrintf() {
undent.Printf(`
{
"hello": "%s"
}`,
"world",
)
// Output:
// {
// "hello": "world"
// }
}
func ExampleFprint() {
var buf bytes.Buffer
undent.Fprint(&buf, `
{
"hello": "world"
}`,
)
fmt.Println(buf.String())
// Output:
// {
// "hello": "world"
// }
}
func ExampleFprintf() {
var buf bytes.Buffer
undent.Fprintf(&buf, `
{
"hello": "%s"
}`,
"world",
)
fmt.Println(buf.String())
// Output:
// {
// "hello": "world"
// }
}