encode_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. //
  2. // Copyright (c) 2011-2019 Canonical Ltd
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. package yaml_test
  16. import (
  17. "bytes"
  18. "fmt"
  19. "math"
  20. "strconv"
  21. "strings"
  22. "time"
  23. "net"
  24. "os"
  25. . "gopkg.in/check.v1"
  26. "gopkg.in/yaml.v3"
  27. )
  28. var marshalIntTest = 123
  29. var marshalTests = []struct {
  30. value interface{}
  31. data string
  32. }{
  33. {
  34. nil,
  35. "null\n",
  36. }, {
  37. (*marshalerType)(nil),
  38. "null\n",
  39. }, {
  40. &struct{}{},
  41. "{}\n",
  42. }, {
  43. map[string]string{"v": "hi"},
  44. "v: hi\n",
  45. }, {
  46. map[string]interface{}{"v": "hi"},
  47. "v: hi\n",
  48. }, {
  49. map[string]string{"v": "true"},
  50. "v: \"true\"\n",
  51. }, {
  52. map[string]string{"v": "false"},
  53. "v: \"false\"\n",
  54. }, {
  55. map[string]interface{}{"v": true},
  56. "v: true\n",
  57. }, {
  58. map[string]interface{}{"v": false},
  59. "v: false\n",
  60. }, {
  61. map[string]interface{}{"v": 10},
  62. "v: 10\n",
  63. }, {
  64. map[string]interface{}{"v": -10},
  65. "v: -10\n",
  66. }, {
  67. map[string]uint{"v": 42},
  68. "v: 42\n",
  69. }, {
  70. map[string]interface{}{"v": int64(4294967296)},
  71. "v: 4294967296\n",
  72. }, {
  73. map[string]int64{"v": int64(4294967296)},
  74. "v: 4294967296\n",
  75. }, {
  76. map[string]uint64{"v": 4294967296},
  77. "v: 4294967296\n",
  78. }, {
  79. map[string]interface{}{"v": "10"},
  80. "v: \"10\"\n",
  81. }, {
  82. map[string]interface{}{"v": 0.1},
  83. "v: 0.1\n",
  84. }, {
  85. map[string]interface{}{"v": float64(0.1)},
  86. "v: 0.1\n",
  87. }, {
  88. map[string]interface{}{"v": float32(0.99)},
  89. "v: 0.99\n",
  90. }, {
  91. map[string]interface{}{"v": -0.1},
  92. "v: -0.1\n",
  93. }, {
  94. map[string]interface{}{"v": math.Inf(+1)},
  95. "v: .inf\n",
  96. }, {
  97. map[string]interface{}{"v": math.Inf(-1)},
  98. "v: -.inf\n",
  99. }, {
  100. map[string]interface{}{"v": math.NaN()},
  101. "v: .nan\n",
  102. }, {
  103. map[string]interface{}{"v": nil},
  104. "v: null\n",
  105. }, {
  106. map[string]interface{}{"v": ""},
  107. "v: \"\"\n",
  108. }, {
  109. map[string][]string{"v": []string{"A", "B"}},
  110. "v:\n - A\n - B\n",
  111. }, {
  112. map[string][]string{"v": []string{"A", "B\nC"}},
  113. "v:\n - A\n - |-\n B\n C\n",
  114. }, {
  115. map[string][]interface{}{"v": []interface{}{"A", 1, map[string][]int{"B": []int{2, 3}}}},
  116. "v:\n - A\n - 1\n - B:\n - 2\n - 3\n",
  117. }, {
  118. map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
  119. "a:\n b: c\n",
  120. }, {
  121. map[string]interface{}{"a": "-"},
  122. "a: '-'\n",
  123. },
  124. // Simple values.
  125. {
  126. &marshalIntTest,
  127. "123\n",
  128. },
  129. // Structures
  130. {
  131. &struct{ Hello string }{"world"},
  132. "hello: world\n",
  133. }, {
  134. &struct {
  135. A struct {
  136. B string
  137. }
  138. }{struct{ B string }{"c"}},
  139. "a:\n b: c\n",
  140. }, {
  141. &struct {
  142. A *struct {
  143. B string
  144. }
  145. }{&struct{ B string }{"c"}},
  146. "a:\n b: c\n",
  147. }, {
  148. &struct {
  149. A *struct {
  150. B string
  151. }
  152. }{},
  153. "a: null\n",
  154. }, {
  155. &struct{ A int }{1},
  156. "a: 1\n",
  157. }, {
  158. &struct{ A []int }{[]int{1, 2}},
  159. "a:\n - 1\n - 2\n",
  160. }, {
  161. &struct{ A [2]int }{[2]int{1, 2}},
  162. "a:\n - 1\n - 2\n",
  163. }, {
  164. &struct {
  165. B int "a"
  166. }{1},
  167. "a: 1\n",
  168. }, {
  169. &struct{ A bool }{true},
  170. "a: true\n",
  171. }, {
  172. &struct{ A string }{"true"},
  173. "a: \"true\"\n",
  174. }, {
  175. &struct{ A string }{"off"},
  176. "a: \"off\"\n",
  177. },
  178. // Conditional flag
  179. {
  180. &struct {
  181. A int "a,omitempty"
  182. B int "b,omitempty"
  183. }{1, 0},
  184. "a: 1\n",
  185. }, {
  186. &struct {
  187. A int "a,omitempty"
  188. B int "b,omitempty"
  189. }{0, 0},
  190. "{}\n",
  191. }, {
  192. &struct {
  193. A *struct{ X, y int } "a,omitempty,flow"
  194. }{&struct{ X, y int }{1, 2}},
  195. "a: {x: 1}\n",
  196. }, {
  197. &struct {
  198. A *struct{ X, y int } "a,omitempty,flow"
  199. }{nil},
  200. "{}\n",
  201. }, {
  202. &struct {
  203. A *struct{ X, y int } "a,omitempty,flow"
  204. }{&struct{ X, y int }{}},
  205. "a: {x: 0}\n",
  206. }, {
  207. &struct {
  208. A struct{ X, y int } "a,omitempty,flow"
  209. }{struct{ X, y int }{1, 2}},
  210. "a: {x: 1}\n",
  211. }, {
  212. &struct {
  213. A struct{ X, y int } "a,omitempty,flow"
  214. }{struct{ X, y int }{0, 1}},
  215. "{}\n",
  216. }, {
  217. &struct {
  218. A float64 "a,omitempty"
  219. B float64 "b,omitempty"
  220. }{1, 0},
  221. "a: 1\n",
  222. },
  223. {
  224. &struct {
  225. T1 time.Time "t1,omitempty"
  226. T2 time.Time "t2,omitempty"
  227. T3 *time.Time "t3,omitempty"
  228. T4 *time.Time "t4,omitempty"
  229. }{
  230. T2: time.Date(2018, 1, 9, 10, 40, 47, 0, time.UTC),
  231. T4: newTime(time.Date(2098, 1, 9, 10, 40, 47, 0, time.UTC)),
  232. },
  233. "t2: 2018-01-09T10:40:47Z\nt4: 2098-01-09T10:40:47Z\n",
  234. },
  235. // Nil interface that implements Marshaler.
  236. {
  237. map[string]yaml.Marshaler{
  238. "a": nil,
  239. },
  240. "a: null\n",
  241. },
  242. // Flow flag
  243. {
  244. &struct {
  245. A []int "a,flow"
  246. }{[]int{1, 2}},
  247. "a: [1, 2]\n",
  248. }, {
  249. &struct {
  250. A map[string]string "a,flow"
  251. }{map[string]string{"b": "c", "d": "e"}},
  252. "a: {b: c, d: e}\n",
  253. }, {
  254. &struct {
  255. A struct {
  256. B, D string
  257. } "a,flow"
  258. }{struct{ B, D string }{"c", "e"}},
  259. "a: {b: c, d: e}\n",
  260. }, {
  261. &struct {
  262. A string "a,flow"
  263. }{"b\nc"},
  264. "a: \"b\\nc\"\n",
  265. },
  266. // Unexported field
  267. {
  268. &struct {
  269. u int
  270. A int
  271. }{0, 1},
  272. "a: 1\n",
  273. },
  274. // Ignored field
  275. {
  276. &struct {
  277. A int
  278. B int "-"
  279. }{1, 2},
  280. "a: 1\n",
  281. },
  282. // Struct inlining
  283. {
  284. &struct {
  285. A int
  286. C inlineB `yaml:",inline"`
  287. }{1, inlineB{2, inlineC{3}}},
  288. "a: 1\nb: 2\nc: 3\n",
  289. },
  290. // Struct inlining as a pointer
  291. {
  292. &struct {
  293. A int
  294. C *inlineB `yaml:",inline"`
  295. }{1, &inlineB{2, inlineC{3}}},
  296. "a: 1\nb: 2\nc: 3\n",
  297. }, {
  298. &struct {
  299. A int
  300. C *inlineB `yaml:",inline"`
  301. }{1, nil},
  302. "a: 1\n",
  303. }, {
  304. &struct {
  305. A int
  306. D *inlineD `yaml:",inline"`
  307. }{1, &inlineD{&inlineC{3}, 4}},
  308. "a: 1\nc: 3\nd: 4\n",
  309. },
  310. // Map inlining
  311. {
  312. &struct {
  313. A int
  314. C map[string]int `yaml:",inline"`
  315. }{1, map[string]int{"b": 2, "c": 3}},
  316. "a: 1\nb: 2\nc: 3\n",
  317. },
  318. // Duration
  319. {
  320. map[string]time.Duration{"a": 3 * time.Second},
  321. "a: 3s\n",
  322. },
  323. // Issue #24: bug in map merging logic.
  324. {
  325. map[string]string{"a": "<foo>"},
  326. "a: <foo>\n",
  327. },
  328. // Issue #34: marshal unsupported base 60 floats quoted for compatibility
  329. // with old YAML 1.1 parsers.
  330. {
  331. map[string]string{"a": "1:1"},
  332. "a: \"1:1\"\n",
  333. },
  334. // Binary data.
  335. {
  336. map[string]string{"a": "\x00"},
  337. "a: \"\\0\"\n",
  338. }, {
  339. map[string]string{"a": "\x80\x81\x82"},
  340. "a: !!binary gIGC\n",
  341. }, {
  342. map[string]string{"a": strings.Repeat("\x90", 54)},
  343. "a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
  344. },
  345. // Encode unicode as utf-8 rather than in escaped form.
  346. {
  347. map[string]string{"a": "你好"},
  348. "a: 你好\n",
  349. },
  350. // Support encoding.TextMarshaler.
  351. {
  352. map[string]net.IP{"a": net.IPv4(1, 2, 3, 4)},
  353. "a: 1.2.3.4\n",
  354. },
  355. // time.Time gets a timestamp tag.
  356. {
  357. map[string]time.Time{"a": time.Date(2015, 2, 24, 18, 19, 39, 0, time.UTC)},
  358. "a: 2015-02-24T18:19:39Z\n",
  359. },
  360. {
  361. map[string]*time.Time{"a": newTime(time.Date(2015, 2, 24, 18, 19, 39, 0, time.UTC))},
  362. "a: 2015-02-24T18:19:39Z\n",
  363. },
  364. {
  365. // This is confirmed to be properly decoded in Python (libyaml) without a timestamp tag.
  366. map[string]time.Time{"a": time.Date(2015, 2, 24, 18, 19, 39, 123456789, time.FixedZone("FOO", -3*60*60))},
  367. "a: 2015-02-24T18:19:39.123456789-03:00\n",
  368. },
  369. // Ensure timestamp-like strings are quoted.
  370. {
  371. map[string]string{"a": "2015-02-24T18:19:39Z"},
  372. "a: \"2015-02-24T18:19:39Z\"\n",
  373. },
  374. // Ensure strings containing ": " are quoted (reported as PR #43, but not reproducible).
  375. {
  376. map[string]string{"a": "b: c"},
  377. "a: 'b: c'\n",
  378. },
  379. // Containing hash mark ('#') in string should be quoted
  380. {
  381. map[string]string{"a": "Hello #comment"},
  382. "a: 'Hello #comment'\n",
  383. },
  384. {
  385. map[string]string{"a": "你好 #comment"},
  386. "a: '你好 #comment'\n",
  387. },
  388. // Ensure MarshalYAML also gets called on the result of MarshalYAML itself.
  389. {
  390. &marshalerType{marshalerType{true}},
  391. "true\n",
  392. }, {
  393. &marshalerType{&marshalerType{true}},
  394. "true\n",
  395. },
  396. // Check indentation of maps inside sequences inside maps.
  397. {
  398. map[string]interface{}{"a": map[string]interface{}{"b": []map[string]int{{"c": 1, "d": 2}}}},
  399. "a:\n b:\n - c: 1\n d: 2\n",
  400. },
  401. // Strings with tabs were disallowed as literals (issue #471).
  402. {
  403. map[string]string{"a": "\tB\n\tC\n"},
  404. "a: |\n \tB\n \tC\n",
  405. },
  406. // Ensure that strings do not wrap
  407. {
  408. map[string]string{"a": "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 "},
  409. "a: 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 '\n",
  410. },
  411. // yaml.Node
  412. {
  413. &struct {
  414. Value yaml.Node
  415. }{
  416. yaml.Node{
  417. Kind: yaml.ScalarNode,
  418. Tag: "!!str",
  419. Value: "foo",
  420. Style: yaml.SingleQuotedStyle,
  421. },
  422. },
  423. "value: 'foo'\n",
  424. }, {
  425. yaml.Node{
  426. Kind: yaml.ScalarNode,
  427. Tag: "!!str",
  428. Value: "foo",
  429. Style: yaml.SingleQuotedStyle,
  430. },
  431. "'foo'\n",
  432. },
  433. // Enforced tagging with shorthand notation (issue #616).
  434. {
  435. &struct {
  436. Value yaml.Node
  437. }{
  438. yaml.Node{
  439. Kind: yaml.ScalarNode,
  440. Style: yaml.TaggedStyle,
  441. Value: "foo",
  442. Tag: "!!str",
  443. },
  444. },
  445. "value: !!str foo\n",
  446. }, {
  447. &struct {
  448. Value yaml.Node
  449. }{
  450. yaml.Node{
  451. Kind: yaml.MappingNode,
  452. Style: yaml.TaggedStyle,
  453. Tag: "!!map",
  454. },
  455. },
  456. "value: !!map {}\n",
  457. }, {
  458. &struct {
  459. Value yaml.Node
  460. }{
  461. yaml.Node{
  462. Kind: yaml.SequenceNode,
  463. Style: yaml.TaggedStyle,
  464. Tag: "!!seq",
  465. },
  466. },
  467. "value: !!seq []\n",
  468. },
  469. }
  470. func (s *S) TestMarshal(c *C) {
  471. defer os.Setenv("TZ", os.Getenv("TZ"))
  472. os.Setenv("TZ", "UTC")
  473. for i, item := range marshalTests {
  474. c.Logf("test %d: %q", i, item.data)
  475. data, err := yaml.Marshal(item.value)
  476. c.Assert(err, IsNil)
  477. c.Assert(string(data), Equals, item.data)
  478. }
  479. }
  480. func (s *S) TestEncoderSingleDocument(c *C) {
  481. for i, item := range marshalTests {
  482. c.Logf("test %d. %q", i, item.data)
  483. var buf bytes.Buffer
  484. enc := yaml.NewEncoder(&buf)
  485. err := enc.Encode(item.value)
  486. c.Assert(err, Equals, nil)
  487. err = enc.Close()
  488. c.Assert(err, Equals, nil)
  489. c.Assert(buf.String(), Equals, item.data)
  490. }
  491. }
  492. func (s *S) TestEncoderMultipleDocuments(c *C) {
  493. var buf bytes.Buffer
  494. enc := yaml.NewEncoder(&buf)
  495. err := enc.Encode(map[string]string{"a": "b"})
  496. c.Assert(err, Equals, nil)
  497. err = enc.Encode(map[string]string{"c": "d"})
  498. c.Assert(err, Equals, nil)
  499. err = enc.Close()
  500. c.Assert(err, Equals, nil)
  501. c.Assert(buf.String(), Equals, "a: b\n---\nc: d\n")
  502. }
  503. func (s *S) TestEncoderWriteError(c *C) {
  504. enc := yaml.NewEncoder(errorWriter{})
  505. err := enc.Encode(map[string]string{"a": "b"})
  506. c.Assert(err, ErrorMatches, `yaml: write error: some write error`) // Data not flushed yet
  507. }
  508. type errorWriter struct{}
  509. func (errorWriter) Write([]byte) (int, error) {
  510. return 0, fmt.Errorf("some write error")
  511. }
  512. var marshalErrorTests = []struct {
  513. value interface{}
  514. error string
  515. panic string
  516. }{{
  517. value: &struct {
  518. B int
  519. inlineB ",inline"
  520. }{1, inlineB{2, inlineC{3}}},
  521. panic: `duplicated key 'b' in struct struct \{ B int; .*`,
  522. }, {
  523. value: &struct {
  524. A int
  525. B map[string]int ",inline"
  526. }{1, map[string]int{"a": 2}},
  527. panic: `cannot have key "a" in inlined map: conflicts with struct field`,
  528. }}
  529. func (s *S) TestMarshalErrors(c *C) {
  530. for _, item := range marshalErrorTests {
  531. if item.panic != "" {
  532. c.Assert(func() { yaml.Marshal(item.value) }, PanicMatches, item.panic)
  533. } else {
  534. _, err := yaml.Marshal(item.value)
  535. c.Assert(err, ErrorMatches, item.error)
  536. }
  537. }
  538. }
  539. func (s *S) TestMarshalTypeCache(c *C) {
  540. var data []byte
  541. var err error
  542. func() {
  543. type T struct{ A int }
  544. data, err = yaml.Marshal(&T{})
  545. c.Assert(err, IsNil)
  546. }()
  547. func() {
  548. type T struct{ B int }
  549. data, err = yaml.Marshal(&T{})
  550. c.Assert(err, IsNil)
  551. }()
  552. c.Assert(string(data), Equals, "b: 0\n")
  553. }
  554. var marshalerTests = []struct {
  555. data string
  556. value interface{}
  557. }{
  558. {"_:\n hi: there\n", map[interface{}]interface{}{"hi": "there"}},
  559. {"_:\n - 1\n - A\n", []interface{}{1, "A"}},
  560. {"_: 10\n", 10},
  561. {"_: null\n", nil},
  562. {"_: BAR!\n", "BAR!"},
  563. }
  564. type marshalerType struct {
  565. value interface{}
  566. }
  567. func (o marshalerType) MarshalText() ([]byte, error) {
  568. panic("MarshalText called on type with MarshalYAML")
  569. }
  570. func (o marshalerType) MarshalYAML() (interface{}, error) {
  571. return o.value, nil
  572. }
  573. type marshalerValue struct {
  574. Field marshalerType "_"
  575. }
  576. func (s *S) TestMarshaler(c *C) {
  577. for _, item := range marshalerTests {
  578. obj := &marshalerValue{}
  579. obj.Field.value = item.value
  580. data, err := yaml.Marshal(obj)
  581. c.Assert(err, IsNil)
  582. c.Assert(string(data), Equals, string(item.data))
  583. }
  584. }
  585. func (s *S) TestMarshalerWholeDocument(c *C) {
  586. obj := &marshalerType{}
  587. obj.value = map[string]string{"hello": "world!"}
  588. data, err := yaml.Marshal(obj)
  589. c.Assert(err, IsNil)
  590. c.Assert(string(data), Equals, "hello: world!\n")
  591. }
  592. type failingMarshaler struct{}
  593. func (ft *failingMarshaler) MarshalYAML() (interface{}, error) {
  594. return nil, failingErr
  595. }
  596. func (s *S) TestMarshalerError(c *C) {
  597. _, err := yaml.Marshal(&failingMarshaler{})
  598. c.Assert(err, Equals, failingErr)
  599. }
  600. func (s *S) TestSetIndent(c *C) {
  601. var buf bytes.Buffer
  602. enc := yaml.NewEncoder(&buf)
  603. enc.SetIndent(8)
  604. err := enc.Encode(map[string]interface{}{"a": map[string]interface{}{"b": map[string]string{"c": "d"}}})
  605. c.Assert(err, Equals, nil)
  606. err = enc.Close()
  607. c.Assert(err, Equals, nil)
  608. c.Assert(buf.String(), Equals, "a:\n b:\n c: d\n")
  609. }
  610. func (s *S) TestSortedOutput(c *C) {
  611. order := []interface{}{
  612. false,
  613. true,
  614. 1,
  615. uint(1),
  616. 1.0,
  617. 1.1,
  618. 1.2,
  619. 2,
  620. uint(2),
  621. 2.0,
  622. 2.1,
  623. "",
  624. ".1",
  625. ".2",
  626. ".a",
  627. "1",
  628. "2",
  629. "a!10",
  630. "a/0001",
  631. "a/002",
  632. "a/3",
  633. "a/10",
  634. "a/11",
  635. "a/0012",
  636. "a/100",
  637. "a~10",
  638. "ab/1",
  639. "b/1",
  640. "b/01",
  641. "b/2",
  642. "b/02",
  643. "b/3",
  644. "b/03",
  645. "b1",
  646. "b01",
  647. "b3",
  648. "c2.10",
  649. "c10.2",
  650. "d1",
  651. "d7",
  652. "d7abc",
  653. "d12",
  654. "d12a",
  655. "e2b",
  656. "e4b",
  657. "e21a",
  658. }
  659. m := make(map[interface{}]int)
  660. for _, k := range order {
  661. m[k] = 1
  662. }
  663. data, err := yaml.Marshal(m)
  664. c.Assert(err, IsNil)
  665. out := "\n" + string(data)
  666. last := 0
  667. for i, k := range order {
  668. repr := fmt.Sprint(k)
  669. if s, ok := k.(string); ok {
  670. if _, err = strconv.ParseFloat(repr, 32); s == "" || err == nil {
  671. repr = `"` + repr + `"`
  672. }
  673. }
  674. index := strings.Index(out, "\n"+repr+":")
  675. if index == -1 {
  676. c.Fatalf("%#v is not in the output: %#v", k, out)
  677. }
  678. if index < last {
  679. c.Fatalf("%#v was generated before %#v: %q", k, order[i-1], out)
  680. }
  681. last = index
  682. }
  683. }
  684. func newTime(t time.Time) *time.Time {
  685. return &t
  686. }