Debian Codegraph @

swar_test.go

raw symbols SCIP
1 package utilsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "math/randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/"
6 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
7 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
8
9 casebytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/ "github.com/gofiber/utils/v2/bytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/"
10 "github.com/gofiber/utils/v2/internal/caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/"
11 "github.com/gofiber/utils/v2/internal/unsafeconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/unsafeconv`/"
12 casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/ "github.com/gofiber/utils/v2/stringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/"
13 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/"
14 )
15
16 func Test_SWAR_Randomizedscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_SWAR_Randomized().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
17 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
18 rng := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/NewSource().(42)) //nolint:gosec // deterministic test data
19
20 for range 20000 {
21 // Lengths 0..100 cover sub-word inputs, all %8 tails, and several
22 // full word iterations.
23 n := rng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(101)
24 a := make([]byte, n)
25 b := make([]byte, n)
26 for i := range n {
27 a[i] = byte(rng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(256))
28 // Bias b towards being a case-variant of a so EqualFold hits
29 // both outcomes.
30 if rng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(2) == 0 {
31 b[i] = a[i] ^ 0x20
32 } else {
33 b[i] = byte(rng.Intnscip-go gomod github.com/golang/go/src go1.25.0 `math/rand`/Rand#Intn().(256))
34 }
35 }
36 as, bs := string(a), string(b)
37
38 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as)), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.ToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/ToLower().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as)))
39 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.25.0 strings/ToUpper().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as)), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.ToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/ToUpper().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as)))
40 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.25.0 strings/EqualFold().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as), asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(bs)), EqualFoldscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/EqualFold().(asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(as), asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(bs)))
41
42 // Non-ASCII bytes must pass through unchanged (table semantics).
43 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.ToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/ToLower().(as))
44 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.ToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/ToUpper().(as))
45 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(asciiFoldUpperBscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpperB().(a), asciiFoldUpperBscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpperB().(b)), EqualFoldscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/EqualFold().(a, b))
46
47 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), string(casebytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/.ToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/ToLower().(append([]byte(nil), a...))))
48 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), string(casebytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/.ToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/ToUpper().(append([]byte(nil), a...))))
49 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), string(casebytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/.UnsafeToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/UnsafeToLower().(append([]byte(nil), a...))))
50 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), string(casebytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/.UnsafeToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/bytes`/UnsafeToUpper().(append([]byte(nil), a...))))
51
52 // The strings in-place wrappers mutate their backing bytes, so hand
53 // each a string view over a private mutable copy — string(a) may
54 // reference read-only interned memory (e.g. 1-byte strings).
55 la := append([]byte(nil), a...)
56 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.UnsafeToLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/UnsafeToLower().(unsafeconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/unsafeconv`/.UnsafeStringscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/unsafeconv`/UnsafeString().(la)))
57 ua := append([]byte(nil), a...)
58 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), casestringsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/.UnsafeToUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/strings`/UnsafeToUpper().(unsafeconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/unsafeconv`/.UnsafeStringscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/unsafeconv`/UnsafeString().(ua)))
59
60 // Exercise the caseconv helpers directly so their sub-word tails are
61 // covered even though the public wrappers route short inputs away.
62 lowered := append([]byte(nil), a...)
63 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerInPlacescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerInPlace().(lowered)
64 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), string(lowered))
65 uppered := append([]byte(nil), a...)
66 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperInPlacescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperInPlace().(uppered)
67 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), string(uppered))
68
69 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stdFirstIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stdFirstIndex().(a, 'A', 'Z'), caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.FirstUpperIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/FirstUpperIndex().(a))
70 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, stdFirstIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stdFirstIndex().(a, 'a', 'z'), caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.FirstLowerIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/FirstLowerIndex().(a))
71
72 loweredCopy := make([]byte, n)
73 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerCopy().(loweredCopy, a, 0)
74 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(as), string(loweredCopy))
75 upperedCopy := make([]byte, n)
76 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperCopy().(upperedCopy, a, 0)
77 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(as), string(upperedCopy))
78 }
79 }
80
81 func stdFirstIndexscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/stdFirstIndex().(b []byte, lo, hi byte) int {
82 for i, c := range b {
83 if c >= lo && c <= hi {
84 return i
85 }
86 }
87 return -1
88 }
89
90 func asciiOnlyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiOnly().(s string) string {
91 b := []byte(s)
92 for i := range b {
93 b[i] &= 0x7f
94 }
95 return string(b)
96 }
97
98 func asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(s string) string {
99 b := []byte(s)
100 for i := range b {
101 if b[i] >= 'A' && b[i] <= 'Z' {
102 b[i] += 'a' - 'A'
103 }
104 }
105 return string(b)
106 }
107
108 func asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(s string) string {
109 b := []byte(s)
110 for i := range b {
111 if b[i] >= 'a' && b[i] <= 'z' {
112 b[i] -= 'a' - 'A'
113 }
114 }
115 return string(b)
116 }
117
118 func asciiFoldUpperBscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpperB().(b []byte) []byte {
119 return []byte(asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(string(b)))
120 }
121
122 // Test_CaseCopy_FromOffsets pins the from > 0 contract of ToLowerCopy and
123 // ToUpperCopy directly: from is word-aligned and at or below the first byte
124 // the conversion changes, so the overlapping tail store may rewrite
125 // dst[n-8:from) only as a no-op. The public wrappers exercise this path
126 // indirectly; this test does it without them.
127 func Test_CaseCopy_FromOffsetsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_CaseCopy_FromOffsets().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
128 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
129 for n := 8; n <= 26; n++ {
130 for from := 0; from < n; from += 8 {
131 // Case-stable filler (digits): bytes before firstChange must not
132 // change under either conversion, or from would be invalid.
133 base := make([]byte, n)
134 for i := range base {
135 base[i] = byte('0' + i%10)
136 }
137 for firstChange := from; firstChange < n; firstChange++ {
138 lsrc := append([]byte(nil), base...)
139 lsrc[firstChange] = 'A' + byte(firstChange%26)
140 if firstChange+1 < n {
141 lsrc[firstChange+1] = 0xE9 // non-ASCII passthrough
142 }
143 dst := make([]byte, n)
144 copy(dst[:from], lsrc[:from])
145 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToLowerCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToLowerCopy().(dst, lsrc, from)
146 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldLowerscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldLower().(string(lsrc)), string(dst),
147 "lower n=%d from=%d change=%d", n, from, firstChange)
148
149 usrc := append([]byte(nil), base...)
150 usrc[firstChange] = 'a' + byte(firstChange%26)
151 if firstChange+1 < n {
152 usrc[firstChange+1] = 0xE9
153 }
154 dst2 := make([]byte, n)
155 copy(dst2[:from], usrc[:from])
156 caseconvscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/.ToUpperCopyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/internal/caseconv`/ToUpperCopy().(dst2, usrc, from)
157 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, asciiFoldUpperscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/asciiFoldUpper().(string(usrc)), string(dst2),
158 "upper n=%d from=%d change=%d", n, from, firstChange)
159 }
160 }
161 }
162 }