Codebase list golang-yaml.v2 / 4df6034
Update upstream source from tag 'upstream/2.4.0' Update to upstream version '2.4.0' with Debian dir d77de48afd34538df52af976a595677d46516a73 Anthony Fok 3 years ago
5 changed file(s) with 44 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1010 - "1.11.x"
1111 - "1.12.x"
1212 - "1.13.x"
13 - "1.14.x"
1314 - "tip"
1415
1516 go_import_path: gopkg.in/yaml.v2
7878 parser.encoding = encoding
7979 }
8080
81 var disableLineWrapping = false
82
8183 // Create a new emitter object.
8284 func yaml_emitter_initialize(emitter *yaml_emitter_t) {
8385 *emitter = yaml_emitter_t{
8587 raw_buffer: make([]byte, 0, output_raw_buffer_size),
8688 states: make([]yaml_emitter_state_t, 0, initial_stack_size),
8789 events: make([]yaml_event_t, 0, initial_queue_size),
88 best_width: -1,
90 }
91 if disableLineWrapping {
92 emitter.best_width = -1
8993 }
9094 }
9195
396396 map[string]interface{}{"a": jsonNumberT("bogus")},
397397 "a: bogus\n",
398398 },
399 // Ensure that strings do not wrap
400 {
401 map[string]string{"a": "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 "},
402 "a: 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 '\n",
403 },
399 }
400
401 func (s *S) TestLineWrapping(c *C) {
402 var v = map[string]string{
403 "a": "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 ",
404 }
405 data, err := yaml.Marshal(v)
406 c.Assert(err, IsNil)
407 c.Assert(string(data), Equals,
408 "a: 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz\n" +
409 " ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 '\n")
410
411 // The API does not allow this process to be reversed as it's intended
412 // for migration only. v3 drops this method and instead offers more
413 // control on a per encoding basis.
414 yaml.FutureLineWrap()
415
416 data, err = yaml.Marshal(v)
417 c.Assert(err, IsNil)
418 c.Assert(string(data), Equals,
419 "a: 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 '\n")
404420 }
405421
406422 func (s *S) TestMarshal(c *C) {
0 module "gopkg.in/yaml.v2"
0 module gopkg.in/yaml.v2
11
2 require (
3 "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405
4 )
2 go 1.15
3
4 require gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
174174 // Zero valued structs will be omitted if all their public
175175 // fields are zero, unless they implement an IsZero
176176 // method (see the IsZeroer interface type), in which
177 // case the field will be included if that method returns true.
177 // case the field will be excluded if IsZero returns true.
178178 //
179179 // flow Marshal using a flow style (useful for structs,
180180 // sequences and maps).
463463 }
464464 return false
465465 }
466
467 // FutureLineWrap globally disables line wrapping when encoding long strings.
468 // This is a temporary and thus deprecated method introduced to faciliate
469 // migration towards v3, which offers more control of line lengths on
470 // individual encodings, and has a default matching the behavior introduced
471 // by this function.
472 //
473 // The default formatting of v2 was erroneously changed in v2.3.0 and reverted
474 // in v2.4.0, at which point this function was introduced to help migration.
475 func FutureLineWrap() {
476 disableLineWrapping = true
477 }