mirror of
https://github.com/jimeh/undent.git
synced 2026-02-19 11:56:39 +00:00
This effectively cleans up what I consider syntactical sugar required
due to Go's syntax. For example:
str := undent.String(`
hello
world`,
)
In the above example I would consider the initial line-break after the
opening back-tick (`) character syntactical sugar, and hence should be
discarded from the final undented string.
However if the literal string contains more than one initial line-break,
only the first one should be removed, as the rest would intentionally be
part of the input.
49 lines
527 B
Go
49 lines
527 B
Go
package undent_test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jimeh/undent"
|
|
)
|
|
|
|
func ExampleBytes() {
|
|
b := undent.Bytes([]byte(`
|
|
{
|
|
"hello": "world"
|
|
}`,
|
|
))
|
|
|
|
fmt.Println(string(b))
|
|
// Output:
|
|
// {
|
|
// "hello": "world"
|
|
// }
|
|
}
|
|
|
|
func ExampleString() {
|
|
s := undent.String(`
|
|
{
|
|
"hello": "world"
|
|
}`,
|
|
)
|
|
fmt.Println(s)
|
|
// Output:
|
|
// {
|
|
// "hello": "world"
|
|
// }
|
|
}
|
|
|
|
func ExampleStringf() {
|
|
s := undent.Stringf(`
|
|
{
|
|
"hello": "%s"
|
|
}`,
|
|
"world",
|
|
)
|
|
fmt.Println(s)
|
|
// Output:
|
|
// {
|
|
// "hello": "world"
|
|
// }
|
|
}
|