mirror of
https://github.com/goccy/go-yaml.git
synced 2025-10-26 10:54:20 +00:00
Add Flow option for Encoder
This commit is contained in:
parent
5e642017ee
commit
e4be76e5f8
3 changed files with 49 additions and 9 deletions
|
|
@ -495,6 +495,35 @@ c: true
|
|||
}
|
||||
}
|
||||
|
||||
func TestEncoder_Flow(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
enc := yaml.NewEncoder(&buf, yaml.Flow(true))
|
||||
var v struct {
|
||||
A int
|
||||
B string
|
||||
C struct {
|
||||
D int
|
||||
E string
|
||||
}
|
||||
F []int
|
||||
}
|
||||
v.A = 1
|
||||
v.B = "hello"
|
||||
v.C.D = 3
|
||||
v.C.E = "world"
|
||||
v.F = []int{1, 2}
|
||||
if err := enc.Encode(v); err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
expect := `
|
||||
{a: 1, b: hello, c: {d: 3, e: world}, f: [1, 2]}
|
||||
`
|
||||
actual := "\n" + buf.String()
|
||||
if expect != actual {
|
||||
t.Fatalf("flow style marshal error: expect=[%s] actual=[%s]", expect, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Example_Marshal_ExplicitAnchorAlias() {
|
||||
type T struct {
|
||||
A int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue