decode_test.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. package yaml_test
  2. import (
  3. . "gopkg.in/check.v1"
  4. "gopkg.in/yaml.v1"
  5. "math"
  6. "reflect"
  7. "strings"
  8. "time"
  9. )
  10. var unmarshalIntTest = 123
  11. var unmarshalTests = []struct {
  12. data string
  13. value interface{}
  14. }{
  15. {
  16. "",
  17. &struct{}{},
  18. }, {
  19. "{}", &struct{}{},
  20. }, {
  21. "v: hi",
  22. map[string]string{"v": "hi"},
  23. }, {
  24. "v: hi", map[string]interface{}{"v": "hi"},
  25. }, {
  26. "v: true",
  27. map[string]string{"v": "true"},
  28. }, {
  29. "v: true",
  30. map[string]interface{}{"v": true},
  31. }, {
  32. "v: 10",
  33. map[string]interface{}{"v": 10},
  34. }, {
  35. "v: 0b10",
  36. map[string]interface{}{"v": 2},
  37. }, {
  38. "v: 0xA",
  39. map[string]interface{}{"v": 10},
  40. }, {
  41. "v: 4294967296",
  42. map[string]int64{"v": 4294967296},
  43. }, {
  44. "v: 0.1",
  45. map[string]interface{}{"v": 0.1},
  46. }, {
  47. "v: .1",
  48. map[string]interface{}{"v": 0.1},
  49. }, {
  50. "v: .Inf",
  51. map[string]interface{}{"v": math.Inf(+1)},
  52. }, {
  53. "v: -.Inf",
  54. map[string]interface{}{"v": math.Inf(-1)},
  55. }, {
  56. "v: -10",
  57. map[string]interface{}{"v": -10},
  58. }, {
  59. "v: -.1",
  60. map[string]interface{}{"v": -0.1},
  61. },
  62. // Simple values.
  63. {
  64. "123",
  65. &unmarshalIntTest,
  66. },
  67. // Floats from spec
  68. {
  69. "canonical: 6.8523e+5",
  70. map[string]interface{}{"canonical": 6.8523e+5},
  71. }, {
  72. "expo: 685.230_15e+03",
  73. map[string]interface{}{"expo": 685.23015e+03},
  74. }, {
  75. "fixed: 685_230.15",
  76. map[string]interface{}{"fixed": 685230.15},
  77. }, {
  78. "neginf: -.inf",
  79. map[string]interface{}{"neginf": math.Inf(-1)},
  80. }, {
  81. "fixed: 685_230.15",
  82. map[string]float64{"fixed": 685230.15},
  83. },
  84. //{"sexa: 190:20:30.15", map[string]interface{}{"sexa": 0}}, // Unsupported
  85. //{"notanum: .NaN", map[string]interface{}{"notanum": math.NaN()}}, // Equality of NaN fails.
  86. // Bools from spec
  87. {
  88. "canonical: y",
  89. map[string]interface{}{"canonical": true},
  90. }, {
  91. "answer: NO",
  92. map[string]interface{}{"answer": false},
  93. }, {
  94. "logical: True",
  95. map[string]interface{}{"logical": true},
  96. }, {
  97. "option: on",
  98. map[string]interface{}{"option": true},
  99. }, {
  100. "option: on",
  101. map[string]bool{"option": true},
  102. },
  103. // Ints from spec
  104. {
  105. "canonical: 685230",
  106. map[string]interface{}{"canonical": 685230},
  107. }, {
  108. "decimal: +685_230",
  109. map[string]interface{}{"decimal": 685230},
  110. }, {
  111. "octal: 02472256",
  112. map[string]interface{}{"octal": 685230},
  113. }, {
  114. "hexa: 0x_0A_74_AE",
  115. map[string]interface{}{"hexa": 685230},
  116. }, {
  117. "bin: 0b1010_0111_0100_1010_1110",
  118. map[string]interface{}{"bin": 685230},
  119. }, {
  120. "bin: -0b101010",
  121. map[string]interface{}{"bin": -42},
  122. }, {
  123. "decimal: +685_230",
  124. map[string]int{"decimal": 685230},
  125. },
  126. //{"sexa: 190:20:30", map[string]interface{}{"sexa": 0}}, // Unsupported
  127. // Nulls from spec
  128. {
  129. "empty:",
  130. map[string]interface{}{"empty": nil},
  131. }, {
  132. "canonical: ~",
  133. map[string]interface{}{"canonical": nil},
  134. }, {
  135. "english: null",
  136. map[string]interface{}{"english": nil},
  137. }, {
  138. "~: null key",
  139. map[interface{}]string{nil: "null key"},
  140. }, {
  141. "empty:",
  142. map[string]*bool{"empty": nil},
  143. },
  144. // Flow sequence
  145. {
  146. "seq: [A,B]",
  147. map[string]interface{}{"seq": []interface{}{"A", "B"}},
  148. }, {
  149. "seq: [A,B,C,]",
  150. map[string][]string{"seq": []string{"A", "B", "C"}},
  151. }, {
  152. "seq: [A,1,C]",
  153. map[string][]string{"seq": []string{"A", "1", "C"}},
  154. }, {
  155. "seq: [A,1,C]",
  156. map[string][]int{"seq": []int{1}},
  157. }, {
  158. "seq: [A,1,C]",
  159. map[string]interface{}{"seq": []interface{}{"A", 1, "C"}},
  160. },
  161. // Block sequence
  162. {
  163. "seq:\n - A\n - B",
  164. map[string]interface{}{"seq": []interface{}{"A", "B"}},
  165. }, {
  166. "seq:\n - A\n - B\n - C",
  167. map[string][]string{"seq": []string{"A", "B", "C"}},
  168. }, {
  169. "seq:\n - A\n - 1\n - C",
  170. map[string][]string{"seq": []string{"A", "1", "C"}},
  171. }, {
  172. "seq:\n - A\n - 1\n - C",
  173. map[string][]int{"seq": []int{1}},
  174. }, {
  175. "seq:\n - A\n - 1\n - C",
  176. map[string]interface{}{"seq": []interface{}{"A", 1, "C"}},
  177. },
  178. // Literal block scalar
  179. {
  180. "scalar: | # Comment\n\n literal\n\n \ttext\n\n",
  181. map[string]string{"scalar": "\nliteral\n\n\ttext\n"},
  182. },
  183. // Folded block scalar
  184. {
  185. "scalar: > # Comment\n\n folded\n line\n \n next\n line\n * one\n * two\n\n last\n line\n\n",
  186. map[string]string{"scalar": "\nfolded line\nnext line\n * one\n * two\n\nlast line\n"},
  187. },
  188. // Map inside interface with no type hints.
  189. {
  190. "a: {b: c}",
  191. map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
  192. },
  193. // Structs and type conversions.
  194. {
  195. "hello: world",
  196. &struct{ Hello string }{"world"},
  197. }, {
  198. "a: {b: c}",
  199. &struct{ A struct{ B string } }{struct{ B string }{"c"}},
  200. }, {
  201. "a: {b: c}",
  202. &struct{ A *struct{ B string } }{&struct{ B string }{"c"}},
  203. }, {
  204. "a: {b: c}",
  205. &struct{ A map[string]string }{map[string]string{"b": "c"}},
  206. }, {
  207. "a: {b: c}",
  208. &struct{ A *map[string]string }{&map[string]string{"b": "c"}},
  209. }, {
  210. "a:",
  211. &struct{ A map[string]string }{},
  212. }, {
  213. "a: 1",
  214. &struct{ A int }{1},
  215. }, {
  216. "a: 1",
  217. &struct{ A float64 }{1},
  218. }, {
  219. "a: 1.0",
  220. &struct{ A int }{1},
  221. }, {
  222. "a: 1.0",
  223. &struct{ A uint }{1},
  224. }, {
  225. "a: [1, 2]",
  226. &struct{ A []int }{[]int{1, 2}},
  227. }, {
  228. "a: 1",
  229. &struct{ B int }{0},
  230. }, {
  231. "a: 1",
  232. &struct {
  233. B int "a"
  234. }{1},
  235. }, {
  236. "a: y",
  237. &struct{ A bool }{true},
  238. },
  239. // Some cross type conversions
  240. {
  241. "v: 42",
  242. map[string]uint{"v": 42},
  243. }, {
  244. "v: -42",
  245. map[string]uint{},
  246. }, {
  247. "v: 4294967296",
  248. map[string]uint64{"v": 4294967296},
  249. }, {
  250. "v: -4294967296",
  251. map[string]uint64{},
  252. },
  253. // Overflow cases.
  254. {
  255. "v: 4294967297",
  256. map[string]int32{},
  257. }, {
  258. "v: 128",
  259. map[string]int8{},
  260. },
  261. // Quoted values.
  262. {
  263. "'1': '\"2\"'",
  264. map[interface{}]interface{}{"1": "\"2\""},
  265. }, {
  266. "v:\n- A\n- 'B\n\n C'\n",
  267. map[string][]string{"v": []string{"A", "B\nC"}},
  268. },
  269. // Explicit tags.
  270. {
  271. "v: !!float '1.1'",
  272. map[string]interface{}{"v": 1.1},
  273. }, {
  274. "v: !!null ''",
  275. map[string]interface{}{"v": nil},
  276. }, {
  277. "%TAG !y! tag:yaml.org,2002:\n---\nv: !y!int '1'",
  278. map[string]interface{}{"v": 1},
  279. },
  280. // Anchors and aliases.
  281. {
  282. "a: &x 1\nb: &y 2\nc: *x\nd: *y\n",
  283. &struct{ A, B, C, D int }{1, 2, 1, 2},
  284. }, {
  285. "a: &a {c: 1}\nb: *a",
  286. &struct {
  287. A, B struct {
  288. C int
  289. }
  290. }{struct{ C int }{1}, struct{ C int }{1}},
  291. }, {
  292. "a: &a [1, 2]\nb: *a",
  293. &struct{ B []int }{[]int{1, 2}},
  294. },
  295. // Bug #1133337
  296. {
  297. "foo: ''",
  298. map[string]*string{"foo": new(string)},
  299. }, {
  300. "foo: null",
  301. map[string]string{"foo": ""},
  302. }, {
  303. "foo: null",
  304. map[string]interface{}{"foo": nil},
  305. },
  306. // Ignored field
  307. {
  308. "a: 1\nb: 2\n",
  309. &struct {
  310. A int
  311. B int "-"
  312. }{1, 0},
  313. },
  314. // Bug #1191981
  315. {
  316. "" +
  317. "%YAML 1.1\n" +
  318. "--- !!str\n" +
  319. `"Generic line break (no glyph)\n\` + "\n" +
  320. ` Generic line break (glyphed)\n\` + "\n" +
  321. ` Line separator\u2028\` + "\n" +
  322. ` Paragraph separator\u2029"` + "\n",
  323. "" +
  324. "Generic line break (no glyph)\n" +
  325. "Generic line break (glyphed)\n" +
  326. "Line separator\u2028Paragraph separator\u2029",
  327. },
  328. // Struct inlining
  329. {
  330. "a: 1\nb: 2\nc: 3\n",
  331. &struct {
  332. A int
  333. C inlineB `yaml:",inline"`
  334. }{1, inlineB{2, inlineC{3}}},
  335. },
  336. // bug 1243827
  337. {
  338. "a: -b_c",
  339. map[string]interface{}{"a": "-b_c"},
  340. },
  341. {
  342. "a: +b_c",
  343. map[string]interface{}{"a": "+b_c"},
  344. },
  345. {
  346. "a: 50cent_of_dollar",
  347. map[string]interface{}{"a": "50cent_of_dollar"},
  348. },
  349. // Duration
  350. {
  351. "a: 3s",
  352. map[string]time.Duration{"a": 3 * time.Second},
  353. },
  354. // Issue #24.
  355. {
  356. "a: <foo>",
  357. map[string]string{"a": "<foo>"},
  358. },
  359. // Base 60 floats are obsolete and unsupported.
  360. {
  361. "a: 1:1\n",
  362. map[string]string{"a": "1:1"},
  363. },
  364. // Binary data.
  365. {
  366. "a: !!binary gIGC\n",
  367. map[string]string{"a": "\x80\x81\x82"},
  368. }, {
  369. "a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
  370. map[string]string{"a": strings.Repeat("\x90", 54)},
  371. }, {
  372. "a: !!binary |\n " + strings.Repeat("A", 70) + "\n ==\n",
  373. map[string]string{"a": strings.Repeat("\x00", 52)},
  374. },
  375. }
  376. type inlineB struct {
  377. B int
  378. inlineC `yaml:",inline"`
  379. }
  380. type inlineC struct {
  381. C int
  382. }
  383. func (s *S) TestUnmarshal(c *C) {
  384. for i, item := range unmarshalTests {
  385. t := reflect.ValueOf(item.value).Type()
  386. var value interface{}
  387. switch t.Kind() {
  388. case reflect.Map:
  389. value = reflect.MakeMap(t).Interface()
  390. case reflect.String:
  391. t := reflect.ValueOf(item.value).Type()
  392. v := reflect.New(t)
  393. value = v.Interface()
  394. default:
  395. pt := reflect.ValueOf(item.value).Type()
  396. pv := reflect.New(pt.Elem())
  397. value = pv.Interface()
  398. }
  399. err := yaml.Unmarshal([]byte(item.data), value)
  400. c.Assert(err, IsNil, Commentf("Item #%d", i))
  401. if t.Kind() == reflect.String {
  402. c.Assert(*value.(*string), Equals, item.value, Commentf("Item #%d", i))
  403. } else {
  404. c.Assert(value, DeepEquals, item.value, Commentf("Item #%d", i))
  405. }
  406. }
  407. }
  408. func (s *S) TestUnmarshalNaN(c *C) {
  409. value := map[string]interface{}{}
  410. err := yaml.Unmarshal([]byte("notanum: .NaN"), &value)
  411. c.Assert(err, IsNil)
  412. c.Assert(math.IsNaN(value["notanum"].(float64)), Equals, true)
  413. }
  414. var unmarshalErrorTests = []struct {
  415. data, error string
  416. }{
  417. {"v: !!float 'error'", "YAML error: cannot decode !!str `error` as a !!float"},
  418. {"v: [A,", "YAML error: line 1: did not find expected node content"},
  419. {"v:\n- [A,", "YAML error: line 2: did not find expected node content"},
  420. {"a: *b\n", "YAML error: Unknown anchor 'b' referenced"},
  421. {"a: &a\n b: *a\n", "YAML error: Anchor 'a' value contains itself"},
  422. {"value: -", "YAML error: block sequence entries are not allowed in this context"},
  423. {"a: !!binary ==", "YAML error: !!binary value contains invalid base64 data"},
  424. {"{[.]}", `YAML error: invalid map key: \[\]interface \{\}\{"\."\}`},
  425. {"{{.}}", `YAML error: invalid map key: map\[interface\ \{\}\]interface \{\}\{".":interface \{\}\(nil\)\}`},
  426. }
  427. func (s *S) TestUnmarshalErrors(c *C) {
  428. for _, item := range unmarshalErrorTests {
  429. var value interface{}
  430. err := yaml.Unmarshal([]byte(item.data), &value)
  431. c.Assert(err, ErrorMatches, item.error, Commentf("Partial unmarshal: %#v", value))
  432. }
  433. }
  434. var setterTests = []struct {
  435. data, tag string
  436. value interface{}
  437. }{
  438. {"_: {hi: there}", "!!map", map[interface{}]interface{}{"hi": "there"}},
  439. {"_: [1,A]", "!!seq", []interface{}{1, "A"}},
  440. {"_: 10", "!!int", 10},
  441. {"_: null", "!!null", nil},
  442. {`_: BAR!`, "!!str", "BAR!"},
  443. {`_: "BAR!"`, "!!str", "BAR!"},
  444. {"_: !!foo 'BAR!'", "!!foo", "BAR!"},
  445. }
  446. var setterResult = map[int]bool{}
  447. type typeWithSetter struct {
  448. tag string
  449. value interface{}
  450. }
  451. func (o *typeWithSetter) SetYAML(tag string, value interface{}) (ok bool) {
  452. o.tag = tag
  453. o.value = value
  454. if i, ok := value.(int); ok {
  455. if result, ok := setterResult[i]; ok {
  456. return result
  457. }
  458. }
  459. return true
  460. }
  461. type setterPointerType struct {
  462. Field *typeWithSetter "_"
  463. }
  464. type setterValueType struct {
  465. Field typeWithSetter "_"
  466. }
  467. func (s *S) TestUnmarshalWithPointerSetter(c *C) {
  468. for _, item := range setterTests {
  469. obj := &setterPointerType{}
  470. err := yaml.Unmarshal([]byte(item.data), obj)
  471. c.Assert(err, IsNil)
  472. c.Assert(obj.Field, NotNil, Commentf("Pointer not initialized (%#v)", item.value))
  473. c.Assert(obj.Field.tag, Equals, item.tag)
  474. c.Assert(obj.Field.value, DeepEquals, item.value)
  475. }
  476. }
  477. func (s *S) TestUnmarshalWithValueSetter(c *C) {
  478. for _, item := range setterTests {
  479. obj := &setterValueType{}
  480. err := yaml.Unmarshal([]byte(item.data), obj)
  481. c.Assert(err, IsNil)
  482. c.Assert(obj.Field, NotNil, Commentf("Pointer not initialized (%#v)", item.value))
  483. c.Assert(obj.Field.tag, Equals, item.tag)
  484. c.Assert(obj.Field.value, DeepEquals, item.value)
  485. }
  486. }
  487. func (s *S) TestUnmarshalWholeDocumentWithSetter(c *C) {
  488. obj := &typeWithSetter{}
  489. err := yaml.Unmarshal([]byte(setterTests[0].data), obj)
  490. c.Assert(err, IsNil)
  491. c.Assert(obj.tag, Equals, setterTests[0].tag)
  492. value, ok := obj.value.(map[interface{}]interface{})
  493. c.Assert(ok, Equals, true)
  494. c.Assert(value["_"], DeepEquals, setterTests[0].value)
  495. }
  496. func (s *S) TestUnmarshalWithFalseSetterIgnoresValue(c *C) {
  497. setterResult[2] = false
  498. setterResult[4] = false
  499. defer func() {
  500. delete(setterResult, 2)
  501. delete(setterResult, 4)
  502. }()
  503. m := map[string]*typeWithSetter{}
  504. data := `{abc: 1, def: 2, ghi: 3, jkl: 4}`
  505. err := yaml.Unmarshal([]byte(data), m)
  506. c.Assert(err, IsNil)
  507. c.Assert(m["abc"], NotNil)
  508. c.Assert(m["def"], IsNil)
  509. c.Assert(m["ghi"], NotNil)
  510. c.Assert(m["jkl"], IsNil)
  511. c.Assert(m["abc"].value, Equals, 1)
  512. c.Assert(m["ghi"].value, Equals, 3)
  513. }
  514. // From http://yaml.org/type/merge.html
  515. var mergeTests = `
  516. anchors:
  517. - &CENTER { "x": 1, "y": 2 }
  518. - &LEFT { "x": 0, "y": 2 }
  519. - &BIG { "r": 10 }
  520. - &SMALL { "r": 1 }
  521. # All the following maps are equal:
  522. plain:
  523. # Explicit keys
  524. "x": 1
  525. "y": 2
  526. "r": 10
  527. label: center/big
  528. mergeOne:
  529. # Merge one map
  530. << : *CENTER
  531. "r": 10
  532. label: center/big
  533. mergeMultiple:
  534. # Merge multiple maps
  535. << : [ *CENTER, *BIG ]
  536. label: center/big
  537. override:
  538. # Override
  539. << : [ *BIG, *LEFT, *SMALL ]
  540. "x": 1
  541. label: center/big
  542. shortTag:
  543. # Explicit short merge tag
  544. !!merge "<<" : [ *CENTER, *BIG ]
  545. label: center/big
  546. longTag:
  547. # Explicit merge long tag
  548. !<tag:yaml.org,2002:merge> "<<" : [ *CENTER, *BIG ]
  549. label: center/big
  550. inlineMap:
  551. # Inlined map
  552. << : {"x": 1, "y": 2, "r": 10}
  553. label: center/big
  554. inlineSequenceMap:
  555. # Inlined map in sequence
  556. << : [ *CENTER, {"r": 10} ]
  557. label: center/big
  558. `
  559. func (s *S) TestMerge(c *C) {
  560. var want = map[interface{}]interface{}{
  561. "x": 1,
  562. "y": 2,
  563. "r": 10,
  564. "label": "center/big",
  565. }
  566. var m map[string]interface{}
  567. err := yaml.Unmarshal([]byte(mergeTests), &m)
  568. c.Assert(err, IsNil)
  569. for name, test := range m {
  570. if name == "anchors" {
  571. continue
  572. }
  573. c.Assert(test, DeepEquals, want, Commentf("test %q failed", name))
  574. }
  575. }
  576. func (s *S) TestMergeStruct(c *C) {
  577. type Data struct {
  578. X, Y, R int
  579. Label string
  580. }
  581. want := Data{1, 2, 10, "center/big"}
  582. var m map[string]Data
  583. err := yaml.Unmarshal([]byte(mergeTests), &m)
  584. c.Assert(err, IsNil)
  585. for name, test := range m {
  586. if name == "anchors" {
  587. continue
  588. }
  589. c.Assert(test, Equals, want, Commentf("test %q failed", name))
  590. }
  591. }
  592. var unmarshalNullTests = []func() interface{}{
  593. func() interface{} { var v interface{}; v = "v"; return &v },
  594. func() interface{} { var s = "s"; return &s },
  595. func() interface{} { var s = "s"; sptr := &s; return &sptr },
  596. func() interface{} { var i = 1; return &i },
  597. func() interface{} { var i = 1; iptr := &i; return &iptr },
  598. func() interface{} { m := map[string]int{"s": 1}; return &m },
  599. func() interface{} { m := map[string]int{"s": 1}; return m },
  600. }
  601. func (s *S) TestUnmarshalNull(c *C) {
  602. for _, test := range unmarshalNullTests {
  603. item := test()
  604. zero := reflect.Zero(reflect.TypeOf(item).Elem()).Interface()
  605. err := yaml.Unmarshal([]byte("null"), item)
  606. c.Assert(err, IsNil)
  607. if reflect.TypeOf(item).Kind() == reflect.Map {
  608. c.Assert(reflect.ValueOf(item).Interface(), DeepEquals, reflect.MakeMap(reflect.TypeOf(item)).Interface())
  609. } else {
  610. c.Assert(reflect.ValueOf(item).Elem().Interface(), DeepEquals, zero)
  611. }
  612. }
  613. }
  614. //var data []byte
  615. //func init() {
  616. // var err error
  617. // data, err = ioutil.ReadFile("/tmp/file.yaml")
  618. // if err != nil {
  619. // panic(err)
  620. // }
  621. //}
  622. //
  623. //func (s *S) BenchmarkUnmarshal(c *C) {
  624. // var err error
  625. // for i := 0; i < c.N; i++ {
  626. // var v map[string]interface{}
  627. // err = yaml.Unmarshal(data, &v)
  628. // }
  629. // if err != nil {
  630. // panic(err)
  631. // }
  632. //}
  633. //
  634. //func (s *S) BenchmarkMarshal(c *C) {
  635. // var v map[string]interface{}
  636. // yaml.Unmarshal(data, &v)
  637. // c.ResetTimer()
  638. // for i := 0; i < c.N; i++ {
  639. // yaml.Marshal(&v)
  640. // }
  641. //}