-
Notifications
You must be signed in to change notification settings - Fork 27
/
checker_test.go
3110 lines (3093 loc) · 63.3 KB
/
checker_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
// Licensed under the MIT license, see LICENSE file for details.
package quicktest_test
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
qt "github.com/frankban/quicktest"
)
// Fooer is an interface for testing.
type Fooer interface {
Foo()
}
var (
goTime = time.Date(2012, 3, 28, 0, 0, 0, 0, time.UTC)
chInt = func() chan int {
ch := make(chan int, 4)
ch <- 42
ch <- 47
return ch
}()
sameInts = cmpopts.SortSlices(func(x, y int) bool {
return x < y
})
cmpEqualsGot = struct {
Strings []interface{}
Ints []int
}{
Strings: []interface{}{"who", "dalek"},
Ints: []int{42, 47},
}
cmpEqualsWant = struct {
Strings []interface{}
Ints []int
}{
Strings: []interface{}{"who", "dalek"},
Ints: []int{42},
}
)
type InnerJSON struct {
First string
Second int `json:",omitempty" yaml:",omitempty"`
Third map[string]bool `json:",omitempty" yaml:",omitempty"`
}
type OuterJSON struct {
First float64
Second []*InnerJSON `json:"Last,omitempty" yaml:"last,omitempty"`
}
type boolean bool
var checkerTests = []struct {
about string
checker qt.Checker
got interface{}
args []interface{}
verbose bool
expectedCheckFailure string
expectedNegateFailure string
}{{
about: "Equals: same values",
checker: qt.Equals,
got: 42,
args: []interface{}{42},
expectedNegateFailure: `
error:
unexpected success
got:
int(42)
want:
<same as "got">
`,
}, {
about: "Equals: different values",
checker: qt.Equals,
got: "42",
args: []interface{}{"47"},
expectedCheckFailure: `
error:
values are not equal
got:
"42"
want:
"47"
`,
}, {
about: "Equals: different strings with quotes",
checker: qt.Equals,
got: `string "foo"`,
args: []interface{}{`string "bar"`},
expectedCheckFailure: tilde2bq(`
error:
values are not equal
got:
~string "foo"~
want:
~string "bar"~
`),
}, {
about: "Equals: same multiline strings",
checker: qt.Equals,
got: "a\nmultiline\nstring",
args: []interface{}{"a\nmultiline\nstring"},
expectedNegateFailure: `
error:
unexpected success
got:
"a\nmultiline\nstring"
want:
<same as "got">
`,
}, {
about: "Equals: different multi-line strings",
checker: qt.Equals,
got: "a\nlong\nmultiline\nstring",
args: []interface{}{"just\na\nlong\nmulti-line\nstring\n"},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-want +got):
%s
got:
"a\nlong\nmultiline\nstring"
want:
"just\na\nlong\nmulti-line\nstring\n"
`, diff([]string{"a\n", "long\n", "multiline\n", "string"}, []string{"just\n", "a\n", "long\n", "multi-line\n", "string\n", ""})),
}, {
about: "Equals: different single-line strings ending with newline",
checker: qt.Equals,
got: "foo\n",
args: []interface{}{"bar\n"},
expectedCheckFailure: `
error:
values are not equal
got:
"foo\n"
want:
"bar\n"
`,
}, {
about: "Equals: different strings starting with newline",
checker: qt.Equals,
got: "\nfoo",
args: []interface{}{"\nbar"},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-want +got):
%s
got:
"\nfoo"
want:
"\nbar"
`, diff([]string{"\n", "foo"}, []string{"\n", "bar"})),
}, {
about: "Equals: different types",
checker: qt.Equals,
got: 42,
args: []interface{}{"42"},
expectedCheckFailure: `
error:
values are not equal
got:
int(42)
want:
"42"
`,
}, {
about: "Equals: nil and nil",
checker: qt.Equals,
got: nil,
args: []interface{}{nil},
expectedNegateFailure: `
error:
unexpected success
got:
nil
want:
<same as "got">
`,
}, {
about: "Equals: error is not nil",
checker: qt.Equals,
got: errBadWolf,
args: []interface{}{nil},
expectedCheckFailure: `
error:
got non-nil error
got:
bad wolf
file:line
want:
nil
`,
}, {
about: "Equals: error is not nil: not formatted",
checker: qt.Equals,
got: &errTest{
msg: "bad wolf",
},
args: []interface{}{nil},
expectedCheckFailure: `
error:
got non-nil error
got:
e"bad wolf"
want:
nil
`,
}, {
about: "Equals: error does not guard against nil",
checker: qt.Equals,
got: (*errTest)(nil),
args: []interface{}{nil},
expectedCheckFailure: `
error:
got non-nil error
got:
e<nil>
want:
nil
`,
}, {
about: "Equals: error is not nil: not formatted and with quotes",
checker: qt.Equals,
got: &errTest{
msg: `failure: "bad wolf"`,
},
args: []interface{}{nil},
expectedCheckFailure: tilde2bq(`
error:
got non-nil error
got:
e~failure: "bad wolf"~
want:
nil
`),
}, {
about: "Equals: different errors with same message",
checker: qt.Equals,
got: &errTest{
msg: "bad wolf",
},
args: []interface{}{errors.New("bad wolf")},
expectedCheckFailure: `
error:
values are not equal
got type:
*quicktest_test.errTest
want type:
*errors.errorString
got:
e"bad wolf"
want:
<same as "got" but different pointer value>
`,
}, {
about: "Equals: different pointer errors with the same message",
checker: qt.Equals,
got: &errTest{
msg: "bad wolf",
},
args: []interface{}{&errTest{
msg: "bad wolf",
}},
expectedCheckFailure: `
error:
values are not equal
got:
e"bad wolf"
want:
<same as "got" but different pointer value>
`,
}, {
about: "Equals: different pointers with the same formatted output",
checker: qt.Equals,
got: new(int),
args: []interface{}{new(int)},
expectedCheckFailure: `
error:
values are not equal
got:
&int(0)
want:
<same as "got" but different pointer value>
`,
}, {
about: "Equals: nil struct",
checker: qt.Equals,
got: (*struct{})(nil),
args: []interface{}{nil},
expectedCheckFailure: `
error:
values are not equal
got:
(*struct {})(nil)
want:
nil
`,
}, {
about: "Equals: different booleans",
checker: qt.Equals,
got: true,
args: []interface{}{false},
expectedCheckFailure: `
error:
values are not equal
got:
bool(true)
want:
bool(false)
`,
}, {
about: "Equals: uncomparable types",
checker: qt.Equals,
got: struct {
Ints []int
}{
Ints: []int{42, 47},
},
args: []interface{}{struct {
Ints []int
}{
Ints: []int{42, 47},
}},
expectedCheckFailure: `
error:
runtime error: comparing uncomparable type struct { Ints []int }
got:
struct { Ints []int }{
Ints: {42, 47},
}
want:
<same as "got">
`,
}, {
about: "Equals: not enough arguments",
checker: qt.Equals,
expectedCheckFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
expectedNegateFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
}, {
about: "Equals: too many arguments",
checker: qt.Equals,
args: []interface{}{nil, 47},
expectedCheckFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
nil,
int(47),
}
want args:
want
`,
expectedNegateFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
nil,
int(47),
}
want args:
want
`,
}, {
about: "CmpEquals: same values",
checker: qt.CmpEquals(),
got: cmpEqualsGot,
args: []interface{}{cmpEqualsGot},
expectedNegateFailure: `
error:
unexpected success
got:
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
}
want:
<same as "got">
`,
}, {
about: "CmpEquals: different values",
checker: qt.CmpEquals(),
got: cmpEqualsGot,
args: []interface{}{cmpEqualsWant},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
}
want:
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
}
`, diff(cmpEqualsGot, cmpEqualsWant)),
}, {
about: "CmpEquals: different values, long output",
checker: qt.CmpEquals(),
got: []interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line 3"},
args: []interface{}{[]interface{}{cmpEqualsWant, "extra line 1"}},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
want:
[]interface {}{
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
"extra line 1",
}
`, diff([]interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line 3"}, []interface{}{cmpEqualsWant, "extra line 1"})),
}, {
about: "CmpEquals: different values: long output and verbose",
checker: qt.CmpEquals(),
got: []interface{}{cmpEqualsWant, "extra line 1", "extra line 2"},
args: []interface{}{[]interface{}{cmpEqualsWant, "extra line 1"}},
verbose: true,
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
[]interface {}{
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
"extra line 1",
"extra line 2",
}
want:
[]interface {}{
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
"extra line 1",
}
`, diff([]interface{}{cmpEqualsWant, "extra line 1", "extra line 2"}, []interface{}{cmpEqualsWant, "extra line 1"})),
}, {
about: "CmpEquals: different values, long output, same number of lines",
checker: qt.CmpEquals(),
got: []interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line 3"},
args: []interface{}{[]interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line three"}},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
want:
<suppressed due to length (11 lines), use -v for full output>
`, diff([]interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line 3"}, []interface{}{cmpEqualsWant, "extra line 1", "extra line 2", "extra line three"})),
}, {
about: "CmpEquals: same values with options",
checker: qt.CmpEquals(sameInts),
got: []int{1, 2, 3},
args: []interface{}{
[]int{3, 2, 1},
},
expectedNegateFailure: `
error:
unexpected success
got:
[]int{1, 2, 3}
want:
[]int{3, 2, 1}
`,
}, {
about: "CmpEquals: different values with options",
checker: qt.CmpEquals(sameInts),
got: []int{1, 2, 4},
args: []interface{}{
[]int{3, 2, 1},
},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
[]int{1, 2, 4}
want:
[]int{3, 2, 1}
`, diff([]int{1, 2, 4}, []int{3, 2, 1}, sameInts)),
}, {
about: "CmpEquals: structs with unexported fields not allowed",
checker: qt.CmpEquals(),
got: struct{ answer int }{
answer: 42,
},
args: []interface{}{
struct{ answer int }{
answer: 42,
},
},
expectedCheckFailure: `
error:
bad check: cannot handle unexported field at root.answer:
"github.com/frankban/quicktest_test".(struct { answer int })
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
`,
expectedNegateFailure: `
error:
bad check: cannot handle unexported field at root.answer:
"github.com/frankban/quicktest_test".(struct { answer int })
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
`,
}, {
about: "CmpEquals: structs with unexported fields ignored",
checker: qt.CmpEquals(cmpopts.IgnoreUnexported(struct{ answer int }{})),
got: struct{ answer int }{
answer: 42,
},
args: []interface{}{
struct{ answer int }{
answer: 42,
},
},
expectedNegateFailure: `
error:
unexpected success
got:
struct { answer int }{answer:42}
want:
<same as "got">
`,
}, {
about: "CmpEquals: same times",
checker: qt.CmpEquals(),
got: goTime,
args: []interface{}{
goTime,
},
expectedNegateFailure: `
error:
unexpected success
got:
s"2012-03-28 00:00:00 +0000 UTC"
want:
<same as "got">
`,
}, {
about: "CmpEquals: different times: verbose",
checker: qt.CmpEquals(),
got: goTime.Add(24 * time.Hour),
args: []interface{}{
goTime,
},
verbose: true,
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
s"2012-03-29 00:00:00 +0000 UTC"
want:
s"2012-03-28 00:00:00 +0000 UTC"
`, diff(goTime.Add(24*time.Hour), goTime)),
}, {
about: "CmpEquals: not enough arguments",
checker: qt.CmpEquals(),
expectedCheckFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
expectedNegateFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
}, {
about: "CmpEquals: too many arguments",
checker: qt.CmpEquals(),
got: []int{42},
args: []interface{}{[]int{42}, "bad wolf"},
expectedCheckFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
[]int{42},
"bad wolf",
}
want args:
want
`,
expectedNegateFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
[]int{42},
"bad wolf",
}
want args:
want
`,
}, {
about: "DeepEquals: different values",
checker: qt.DeepEquals,
got: cmpEqualsGot,
args: []interface{}{cmpEqualsWant},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
}
want:
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
}
`, diff(cmpEqualsGot, cmpEqualsWant)),
}, {
about: "DeepEquals: different values: long output",
checker: qt.DeepEquals,
got: []interface{}{cmpEqualsWant, cmpEqualsWant},
args: []interface{}{[]interface{}{cmpEqualsWant, cmpEqualsWant, 42}},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
<suppressed due to length (15 lines), use -v for full output>
want:
<suppressed due to length (16 lines), use -v for full output>
`, diff([]interface{}{cmpEqualsWant, cmpEqualsWant}, []interface{}{cmpEqualsWant, cmpEqualsWant, 42})),
}, {
about: "DeepEquals: different values: long output and verbose",
checker: qt.DeepEquals,
got: []interface{}{cmpEqualsWant, cmpEqualsWant},
args: []interface{}{[]interface{}{cmpEqualsWant, cmpEqualsWant, 42}},
verbose: true,
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
[]interface {}{
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
}
want:
[]interface {}{
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
struct { Strings []interface {}; Ints []int }{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
int(42),
}
`, diff([]interface{}{cmpEqualsWant, cmpEqualsWant}, []interface{}{cmpEqualsWant, cmpEqualsWant, 42})),
}, {
about: "ContentEquals: same values",
checker: qt.ContentEquals,
got: []string{"these", "are", "the", "voyages"},
args: []interface{}{
[]string{"these", "are", "the", "voyages"},
},
expectedNegateFailure: `
error:
unexpected success
got:
[]string{"these", "are", "the", "voyages"}
want:
<same as "got">
`,
}, {
about: "ContentEquals: same contents",
checker: qt.ContentEquals,
got: []int{1, 2, 3},
args: []interface{}{
[]int{3, 2, 1},
},
expectedNegateFailure: `
error:
unexpected success
got:
[]int{1, 2, 3}
want:
[]int{3, 2, 1}
`,
}, {
about: "ContentEquals: same contents on complex slice",
checker: qt.ContentEquals,
got: []struct {
Strings []interface{}
Ints []int
}{cmpEqualsGot, cmpEqualsGot, cmpEqualsWant},
args: []interface{}{
[]struct {
Strings []interface{}
Ints []int
}{cmpEqualsWant, cmpEqualsGot, cmpEqualsGot},
},
expectedNegateFailure: `
error:
unexpected success
got:
[]struct { Strings []interface {}; Ints []int }{
{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
},
{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
},
{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
}
want:
[]struct { Strings []interface {}; Ints []int }{
{
Strings: {
"who",
"dalek",
},
Ints: {42},
},
{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
},
{
Strings: {
"who",
"dalek",
},
Ints: {42, 47},
},
}
`,
}, {
about: "ContentEquals: same contents on a nested slice",
checker: qt.ContentEquals,
got: struct {
Nums []int
}{
Nums: []int{1, 2, 3, 4},
},
args: []interface{}{
struct {
Nums []int
}{
Nums: []int{4, 3, 2, 1},
},
},
expectedNegateFailure: `
error:
unexpected success
got:
struct { Nums []int }{
Nums: {1, 2, 3, 4},
}
want:
struct { Nums []int }{
Nums: {4, 3, 2, 1},
}
`,
}, {
about: "ContentEquals: slices of different type",
checker: qt.ContentEquals,
got: []string{"bad", "wolf"},
args: []interface{}{
[]interface{}{"bad", "wolf"},
},
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-want +got):
%s
got:
[]string{"bad", "wolf"}
want:
[]interface {}{
"bad",
"wolf",
}
`, diff([]string{"bad", "wolf"}, []interface{}{"bad", "wolf"})),
}, {
about: "ContentEquals: not enough arguments",
checker: qt.ContentEquals,
expectedCheckFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
expectedNegateFailure: `
error:
bad check: not enough arguments provided to checker: got 0, want 1
want args:
want
`,
}, {
about: "ContentEquals: too many arguments",
checker: qt.ContentEquals,
args: []interface{}{nil, nil},
expectedCheckFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
nil,
nil,
}
want args:
want
`,
expectedNegateFailure: `
error:
bad check: too many arguments provided to checker: got 2, want 1
got args:
[]interface {}{
nil,
nil,
}
want args:
want
`,
}, {
about: "Matches: perfect match",
checker: qt.Matches,
got: "exterminate",
args: []interface{}{"exterminate"},
expectedNegateFailure: `
error:
unexpected success
got value:
"exterminate"
regexp:
<same as "got value">
`,
}, {
about: "Matches: match",
checker: qt.Matches,
got: "these are the voyages",
args: []interface{}{"these are the .*"},
expectedNegateFailure: `
error:
unexpected success
got value:
"these are the voyages"
regexp:
"these are the .*"
`,
}, {
about: "Matches: match with pre-compiled regexp",
checker: qt.Matches,
got: bytes.NewBufferString("resistance is futile"),
args: []interface{}{regexp.MustCompile("resistance is (futile|useful)")},
expectedNegateFailure: `
error:
unexpected success
got value:
s"resistance is futile"
regexp:
s"resistance is (futile|useful)"
`,
}, {
about: "Matches: mismatch with pre-compiled regexp",
checker: qt.Matches,
got: bytes.NewBufferString("resistance is cool"),
args: []interface{}{regexp.MustCompile("resistance is (futile|useful)")},
expectedCheckFailure: `
error:
value.String() does not match regexp
got value:
s"resistance is cool"
regexp:
s"resistance is (futile|useful)"
`,
}, {
about: "Matches: match with pre-compiled multi-line regexp",
checker: qt.Matches,
got: bytes.NewBufferString("line 1\nline 2"),
args: []interface{}{regexp.MustCompile(`line \d\nline \d`)},
expectedNegateFailure: `
error:
unexpected success
got value:
s"line 1\nline 2"
regexp:
s"line \\d\\nline \\d"
`,
}, {
about: "Matches: match with stringer",
checker: qt.Matches,
got: bytes.NewBufferString("resistance is futile"),