Просмотр исходного кода

Fix indentation of block map under sequence.

Do this:

  - A
  - B:
      - C
      - D

Instead of that:

  - A
  -   B:
      - C
      - D
Gustavo Niemeyer 7 лет назад
Родитель
Сommit
b9fa90259b
2 измененных файлов с 5 добавлено и 3 удалено
  1. 4 2
      emitterc.go
  2. 1 1
      encode_test.go

+ 4 - 2
emitterc.go

@@ -742,8 +742,10 @@ func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_ev
 	if !yaml_emitter_process_header_comment(emitter) {
 		return false
 	}
-	if !yaml_emitter_write_indent(emitter) {
-		return false
+	if emitter.states[len(emitter.states)-1] != yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE {
+		if !yaml_emitter_write_indent(emitter) {
+			return false
+		}
 	}
 	if yaml_emitter_check_simple_key(emitter) {
 		emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE)

+ 1 - 1
encode_test.go

@@ -104,7 +104,7 @@ var marshalTests = []struct {
 		"v:\n- A\n- |-\n    B\n    C\n",
 	}, {
 		map[string][]interface{}{"v": []interface{}{"A", 1, map[string][]int{"B": []int{2, 3}}}},
-		"v:\n- A\n- 1\n-   B:\n    - 2\n    - 3\n",
+		"v:\n- A\n- 1\n- B:\n    - 2\n    - 3\n",
 	}, {
 		map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
 		"a:\n    b: c\n",