Debian Codegraph @

cmd/stringer/golden_test.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // This file contains simple golden tests for various examples.
6 // Besides validating the results when the implementation changes,
7 // it provides a way to look at the generated code without having
8 // to execute the print statements in one's head.
9
10 package main
11
12 import (
13 "os"
14 "path/filepath"
15 "strings"
16 "testing"
17
18 "golang.org/x/tools/internal/testenv"
19 )
20
21 // Golden represents a test case.
22 type Golden struct {
23 name string
24 trimPrefix string
25 lineComment bool
26 input string // input; the package clause is provided when running the test.
27 output string // expected output.
28 }
29
30 var golden = []Golden{
31 {"day", "", false, day_in, day_out},
32 {"offset", "", false, offset_in, offset_out},
33 {"gap", "", false, gap_in, gap_out},
34 {"num", "", false, num_in, num_out},
35 {"unum", "", false, unum_in, unum_out},
36 {"unumpos", "", false, unumpos_in, unumpos_out},
37 {"prime", "", false, prime_in, prime_out},
38 {"prefix", "Type", false, prefix_in, prefix_out},
39 {"tokens", "", true, tokens_in, tokens_out},
40 {"overflow8", "", false, overflow8_in, overflow8_out},
41 }
42
43 // Each example starts with "type XXX [u]int", with a single space separating them.
44
45 // Simple test: enumeration of type int starting at 0.
46 const day_in = `type Day int
47 const (
48 Monday Day = iota
49 Tuesday
50 Wednesday
51 Thursday
52 Friday
53 Saturday
54 Sunday
55 )
56 `
57
58 const day_out = `func _() {
59 // An "invalid array index" compiler error signifies that the constant values have changed.
60 // Re-run the stringer command to generate them again.
61 var x [1]struct{}
62 _ = x[Monday-0]
63 _ = x[Tuesday-1]
64 _ = x[Wednesday-2]
65 _ = x[Thursday-3]
66 _ = x[Friday-4]
67 _ = x[Saturday-5]
68 _ = x[Sunday-6]
69 }
70
71 const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
72
73 var _Day_index = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
74
75 func (i Day) String() string {
76 idx := int(i) - 0
77 if i < 0 || idx >= len(_Day_index)-1 {
78 return "Day(" + strconv.FormatInt(int64(i), 10) + ")"
79 }
80 return _Day_name[_Day_index[idx]:_Day_index[idx+1]]
81 }
82 `
83
84 // Enumeration with an offset.
85 // Also includes a duplicate.
86 const offset_in = `type Number int
87 const (
88 _ Number = iota
89 One
90 Two
91 Three
92 AnotherOne = One // Duplicate; note that AnotherOne doesn't appear below.
93 )
94 `
95
96 const offset_out = `func _() {
97 // An "invalid array index" compiler error signifies that the constant values have changed.
98 // Re-run the stringer command to generate them again.
99 var x [1]struct{}
100 _ = x[One-1]
101 _ = x[Two-2]
102 _ = x[Three-3]
103 }
104
105 const _Number_name = "OneTwoThree"
106
107 var _Number_index = [...]uint8{0, 3, 6, 11}
108
109 func (i Number) String() string {
110 idx := int(i) - 1
111 if i < 1 || idx >= len(_Number_index)-1 {
112 return "Number(" + strconv.FormatInt(int64(i), 10) + ")"
113 }
114 return _Number_name[_Number_index[idx]:_Number_index[idx+1]]
115 }
116 `
117
118 // Gaps and an offset.
119 const gap_in = `type Gap int
120 const (
121 Two Gap = 2
122 Three Gap = 3
123 Five Gap = 5
124 Six Gap = 6
125 Seven Gap = 7
126 Eight Gap = 8
127 Nine Gap = 9
128 Eleven Gap = 11
129 )
130 `
131
132 const gap_out = `func _() {
133 // An "invalid array index" compiler error signifies that the constant values have changed.
134 // Re-run the stringer command to generate them again.
135 var x [1]struct{}
136 _ = x[Two-2]
137 _ = x[Three-3]
138 _ = x[Five-5]
139 _ = x[Six-6]
140 _ = x[Seven-7]
141 _ = x[Eight-8]
142 _ = x[Nine-9]
143 _ = x[Eleven-11]
144 }
145
146 const (
147 _Gap_name_0 = "TwoThree"
148 _Gap_name_1 = "FiveSixSevenEightNine"
149 _Gap_name_2 = "Eleven"
150 )
151
152 var (
153 _Gap_index_0 = [...]uint8{0, 3, 8}
154 _Gap_index_1 = [...]uint8{0, 4, 7, 12, 17, 21}
155 )
156
157 func (i Gap) String() string {
158 switch {
159 case 2 <= i && i <= 3:
160 i -= 2
161 return _Gap_name_0[_Gap_index_0[i]:_Gap_index_0[i+1]]
162 case 5 <= i && i <= 9:
163 i -= 5
164 return _Gap_name_1[_Gap_index_1[i]:_Gap_index_1[i+1]]
165 case i == 11:
166 return _Gap_name_2
167 default:
168 return "Gap(" + strconv.FormatInt(int64(i), 10) + ")"
169 }
170 }
171 `
172
173 // Signed integers spanning zero.
174 const num_in = `type Num int
175 const (
176 m_2 Num = -2 + iota
177 m_1
178 m0
179 m1
180 m2
181 )
182 `
183
184 const num_out = `func _() {
185 // An "invalid array index" compiler error signifies that the constant values have changed.
186 // Re-run the stringer command to generate them again.
187 var x [1]struct{}
188 _ = x[m_2 - -2]
189 _ = x[m_1 - -1]
190 _ = x[m0-0]
191 _ = x[m1-1]
192 _ = x[m2-2]
193 }
194
195 const _Num_name = "m_2m_1m0m1m2"
196
197 var _Num_index = [...]uint8{0, 3, 6, 8, 10, 12}
198
199 func (i Num) String() string {
200 idx := int(i) - -2
201 if i < -2 || idx >= len(_Num_index)-1 {
202 return "Num(" + strconv.FormatInt(int64(i), 10) + ")"
203 }
204 return _Num_name[_Num_index[idx]:_Num_index[idx+1]]
205 }
206 `
207
208 // Unsigned integers spanning zero.
209 const unum_in = `type Unum uint
210 const (
211 m_2 Unum = iota + 253
212 m_1
213 )
214
215 const (
216 m0 Unum = iota
217 m1
218 m2
219 )
220 `
221
222 const unum_out = `func _() {
223 // An "invalid array index" compiler error signifies that the constant values have changed.
224 // Re-run the stringer command to generate them again.
225 var x [1]struct{}
226 _ = x[m_2-253]
227 _ = x[m_1-254]
228 _ = x[m0-0]
229 _ = x[m1-1]
230 _ = x[m2-2]
231 }
232
233 const (
234 _Unum_name_0 = "m0m1m2"
235 _Unum_name_1 = "m_2m_1"
236 )
237
238 var (
239 _Unum_index_0 = [...]uint8{0, 2, 4, 6}
240 _Unum_index_1 = [...]uint8{0, 3, 6}
241 )
242
243 func (i Unum) String() string {
244 switch {
245 case i <= 2:
246 return _Unum_name_0[_Unum_index_0[i]:_Unum_index_0[i+1]]
247 case 253 <= i && i <= 254:
248 i -= 253
249 return _Unum_name_1[_Unum_index_1[i]:_Unum_index_1[i+1]]
250 default:
251 return "Unum(" + strconv.FormatInt(int64(i), 10) + ")"
252 }
253 }
254 `
255
256 // Unsigned positive integers.
257 const unumpos_in = `type Unumpos uint
258 const (
259 m253 Unumpos = iota + 253
260 m254
261 )
262
263 const (
264 m1 Unumpos = iota + 1
265 m2
266 m3
267 )
268 `
269
270 const unumpos_out = `func _() {
271 // An "invalid array index" compiler error signifies that the constant values have changed.
272 // Re-run the stringer command to generate them again.
273 var x [1]struct{}
274 _ = x[m253-253]
275 _ = x[m254-254]
276 _ = x[m1-1]
277 _ = x[m2-2]
278 _ = x[m3-3]
279 }
280
281 const (
282 _Unumpos_name_0 = "m1m2m3"
283 _Unumpos_name_1 = "m253m254"
284 )
285
286 var (
287 _Unumpos_index_0 = [...]uint8{0, 2, 4, 6}
288 _Unumpos_index_1 = [...]uint8{0, 4, 8}
289 )
290
291 func (i Unumpos) String() string {
292 switch {
293 case 1 <= i && i <= 3:
294 i -= 1
295 return _Unumpos_name_0[_Unumpos_index_0[i]:_Unumpos_index_0[i+1]]
296 case 253 <= i && i <= 254:
297 i -= 253
298 return _Unumpos_name_1[_Unumpos_index_1[i]:_Unumpos_index_1[i+1]]
299 default:
300 return "Unumpos(" + strconv.FormatInt(int64(i), 10) + ")"
301 }
302 }
303 `
304
305 // Enough gaps to trigger a map implementation of the method.
306 // Also includes a duplicate to test that it doesn't cause problems
307 const prime_in = `type Prime int
308 const (
309 p2 Prime = 2
310 p3 Prime = 3
311 p5 Prime = 5
312 p7 Prime = 7
313 p77 Prime = 7 // Duplicate; note that p77 doesn't appear below.
314 p11 Prime = 11
315 p13 Prime = 13
316 p17 Prime = 17
317 p19 Prime = 19
318 p23 Prime = 23
319 p29 Prime = 29
320 p37 Prime = 31
321 p41 Prime = 41
322 p43 Prime = 43
323 )
324 `
325
326 const prime_out = `func _() {
327 // An "invalid array index" compiler error signifies that the constant values have changed.
328 // Re-run the stringer command to generate them again.
329 var x [1]struct{}
330 _ = x[p2-2]
331 _ = x[p3-3]
332 _ = x[p5-5]
333 _ = x[p7-7]
334 _ = x[p77-7]
335 _ = x[p11-11]
336 _ = x[p13-13]
337 _ = x[p17-17]
338 _ = x[p19-19]
339 _ = x[p23-23]
340 _ = x[p29-29]
341 _ = x[p37-31]
342 _ = x[p41-41]
343 _ = x[p43-43]
344 }
345
346 const _Prime_name = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
347
348 var _Prime_map = map[Prime]string{
349 2: _Prime_name[0:2],
350 3: _Prime_name[2:4],
351 5: _Prime_name[4:6],
352 7: _Prime_name[6:8],
353 11: _Prime_name[8:11],
354 13: _Prime_name[11:14],
355 17: _Prime_name[14:17],
356 19: _Prime_name[17:20],
357 23: _Prime_name[20:23],
358 29: _Prime_name[23:26],
359 31: _Prime_name[26:29],
360 41: _Prime_name[29:32],
361 43: _Prime_name[32:35],
362 }
363
364 func (i Prime) String() string {
365 if str, ok := _Prime_map[i]; ok {
366 return str
367 }
368 return "Prime(" + strconv.FormatInt(int64(i), 10) + ")"
369 }
370 `
371
372 const prefix_in = `type Type int
373 const (
374 TypeInt Type = iota
375 TypeString
376 TypeFloat
377 TypeRune
378 TypeByte
379 TypeStruct
380 TypeSlice
381 )
382 `
383
384 const prefix_out = `func _() {
385 // An "invalid array index" compiler error signifies that the constant values have changed.
386 // Re-run the stringer command to generate them again.
387 var x [1]struct{}
388 _ = x[TypeInt-0]
389 _ = x[TypeString-1]
390 _ = x[TypeFloat-2]
391 _ = x[TypeRune-3]
392 _ = x[TypeByte-4]
393 _ = x[TypeStruct-5]
394 _ = x[TypeSlice-6]
395 }
396
397 const _Type_name = "IntStringFloatRuneByteStructSlice"
398
399 var _Type_index = [...]uint8{0, 3, 9, 14, 18, 22, 28, 33}
400
401 func (i Type) String() string {
402 idx := int(i) - 0
403 if i < 0 || idx >= len(_Type_index)-1 {
404 return "Type(" + strconv.FormatInt(int64(i), 10) + ")"
405 }
406 return _Type_name[_Type_index[idx]:_Type_index[idx+1]]
407 }
408 `
409
410 const tokens_in = `type Token int
411 const (
412 And Token = iota // &
413 Or // |
414 Add // +
415 Sub // -
416 Ident
417 Period // .
418
419 // not to be used
420 SingleBefore
421 // not to be used
422 BeforeAndInline // inline
423 InlineGeneral /* inline general */
424 )
425 `
426
427 const tokens_out = `func _() {
428 // An "invalid array index" compiler error signifies that the constant values have changed.
429 // Re-run the stringer command to generate them again.
430 var x [1]struct{}
431 _ = x[And-0]
432 _ = x[Or-1]
433 _ = x[Add-2]
434 _ = x[Sub-3]
435 _ = x[Ident-4]
436 _ = x[Period-5]
437 _ = x[SingleBefore-6]
438 _ = x[BeforeAndInline-7]
439 _ = x[InlineGeneral-8]
440 }
441
442 const _Token_name = "&|+-Ident.SingleBeforeinlineinline general"
443
444 var _Token_index = [...]uint8{0, 1, 2, 3, 4, 9, 10, 22, 28, 42}
445
446 func (i Token) String() string {
447 idx := int(i) - 0
448 if i < 0 || idx >= len(_Token_index)-1 {
449 return "Token(" + strconv.FormatInt(int64(i), 10) + ")"
450 }
451 return _Token_name[_Token_index[idx]:_Token_index[idx+1]]
452 }
453 `
454
455 const overflow8_in = `type Overflow8 int8
456 const (
457 O_128 Overflow8 = -128
458 O_127 Overflow8 = -127
459 O_126 Overflow8 = -126
460 O_125 Overflow8 = -125
461 O_124 Overflow8 = -124
462 O_123 Overflow8 = -123
463 O_122 Overflow8 = -122
464 O_121 Overflow8 = -121
465 O_120 Overflow8 = -120
466 O_119 Overflow8 = -119
467 O_118 Overflow8 = -118
468 O_117 Overflow8 = -117
469 O_116 Overflow8 = -116
470 O_115 Overflow8 = -115
471 O_114 Overflow8 = -114
472 O_113 Overflow8 = -113
473 O_112 Overflow8 = -112
474 O_111 Overflow8 = -111
475 O_110 Overflow8 = -110
476 O_109 Overflow8 = -109
477 O_108 Overflow8 = -108
478 O_107 Overflow8 = -107
479 O_106 Overflow8 = -106
480 O_105 Overflow8 = -105
481 O_104 Overflow8 = -104
482 O_103 Overflow8 = -103
483 O_102 Overflow8 = -102
484 O_101 Overflow8 = -101
485 O_100 Overflow8 = -100
486 O_99 Overflow8 = -99
487 O_98 Overflow8 = -98
488 O_97 Overflow8 = -97
489 O_96 Overflow8 = -96
490 O_95 Overflow8 = -95
491 O_94 Overflow8 = -94
492 O_93 Overflow8 = -93
493 O_92 Overflow8 = -92
494 O_91 Overflow8 = -91
495 O_90 Overflow8 = -90
496 O_89 Overflow8 = -89
497 O_88 Overflow8 = -88
498 O_87 Overflow8 = -87
499 O_86 Overflow8 = -86
500 O_85 Overflow8 = -85
501 O_84 Overflow8 = -84
502 O_83 Overflow8 = -83
503 O_82 Overflow8 = -82
504 O_81 Overflow8 = -81
505 O_80 Overflow8 = -80
506 O_79 Overflow8 = -79
507 O_78 Overflow8 = -78
508 O_77 Overflow8 = -77
509 O_76 Overflow8 = -76
510 O_75 Overflow8 = -75
511 O_74 Overflow8 = -74
512 O_73 Overflow8 = -73
513 O_72 Overflow8 = -72
514 O_71 Overflow8 = -71
515 O_70 Overflow8 = -70
516 O_69 Overflow8 = -69
517 O_68 Overflow8 = -68
518 O_67 Overflow8 = -67
519 O_66 Overflow8 = -66
520 O_65 Overflow8 = -65
521 O_64 Overflow8 = -64
522 O_63 Overflow8 = -63
523 O_62 Overflow8 = -62
524 O_61 Overflow8 = -61
525 O_60 Overflow8 = -60
526 O_59 Overflow8 = -59
527 O_58 Overflow8 = -58
528 O_57 Overflow8 = -57
529 O_56 Overflow8 = -56
530 O_55 Overflow8 = -55
531 O_54 Overflow8 = -54
532 O_53 Overflow8 = -53
533 O_52 Overflow8 = -52
534 O_51 Overflow8 = -51
535 O_50 Overflow8 = -50
536 O_49 Overflow8 = -49
537 O_48 Overflow8 = -48
538 O_47 Overflow8 = -47
539 O_46 Overflow8 = -46
540 O_45 Overflow8 = -45
541 O_44 Overflow8 = -44
542 O_43 Overflow8 = -43
543 O_42 Overflow8 = -42
544 O_41 Overflow8 = -41
545 O_40 Overflow8 = -40
546 O_39 Overflow8 = -39
547 O_38 Overflow8 = -38
548 O_37 Overflow8 = -37
549 O_36 Overflow8 = -36
550 O_35 Overflow8 = -35
551 O_34 Overflow8 = -34
552 O_33 Overflow8 = -33
553 O_32 Overflow8 = -32
554 O_31 Overflow8 = -31
555 O_30 Overflow8 = -30
556 O_29 Overflow8 = -29
557 O_28 Overflow8 = -28
558 O_27 Overflow8 = -27
559 O_26 Overflow8 = -26
560 O_25 Overflow8 = -25
561 O_24 Overflow8 = -24
562 O_23 Overflow8 = -23
563 O_22 Overflow8 = -22
564 O_21 Overflow8 = -21
565 O_20 Overflow8 = -20
566 O_19 Overflow8 = -19
567 O_18 Overflow8 = -18
568 O_17 Overflow8 = -17
569 O_16 Overflow8 = -16
570 O_15 Overflow8 = -15
571 O_14 Overflow8 = -14
572 O_13 Overflow8 = -13
573 O_12 Overflow8 = -12
574 O_11 Overflow8 = -11
575 O_10 Overflow8 = -10
576 O_9 Overflow8 = -9
577 O_8 Overflow8 = -8
578 O_7 Overflow8 = -7
579 O_6 Overflow8 = -6
580 O_5 Overflow8 = -5
581 O_4 Overflow8 = -4
582 O_3 Overflow8 = -3
583 O_2 Overflow8 = -2
584 O_1 Overflow8 = -1
585 O0 Overflow8 = 0
586 O1 Overflow8 = 1
587 O2 Overflow8 = 2
588 O3 Overflow8 = 3
589 O4 Overflow8 = 4
590 O5 Overflow8 = 5
591 O6 Overflow8 = 6
592 O7 Overflow8 = 7
593 O8 Overflow8 = 8
594 O9 Overflow8 = 9
595 O10 Overflow8 = 10
596 O11 Overflow8 = 11
597 O12 Overflow8 = 12
598 O13 Overflow8 = 13
599 O14 Overflow8 = 14
600 O15 Overflow8 = 15
601 O16 Overflow8 = 16
602 O17 Overflow8 = 17
603 O18 Overflow8 = 18
604 O19 Overflow8 = 19
605 O20 Overflow8 = 20
606 O21 Overflow8 = 21
607 O22 Overflow8 = 22
608 O23 Overflow8 = 23
609 O24 Overflow8 = 24
610 O25 Overflow8 = 25
611 O26 Overflow8 = 26
612 O27 Overflow8 = 27
613 O28 Overflow8 = 28
614 O29 Overflow8 = 29
615 O30 Overflow8 = 30
616 O31 Overflow8 = 31
617 O32 Overflow8 = 32
618 O33 Overflow8 = 33
619 O34 Overflow8 = 34
620 O35 Overflow8 = 35
621 O36 Overflow8 = 36
622 O37 Overflow8 = 37
623 O38 Overflow8 = 38
624 O39 Overflow8 = 39
625 O40 Overflow8 = 40
626 O41 Overflow8 = 41
627 O42 Overflow8 = 42
628 O43 Overflow8 = 43
629 O44 Overflow8 = 44
630 O45 Overflow8 = 45
631 O46 Overflow8 = 46
632 O47 Overflow8 = 47
633 O48 Overflow8 = 48
634 O49 Overflow8 = 49
635 O50 Overflow8 = 50
636 O51 Overflow8 = 51
637 O52 Overflow8 = 52
638 O53 Overflow8 = 53
639 O54 Overflow8 = 54
640 O55 Overflow8 = 55
641 O56 Overflow8 = 56
642 O57 Overflow8 = 57
643 O58 Overflow8 = 58
644 O59 Overflow8 = 59
645 O60 Overflow8 = 60
646 O61 Overflow8 = 61
647 O62 Overflow8 = 62
648 O63 Overflow8 = 63
649 O64 Overflow8 = 64
650 O65 Overflow8 = 65
651 O66 Overflow8 = 66
652 O67 Overflow8 = 67
653 O68 Overflow8 = 68
654 O69 Overflow8 = 69
655 O70 Overflow8 = 70
656 O71 Overflow8 = 71
657 O72 Overflow8 = 72
658 O73 Overflow8 = 73
659 O74 Overflow8 = 74
660 O75 Overflow8 = 75
661 O76 Overflow8 = 76
662 O77 Overflow8 = 77
663 O78 Overflow8 = 78
664 O79 Overflow8 = 79
665 O80 Overflow8 = 80
666 O81 Overflow8 = 81
667 O82 Overflow8 = 82
668 O83 Overflow8 = 83
669 O84 Overflow8 = 84
670 O85 Overflow8 = 85
671 O86 Overflow8 = 86
672 O87 Overflow8 = 87
673 O88 Overflow8 = 88
674 O89 Overflow8 = 89
675 O90 Overflow8 = 90
676 O91 Overflow8 = 91
677 O92 Overflow8 = 92
678 O93 Overflow8 = 93
679 O94 Overflow8 = 94
680 O95 Overflow8 = 95
681 O96 Overflow8 = 96
682 O97 Overflow8 = 97
683 O98 Overflow8 = 98
684 O99 Overflow8 = 99
685 O100 Overflow8 = 100
686 O101 Overflow8 = 101
687 O102 Overflow8 = 102
688 O103 Overflow8 = 103
689 O104 Overflow8 = 104
690 O105 Overflow8 = 105
691 O106 Overflow8 = 106
692 O107 Overflow8 = 107
693 O108 Overflow8 = 108
694 O109 Overflow8 = 109
695 O110 Overflow8 = 110
696 O111 Overflow8 = 111
697 O112 Overflow8 = 112
698 O113 Overflow8 = 113
699 O114 Overflow8 = 114
700 O115 Overflow8 = 115
701 O116 Overflow8 = 116
702 O117 Overflow8 = 117
703 O118 Overflow8 = 118
704 O119 Overflow8 = 119
705 O120 Overflow8 = 120
706 O121 Overflow8 = 121
707 O122 Overflow8 = 122
708 O123 Overflow8 = 123
709 O124 Overflow8 = 124
710 O125 Overflow8 = 125
711 O126 Overflow8 = 126
712 O127 Overflow8 = 127
713 )
714 `
715
716 const overflow8_out = `func _() {
717 // An "invalid array index" compiler error signifies that the constant values have changed.
718 // Re-run the stringer command to generate them again.
719 var x [1]struct{}
720 _ = x[O_128 - -128]
721 _ = x[O_127 - -127]
722 _ = x[O_126 - -126]
723 _ = x[O_125 - -125]
724 _ = x[O_124 - -124]
725 _ = x[O_123 - -123]
726 _ = x[O_122 - -122]
727 _ = x[O_121 - -121]
728 _ = x[O_120 - -120]
729 _ = x[O_119 - -119]
730 _ = x[O_118 - -118]
731 _ = x[O_117 - -117]
732 _ = x[O_116 - -116]
733 _ = x[O_115 - -115]
734 _ = x[O_114 - -114]
735 _ = x[O_113 - -113]
736 _ = x[O_112 - -112]
737 _ = x[O_111 - -111]
738 _ = x[O_110 - -110]
739 _ = x[O_109 - -109]
740 _ = x[O_108 - -108]
741 _ = x[O_107 - -107]
742 _ = x[O_106 - -106]
743 _ = x[O_105 - -105]
744 _ = x[O_104 - -104]
745 _ = x[O_103 - -103]
746 _ = x[O_102 - -102]
747 _ = x[O_101 - -101]
748 _ = x[O_100 - -100]
749 _ = x[O_99 - -99]
750 _ = x[O_98 - -98]
751 _ = x[O_97 - -97]
752 _ = x[O_96 - -96]
753 _ = x[O_95 - -95]
754 _ = x[O_94 - -94]
755 _ = x[O_93 - -93]
756 _ = x[O_92 - -92]
757 _ = x[O_91 - -91]
758 _ = x[O_90 - -90]
759 _ = x[O_89 - -89]
760 _ = x[O_88 - -88]
761 _ = x[O_87 - -87]
762 _ = x[O_86 - -86]
763 _ = x[O_85 - -85]
764 _ = x[O_84 - -84]
765 _ = x[O_83 - -83]
766 _ = x[O_82 - -82]
767 _ = x[O_81 - -81]
768 _ = x[O_80 - -80]
769 _ = x[O_79 - -79]
770 _ = x[O_78 - -78]
771 _ = x[O_77 - -77]
772 _ = x[O_76 - -76]
773 _ = x[O_75 - -75]
774 _ = x[O_74 - -74]
775 _ = x[O_73 - -73]
776 _ = x[O_72 - -72]
777 _ = x[O_71 - -71]
778 _ = x[O_70 - -70]
779 _ = x[O_69 - -69]
780 _ = x[O_68 - -68]
781 _ = x[O_67 - -67]
782 _ = x[O_66 - -66]
783 _ = x[O_65 - -65]
784 _ = x[O_64 - -64]
785 _ = x[O_63 - -63]
786 _ = x[O_62 - -62]
787 _ = x[O_61 - -61]
788 _ = x[O_60 - -60]
789 _ = x[O_59 - -59]
790 _ = x[O_58 - -58]
791 _ = x[O_57 - -57]
792 _ = x[O_56 - -56]
793 _ = x[O_55 - -55]
794 _ = x[O_54 - -54]
795 _ = x[O_53 - -53]
796 _ = x[O_52 - -52]
797 _ = x[O_51 - -51]
798 _ = x[O_50 - -50]
799 _ = x[O_49 - -49]
800 _ = x[O_48 - -48]
801 _ = x[O_47 - -47]
802 _ = x[O_46 - -46]
803 _ = x[O_45 - -45]
804 _ = x[O_44 - -44]
805 _ = x[O_43 - -43]
806 _ = x[O_42 - -42]
807 _ = x[O_41 - -41]
808 _ = x[O_40 - -40]
809 _ = x[O_39 - -39]
810 _ = x[O_38 - -38]
811 _ = x[O_37 - -37]
812 _ = x[O_36 - -36]
813 _ = x[O_35 - -35]
814 _ = x[O_34 - -34]
815 _ = x[O_33 - -33]
816 _ = x[O_32 - -32]
817 _ = x[O_31 - -31]
818 _ = x[O_30 - -30]
819 _ = x[O_29 - -29]
820 _ = x[O_28 - -28]
821 _ = x[O_27 - -27]
822 _ = x[O_26 - -26]
823 _ = x[O_25 - -25]
824 _ = x[O_24 - -24]
825 _ = x[O_23 - -23]
826 _ = x[O_22 - -22]
827 _ = x[O_21 - -21]
828 _ = x[O_20 - -20]
829 _ = x[O_19 - -19]
830 _ = x[O_18 - -18]
831 _ = x[O_17 - -17]
832 _ = x[O_16 - -16]
833 _ = x[O_15 - -15]
834 _ = x[O_14 - -14]
835 _ = x[O_13 - -13]
836 _ = x[O_12 - -12]
837 _ = x[O_11 - -11]
838 _ = x[O_10 - -10]
839 _ = x[O_9 - -9]
840 _ = x[O_8 - -8]
841 _ = x[O_7 - -7]
842 _ = x[O_6 - -6]
843 _ = x[O_5 - -5]
844 _ = x[O_4 - -4]
845 _ = x[O_3 - -3]
846 _ = x[O_2 - -2]
847 _ = x[O_1 - -1]
848 _ = x[O0-0]
849 _ = x[O1-1]
850 _ = x[O2-2]
851 _ = x[O3-3]
852 _ = x[O4-4]
853 _ = x[O5-5]
854 _ = x[O6-6]
855 _ = x[O7-7]
856 _ = x[O8-8]
857 _ = x[O9-9]
858 _ = x[O10-10]
859 _ = x[O11-11]
860 _ = x[O12-12]
861 _ = x[O13-13]
862 _ = x[O14-14]
863 _ = x[O15-15]
864 _ = x[O16-16]
865 _ = x[O17-17]
866 _ = x[O18-18]
867 _ = x[O19-19]
868 _ = x[O20-20]
869 _ = x[O21-21]
870 _ = x[O22-22]
871 _ = x[O23-23]
872 _ = x[O24-24]
873 _ = x[O25-25]
874 _ = x[O26-26]
875 _ = x[O27-27]
876 _ = x[O28-28]
877 _ = x[O29-29]
878 _ = x[O30-30]
879 _ = x[O31-31]
880 _ = x[O32-32]
881 _ = x[O33-33]
882 _ = x[O34-34]
883 _ = x[O35-35]
884 _ = x[O36-36]
885 _ = x[O37-37]
886 _ = x[O38-38]
887 _ = x[O39-39]
888 _ = x[O40-40]
889 _ = x[O41-41]
890 _ = x[O42-42]
891 _ = x[O43-43]
892 _ = x[O44-44]
893 _ = x[O45-45]
894 _ = x[O46-46]
895 _ = x[O47-47]
896 _ = x[O48-48]
897 _ = x[O49-49]
898 _ = x[O50-50]
899 _ = x[O51-51]
900 _ = x[O52-52]
901 _ = x[O53-53]
902 _ = x[O54-54]
903 _ = x[O55-55]
904 _ = x[O56-56]
905 _ = x[O57-57]
906 _ = x[O58-58]
907 _ = x[O59-59]
908 _ = x[O60-60]
909 _ = x[O61-61]
910 _ = x[O62-62]
911 _ = x[O63-63]
912 _ = x[O64-64]
913 _ = x[O65-65]
914 _ = x[O66-66]
915 _ = x[O67-67]
916 _ = x[O68-68]
917 _ = x[O69-69]
918 _ = x[O70-70]
919 _ = x[O71-71]
920 _ = x[O72-72]
921 _ = x[O73-73]
922 _ = x[O74-74]
923 _ = x[O75-75]
924 _ = x[O76-76]
925 _ = x[O77-77]
926 _ = x[O78-78]
927 _ = x[O79-79]
928 _ = x[O80-80]
929 _ = x[O81-81]
930 _ = x[O82-82]
931 _ = x[O83-83]
932 _ = x[O84-84]
933 _ = x[O85-85]
934 _ = x[O86-86]
935 _ = x[O87-87]
936 _ = x[O88-88]
937 _ = x[O89-89]
938 _ = x[O90-90]
939 _ = x[O91-91]
940 _ = x[O92-92]
941 _ = x[O93-93]
942 _ = x[O94-94]
943 _ = x[O95-95]
944 _ = x[O96-96]
945 _ = x[O97-97]
946 _ = x[O98-98]
947 _ = x[O99-99]
948 _ = x[O100-100]
949 _ = x[O101-101]
950 _ = x[O102-102]
951 _ = x[O103-103]
952 _ = x[O104-104]
953 _ = x[O105-105]
954 _ = x[O106-106]
955 _ = x[O107-107]
956 _ = x[O108-108]
957 _ = x[O109-109]
958 _ = x[O110-110]
959 _ = x[O111-111]
960 _ = x[O112-112]
961 _ = x[O113-113]
962 _ = x[O114-114]
963 _ = x[O115-115]
964 _ = x[O116-116]
965 _ = x[O117-117]
966 _ = x[O118-118]
967 _ = x[O119-119]
968 _ = x[O120-120]
969 _ = x[O121-121]
970 _ = x[O122-122]
971 _ = x[O123-123]
972 _ = x[O124-124]
973 _ = x[O125-125]
974 _ = x[O126-126]
975 _ = x[O127-127]
976 }
977
978 const _Overflow8_name = "O_128O_127O_126O_125O_124O_123O_122O_121O_120O_119O_118O_117O_116O_115O_114O_113O_112O_111O_110O_109O_108O_107O_106O_105O_104O_103O_102O_101O_100O_99O_98O_97O_96O_95O_94O_93O_92O_91O_90O_89O_88O_87O_86O_85O_84O_83O_82O_81O_80O_79O_78O_77O_76O_75O_74O_73O_72O_71O_70O_69O_68O_67O_66O_65O_64O_63O_62O_61O_60O_59O_58O_57O_56O_55O_54O_53O_52O_51O_50O_49O_48O_47O_46O_45O_44O_43O_42O_41O_40O_39O_38O_37O_36O_35O_34O_33O_32O_31O_30O_29O_28O_27O_26O_25O_24O_23O_22O_21O_20O_19O_18O_17O_16O_15O_14O_13O_12O_11O_10O_9O_8O_7O_6O_5O_4O_3O_2O_1O0O1O2O3O4O5O6O7O8O9O10O11O12O13O14O15O16O17O18O19O20O21O22O23O24O25O26O27O28O29O30O31O32O33O34O35O36O37O38O39O40O41O42O43O44O45O46O47O48O49O50O51O52O53O54O55O56O57O58O59O60O61O62O63O64O65O66O67O68O69O70O71O72O73O74O75O76O77O78O79O80O81O82O83O84O85O86O87O88O89O90O91O92O93O94O95O96O97O98O99O100O101O102O103O104O105O106O107O108O109O110O111O112O113O114O115O116O117O118O119O120O121O122O123O124O125O126O127"
979
980 var _Overflow8_index = [...]uint16{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233, 237, 241, 245, 249, 253, 257, 261, 265, 269, 273, 277, 281, 285, 289, 293, 297, 301, 305, 309, 313, 317, 321, 325, 329, 333, 337, 341, 345, 349, 353, 357, 361, 365, 369, 373, 377, 381, 385, 389, 393, 397, 401, 405, 409, 413, 417, 421, 425, 429, 433, 437, 441, 445, 449, 453, 457, 461, 465, 469, 473, 477, 481, 485, 489, 493, 497, 501, 505, 508, 511, 514, 517, 520, 523, 526, 529, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 555, 558, 561, 564, 567, 570, 573, 576, 579, 582, 585, 588, 591, 594, 597, 600, 603, 606, 609, 612, 615, 618, 621, 624, 627, 630, 633, 636, 639, 642, 645, 648, 651, 654, 657, 660, 663, 666, 669, 672, 675, 678, 681, 684, 687, 690, 693, 696, 699, 702, 705, 708, 711, 714, 717, 720, 723, 726, 729, 732, 735, 738, 741, 744, 747, 750, 753, 756, 759, 762, 765, 768, 771, 774, 777, 780, 783, 786, 789, 792, 795, 798, 801, 804, 807, 810, 813, 816, 819, 822, 826, 830, 834, 838, 842, 846, 850, 854, 858, 862, 866, 870, 874, 878, 882, 886, 890, 894, 898, 902, 906, 910, 914, 918, 922, 926, 930, 934}
981
982 func (i Overflow8) String() string {
983 idx := int(i) - -128
984 if i < -128 || idx >= len(_Overflow8_index)-1 {
985 return "Overflow8(" + strconv.FormatInt(int64(i), 10) + ")"
986 }
987 return _Overflow8_name[_Overflow8_index[idx]:_Overflow8_index[idx+1]]
988 }
989 `
990
991 func TestGolden(t *testing.T) {
992 testenv.NeedsTool(t, "go")
993
994 dir := t.TempDir()
995 for _, test := range golden {
996 t.Run(test.name, func(t *testing.T) {
997 input := "package test\n" + test.input
998 file := test.name + ".go"
999 absFile := filepath.Join(dir, file)
1000 err := os.WriteFile(absFile, []byte(input), 0644)
1001 if err != nil {
1002 t.Fatal(err)
1003 }
1004
1005 pkgs := loadPackages([]string{absFile}, nil, test.trimPrefix, test.lineComment, t.Logf)
1006 if len(pkgs) != 1 {
1007 t.Fatalf("got %d parsed packages but expected 1", len(pkgs))
1008 }
1009 // Extract the name and type of the constant from the first line.
1010 tokens := strings.SplitN(test.input, " ", 3)
1011 if len(tokens) != 3 {
1012 t.Fatalf("%s: need type declaration on first line", test.name)
1013 }
1014
1015 g := Generator{
1016 pkg: pkgs[0],
1017 logf: t.Logf,
1018 }
1019 g.generate(tokens[1], findValues(tokens[1], pkgs[0]))
1020 got := string(g.format())
1021 if got != test.output {
1022 t.Errorf("%s: got(%d)\n====\n%q====\nexpected(%d)\n====\n%q", test.name, len(got), got, len(test.output), test.output)
1023 }
1024 })
1025 }
1026 }