Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3c39489

Browse files
committed
Change default indentation to 4 spaces.
1 parent 2c9fce8 commit 3c39489

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

encode.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func (e *encoder) init() {
4242
if e.doneInit {
4343
return
4444
}
45+
if e.indent == 0 {
46+
e.indent = 4
47+
}
4548
e.emitter.best_indent = e.indent
4649
yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING)
4750
e.emit()

encode_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ var marshalTests = []struct {
101101
"v:\n- A\n- B\n",
102102
}, {
103103
map[string][]string{"v": []string{"A", "B\nC"}},
104-
"v:\n- A\n- |-\n B\n C\n",
104+
"v:\n- A\n- |-\n B\n C\n",
105105
}, {
106106
map[string][]interface{}{"v": []interface{}{"A", 1, map[string][]int{"B": []int{2, 3}}}},
107-
"v:\n- A\n- 1\n- B:\n - 2\n - 3\n",
107+
"v:\n- A\n- 1\n- B:\n - 2\n - 3\n",
108108
}, {
109109
map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
110-
"a:\n b: c\n",
110+
"a:\n b: c\n",
111111
}, {
112112
map[string]interface{}{"a": "-"},
113113
"a: '-'\n",
@@ -129,14 +129,14 @@ var marshalTests = []struct {
129129
B string
130130
}
131131
}{struct{ B string }{"c"}},
132-
"a:\n b: c\n",
132+
"a:\n b: c\n",
133133
}, {
134134
&struct {
135135
A *struct {
136136
B string
137137
}
138138
}{&struct{ B string }{"c"}},
139-
"a:\n b: c\n",
139+
"a:\n b: c\n",
140140
}, {
141141
&struct {
142142
A *struct {
@@ -312,7 +312,7 @@ var marshalTests = []struct {
312312
"a: !!binary gIGC\n",
313313
}, {
314314
map[string]string{"a": strings.Repeat("\x90", 54)},
315-
"a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
315+
"a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
316316
},
317317

318318
// Encode unicode as utf-8 rather than in escaped form.
@@ -460,7 +460,7 @@ var marshalerTests = []struct {
460460
data string
461461
value interface{}
462462
}{
463-
{"_:\n hi: there\n", map[interface{}]interface{}{"hi": "there"}},
463+
{"_:\n hi: there\n", map[interface{}]interface{}{"hi": "there"}},
464464
{"_:\n- 1\n- A\n", []interface{}{1, "A"}},
465465
{"_: 10\n", 10},
466466
{"_: null\n", nil},

node_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package yaml_test
22

33
import (
4+
"bytes"
45
"os"
56

67
. "gopkg.in/check.v1"
@@ -844,9 +845,14 @@ func (s *S) TestNodeRoundtrip(c *C) {
844845
err := yaml.Unmarshal([]byte(item.yaml), &node)
845846
c.Assert(err, IsNil)
846847
c.Assert(node, DeepEquals, item.node)
847-
data, err := yaml.Marshal(&node)
848+
buf := bytes.Buffer{}
849+
enc := yaml.NewEncoder(&buf)
850+
enc.SetIndent(2)
851+
err = enc.Encode(&node)
848852
c.Assert(err, IsNil)
849-
c.Assert(string(data), Equals, item.yaml)
853+
err = enc.Close()
854+
c.Assert(err, IsNil)
855+
c.Assert(buf.String(), Equals, item.yaml)
850856
if len(node.Children) > 0 {
851857
c.Assert(node.Children[0].ShortTag(), Equals, item.tag)
852858
}

0 commit comments

Comments
 (0)