Debian Codegraph @

testutil/testutil_test.go

raw symbols SCIP
1 // Copyright (c) The EfficientGo Authors.
2 // Licensed under the Apache License 2.0.
3
4 package testutilscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/
5
6 import (
7 "mathscip-go gomod github.com/golang/go/src go1.17 math/"
8 "testingscip-go gomod github.com/golang/go/src go1.17 testing/"
9
10 "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/"
11 "github.com/google/go-cmp/cmp/cmpoptsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/"
12 )
13
14 func TestContainsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/TestContains().(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
15 tests := map[string]struct {
16 haystack []string
17 needle []string
18 shouldMatch bool
19 }{
20 "empty haystack": {
21 haystack: []string{},
22 needle: []string{"key1"},
23 shouldMatch: false,
24 },
25
26 "empty needle": {
27 haystack: []string{"key1", "key2", "key3"},
28 needle: []string{},
29 shouldMatch: false,
30 },
31
32 "single value needle": {
33 haystack: []string{"key1", "key2", "key3"},
34 needle: []string{"key1"},
35 shouldMatch: true,
36 },
37
38 "multiple value needle": {
39 haystack: []string{"key1", "key2", "key3"},
40 needle: []string{"key1", "key2"},
41 shouldMatch: true,
42 },
43
44 "same size needle as haystack": {
45 haystack: []string{"key1", "key2", "key3"},
46 needle: []string{"key1", "key2", "key3"},
47 shouldMatch: true,
48 },
49
50 "larger needle than haystack": {
51 haystack: []string{"key1", "key2", "key3"},
52 needle: []string{"key1", "key2", "key3", "key4"},
53 shouldMatch: false,
54 },
55
56 "needle not contained": {
57 haystack: []string{"key1", "key2", "key3"},
58 needle: []string{"key4"},
59 shouldMatch: false,
60 },
61
62 "haystack ends before needle": {
63 haystack: []string{"key1", "key2", "key3"},
64 needle: []string{"key3", "key4"},
65 shouldMatch: false,
66 },
67 }
68
69 for testName, testData := range tests {
70 t.Runscip-go gomod github.com/golang/go/src go1.17 testing/T#Run().(testName, func(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
71 if testData.shouldMatch != containsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/contains().(testData.haystack, testData.needle) {
72 t.Fatalfscip-go gomod github.com/golang/go/src go1.17 testing/common#Fatalf().("unexpected result testing contains() with %#v", testData)
73 }
74 })
75 }
76 }
77
78 type childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child# struct {
79 Valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#Val. float64
80 }
81
82 type parentscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent# struct {
83 Cscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent#C. childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#
84 }
85
86 type unexpscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp# struct {
87 valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#val. float64
88 }
89
90 func TestEqualsWithNaNscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/TestEqualsWithNaN().(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
91 for _, tc := range []struct {
92 name string
93 a interface{}
94 b interface{}
95 opts cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.Optionsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/Options#
96 }{
97 {
98 a: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().(),
99 b: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().(),
100 name: "Simple NaN value comparison",
101 opts: cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.Optionsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/Options#{cmpoptsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/.EquateNaNsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/EquateNaNs().()},
102 },
103 {
104 a: childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#{Valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#Val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()},
105 b: childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#{Valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#Val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()},
106 name: "NaN value as struct member comparison",
107 opts: cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.Optionsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/Options#{cmpoptsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/.EquateNaNsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/EquateNaNs().()},
108 },
109 {
110 a: parentscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent#{Cscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent#C.: childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#{Valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#Val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()}},
111 b: parentscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent#{Cscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/parent#C.: childscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#{Valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/child#Val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()}},
112 name: "NaN value in nested struct comparison",
113 opts: cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.Optionsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/Options#{cmpoptsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/.EquateNaNsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/EquateNaNs().()},
114 },
115 {
116 a: unexpscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#{valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()},
117 b: unexpscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#{valscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#val.: mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()},
118 name: "NaN value as unexported struct member comparison",
119 opts: cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.Optionsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/Options#{cmpscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/.AllowUnexportedscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp`/AllowUnexported().(unexpscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/unexp#{}), cmpoptsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/.EquateNaNsscip-go gomod github.com/google/go-cmp v0.5.9 `github.com/google/go-cmp/cmp/cmpopts`/EquateNaNs().()},
120 },
121 } {
122 t.Runscip-go gomod github.com/golang/go/src go1.17 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) {
123 WithGoCmpscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/WithGoCmp().(tc.opts).Equalsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/testutil`/goCmp#Equals().(t, tc.a, tc.b)
124 })
125 }
126 }