-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
valast_test.go
1092 lines (1064 loc) · 27.7 KB
/
valast_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package valast
import (
"reflect"
"testing"
"time"
"unsafe"
"github.com/hexops/autogold"
"github.com/hexops/valast/internal/test"
)
type foo struct {
bar string
}
type baz struct {
Bam complex64
zeta foo
Beta interface{}
}
type ExportedBaz struct {
Bam complex64
zeta foo
Beta interface{}
}
func TestString(t *testing.T) {
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "bool",
input: true,
},
{
name: "bool_unqualify",
input: false,
opt: &Options{Unqualify: true},
},
{
name: "int32",
input: int32(1234),
},
{
name: "int32_unqualify",
input: int32(1234),
opt: &Options{Unqualify: true},
},
{
name: "uintptr",
input: uintptr(1234),
},
{
name: "uintptr_unqualify",
input: uintptr(1234),
opt: &Options{Unqualify: true},
},
{
name: "float64",
input: float64(1.234),
},
{
name: "float64_unqualify",
input: float64(1.234),
opt: &Options{Unqualify: true},
},
{
name: "complex64",
input: complex64(1.234),
},
{
name: "complex64_unqualify",
input: complex64(1.234),
opt: &Options{Unqualify: true},
},
{
name: "string",
input: string("hello \t world"),
},
{
name: "string_unqualify",
input: string(`one
two
three`),
opt: &Options{Unqualify: true},
},
{
name: "struct_anonymous",
input: struct {
a, b int
V string
}{a: 1, b: 2, V: "efg"},
},
{
name: "struct_same_package",
input: baz{
Bam: 1.34,
zeta: foo{
bar: "hello",
},
},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "struct_external_package",
input: test.NewBaz(),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "array",
input: [2]*baz{
{Beta: "foo"},
{Beta: 123},
},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "slice",
input: []*baz{
{Beta: "foo"},
{Beta: 123},
{Beta: 3},
},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "nil",
input: nil,
},
{
name: "interface_anonymous_nil",
input: interface {
a() string
}(nil),
},
{
name: "interface_anonymous",
input: &struct {
v interface {
String() string
Baz() (err error)
}
}{v: test.NewBaz()},
},
{
name: "interface_builtin",
input: &struct {
v error
}{v: nil},
},
{
name: "interface",
input: &struct {
v test.Bazer
}{v: test.NewBaz()},
},
{
name: "unsafe_pointer",
input: unsafe.Pointer(uintptr(0xdeadbeef)),
},
{
name: "map",
input: map[string]int32{
"foo": 32,
"bar": 64,
},
},
{
name: "time_utc",
input: time.Date(2016, 1, 2, 15, 4, 5, 0, time.UTC),
},
{
name: "time_local",
input: time.Date(2016, 1, 2, 15, 4, 5, 0, time.Local),
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestRecursion tests how recursive and cyclic data types/values are handled.
func TestRecursion(t *testing.T) {
type foo struct {
name string
bar *foo
}
cyclic := &foo{name: "one"}
cyclic.bar = cyclic
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "basic",
input: &foo{
name: "one",
bar: &foo{
name: "two",
bar: &foo{
name: "three",
bar: &foo{
name: "four",
bar: &foo{
name: "five",
},
},
},
},
},
},
{
name: "struct_cyclic",
input: cyclic,
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestEdgeCases tests known edge-cases and past bugs that do not fit any of the broader test
// categories.
func TestEdgeCases(t *testing.T) {
var (
nilInterface test.Bazer
nilInterfacePointer = &nilInterface
nilInterfacePointerPointer = &nilInterfacePointer
bazer test.Bazer = test.NewBaz()
bazerPointer = &bazer
)
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "ptr_to_interface",
input: &struct {
v *test.Bazer
}{v: &bazer},
},
{
name: "ptr_to_ptr_to_interface",
input: &struct {
v **test.Bazer
}{v: &bazerPointer},
},
{
name: "ptr_to_nil_interface",
input: &struct {
v *test.Bazer
}{v: &nilInterface},
},
{
name: "ptr2_to_nil_interface",
input: &struct {
v **test.Bazer
}{v: &nilInterfacePointer},
},
{
name: "ptr3_to_nil_interface",
input: &struct {
v ***test.Bazer
}{v: &nilInterfacePointerPointer},
},
{
name: "nil_interface_pointer",
input: &struct {
v *test.Bazer
}{v: nil},
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestExportedOnly_input tests the behavior of Options.ExportedOnly when enabled with a direct unexported input.
func TestExportedOnly_input(t *testing.T) {
type (
unexportedBool bool
unexportedInt int
unexportedInt8 int8
unexportedInt16 int16
unexportedInt32 int32
unexportedInt64 int64
unexportedUint uint
unexportedUint8 uint8
unexportedUint16 uint16
unexportedUint32 uint32
unexportedUint64 uint64
unexportedUintptr uintptr
unexportedFloat32 float32
unexportedFloat64 float64
unexportedComplex64 complex64
unexportedComplex128 complex128
unexportedArray [1]float32
unexportedInterface error
unexportedMap map[string]string
unexportedPointer *int
unexportedSlice []int
unexportedString string
unexportedStruct struct{ A string }
unexportedUnsafePointer unsafe.Pointer
)
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "struct_same_package",
input: baz{
Bam: 1.34,
zeta: foo{
bar: "hello",
},
},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast", ExportedOnly: true},
},
{
name: "bool",
input: unexportedBool(true),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "int",
input: unexportedInt(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "int8",
input: unexportedInt8(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "int16",
input: unexportedInt16(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "int32",
input: unexportedInt32(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "int64",
input: unexportedInt64(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uint",
input: unexportedUint(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uint8",
input: unexportedUint8(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uint16",
input: unexportedUint16(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uint32",
input: unexportedUint32(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uint64",
input: unexportedUint64(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "uintptr",
input: unexportedUintptr(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "float32",
input: unexportedFloat32(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "float64",
input: unexportedFloat64(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "complex64",
input: unexportedComplex64(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "complex128",
input: unexportedComplex128(1),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "array",
input: unexportedArray{1.0},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "interface",
input: struct {
V unexportedInterface
}{V: nil},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "map",
input: unexportedMap{
"a": "b",
},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "map_unexported_key_type",
input: map[unexportedInt]string{},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "map_unexported_value_type",
input: map[string]unexportedInt{},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "map_unexported_key_omitted",
input: map[string]interface{}{
"a": unexportedInt(1),
},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "map_unexported_value_omitted",
input: map[interface{}]string{
unexportedInt(1): "a",
},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "pointer",
input: unexportedPointer(nil),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "slice",
input: unexportedSlice{1, 2, 3},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "string",
input: unexportedString("hello"),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "struct",
input: unexportedStruct{A: "b"},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "unsafe_pointer",
input: unexportedUnsafePointer(uintptr(0xdeadbeef)),
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestExportedOnly_nested tests the behavior of Options.ExportedOnly when enabled with an unexported
// value/type nested below an exported one.
func TestExportedOnly_nested(t *testing.T) {
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "external_struct_unexported_field_omitted",
input: test.NewBaz(),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast", ExportedOnly: true},
},
{
name: "struct_same_package_unexported_field_omitted",
input: ExportedBaz{
Bam: 1.34,
zeta: foo{
bar: "hello",
},
},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
{
name: "interface",
input: struct {
zeta foo
}{zeta: foo{bar: "baz"}},
opt: &Options{PackageName: "other", PackagePath: "github.com/other/other", ExportedOnly: true},
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestUnexportedInputs tests the behavior of Options.ExportedOnly when disabled.
func TestUnexportedInputs(t *testing.T) {
type (
unexportedBool bool
unexportedInt int
unexportedInt8 int8
unexportedInt16 int16
unexportedInt32 int32
unexportedInt64 int64
unexportedUint uint
unexportedUint8 uint8
unexportedUint16 uint16
unexportedUint32 uint32
unexportedUint64 uint64
unexportedUintptr uintptr
unexportedFloat32 float32
unexportedFloat64 float64
unexportedComplex64 complex64
unexportedComplex128 complex128
unexportedArray [1]float32
unexportedInterface error
unexportedMap map[string]string
unexportedPointer *int
unexportedSlice []int
unexportedString string
unexportedStruct struct{ A string }
unexportedUnsafePointer unsafe.Pointer
)
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "bool",
input: unexportedBool(true),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int",
input: unexportedInt(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int8",
input: unexportedInt8(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int16",
input: unexportedInt16(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int32",
input: unexportedInt32(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int64",
input: unexportedInt64(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint",
input: unexportedUint(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint8",
input: unexportedUint8(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint16",
input: unexportedUint16(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint32",
input: unexportedUint32(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint64",
input: unexportedUint64(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uintptr",
input: unexportedUintptr(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "float32",
input: unexportedFloat32(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "float64",
input: unexportedFloat64(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "complex64",
input: unexportedComplex64(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "complex128",
input: unexportedComplex128(1),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "array",
input: unexportedArray{1.0},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "interface",
input: struct {
V unexportedInterface
}{V: nil},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "map",
input: unexportedMap{
"a": "b",
},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "pointer",
input: unexportedPointer(nil),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "slice",
input: unexportedSlice{1, 2, 3},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "string",
input: unexportedString("hello"),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "struct",
input: unexportedStruct{A: "b"},
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "unsafe_pointer",
input: unexportedUnsafePointer(uintptr(0xdeadbeef)),
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
// TestPointers tests to ensure valast.Addr and & are used when appropriate.
func TestPointers(t *testing.T) {
var (
boolValue = true
boolValuePointer = &boolValue
intValue int = 1
intValuePointer = &intValue
intValuePointerPointer = &intValuePointer
int8Value int8 = 1
int16Value int16 = 1
int32Value int32 = 1
int64Value int64 = 1
uintValue uint = 1
uint8Value uint8 = 1
uint16Value uint16 = 1
uint32Value uint32 = 1
uint64Value uint64 = 1
uintptrValue uintptr = 1
float32Value float32 = 1
float64Value float64 = 1
complex64Value complex64 = 1
complex128Value complex128 = 1
arrayValue = [1]float32{1}
arrayValuePointer = &arrayValue
interfaceValue = test.Bazer(test.NewBaz())
interfaceValuePointer = &interfaceValue
mapValue = map[string]string{"hello": "world"}
mapValuePointer = &mapValue
pointerValue = &uintValue
pointerValuePointer = &pointerValue
sliceValue = []int{1, 2, 3}
sliceValuePointer = &sliceValue
stringValue = "hello world"
structValue = struct{ A string }{A: "hello world"}
structValuePointer = &structValue
unsafePointerValue = unsafe.Pointer(uintptr(0xdeadbeef))
unsafePointerValuePointer = &unsafePointerValue
timeUtcValue = time.Date(2016, 1, 2, 15, 4, 5, 0, time.UTC)
timeLocalValue = time.Date(2016, 1, 2, 15, 4, 5, 0, time.Local)
)
tests := []struct {
name string
input interface{}
opt *Options
}{
{
name: "bool",
input: &boolValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "bool2",
input: &boolValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int",
input: &intValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int2",
input: &intValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int3",
input: &intValuePointerPointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int8",
input: &int8Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int16",
input: &int16Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int32",
input: &int32Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "int64",
input: &int64Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint",
input: &uintValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint8",
input: &uint8Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint16",
input: &uint16Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint32",
input: &uint32Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uint64",
input: &uint64Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "uintptr",
input: &uintptrValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "float32",
input: &float32Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "float64",
input: &float64Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "complex64",
input: &complex64Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "complex128",
input: &complex128Value,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "array",
input: &arrayValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "array2",
input: &arrayValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "interface",
input: &interfaceValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "interface2",
input: &interfaceValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "map",
input: &mapValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "map2",
input: &mapValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "pointer",
input: &pointerValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "pointer2", // ***uint
input: &pointerValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "slice",
input: &sliceValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "slice2",
input: &sliceValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "string",
input: &stringValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "struct",
input: &structValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "struct2",
input: &structValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "unsafe_pointer",
input: &unsafePointerValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "unsafe_pointer2",
input: &unsafePointerValuePointer,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "time_utc",
input: &timeUtcValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
{
name: "time_local",
input: &timeLocalValue,
opt: &Options{PackageName: "valast", PackagePath: "github.com/hexops/valast"},
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := StringWithOptions(tst.input, tst.opt)
autogold.Equal(t, got)
})
}
}
func TestStringFormatting(t *testing.T) {
tests := []struct {
name string
input interface{}
}{
{
name: "short_single_line",
input: "hello world",
},
{
name: "long_single_line_180",
input: "hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world ",
},
{
name: "short_multi_line",
input: "hello\nworld",
},
{
name: "long_multi_line_180",
input: `hello world hello world hello world hello world hello world hello world hello world hello world
hello world hello world hello world hello world hello world hello world hello world`,
},
{
name: "long_multi_line_with_backticks",
input: "hello world hello world hello world hello world hello world hello world hello world hello world\n`hello world hello world hello world hello world hello world hello world hello world",
},
{
name: "short_quotes",
input: `"hello" "world"`,
},
{
name: "long_multi_line_with_quotes",
input: `"hello world"! "hello world" hello world hello world hello world hello world hello world hello world
hello world hello world hello world hello world "hello" world hello world hello world`,
},
}
for _, tst := range tests {
tst := tst
t.Run(tst.name, func(t *testing.T) {
got := String(tst.input)
autogold.Equal(t, got)
})
}
}
func TestAddrInterface(t *testing.T) {
var bazer test.Bazer = test.NewBaz()
got := AddrInterface(bazer, (*test.Bazer)(nil)).(*test.Bazer)
if *got != bazer {
t.Fatal("*got != v")
}
}
func TestAddrInterface_golden(t *testing.T) {
// Confirms the AddrInterface calls in testdata/TestEdgeCases/ptr_to_* are valid.
_ = AddrInterface(&test.Baz{
Bam: (1.34 + 0i),
}, (*test.Bazer)(nil)).(*test.Bazer)
_ = AddrInterface(nil, (*test.Bazer)(nil)).(*test.Bazer)