| 1 | package catscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.21 errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.21 fmt/" |
| 6 | "runtimescip-go gomod github.com/golang/go/src go1.21 runtime/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.21 strings/" |
| 8 | "syncscip-go gomod github.com/golang/go/src go1.21 sync/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.21 testing/" |
| 10 | ) |
| 11 | |
| 12 | type sTypescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/sType# string |
| 13 | |
| 14 | func (s sTypescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/sType#) Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/sType#String().() string { return "S(" + string(s) + ")" } |
| 15 | |
| 16 | func TestJoinscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestJoin().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 17 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | args []any |
| 21 | want string |
| 22 | }{ |
| 23 | {"Empty", nil, ""}, |
| 24 | {"Strings", []any{"a", "b"}, "ab"}, |
| 25 | {"Mixed", []any{1, ":", true}, "1:true"}, |
| 26 | {"Stringer", []any{sTypescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/sType#("x")}, "S(x)"}, |
| 27 | {"Error", []any{errorsscip-go gomod github.com/golang/go/src go1.21 errors/.Newscip-go gomod github.com/golang/go/src go1.21 errors/New().("boom")}, "boom"}, |
| 28 | } |
| 29 | for _, tt := range tests { |
| 30 | tt := tt |
| 31 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 32 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 33 | if got := Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(tt.args...); got != tt.want { |
| 34 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Join() = %q, want %q", got, tt.want) |
| 35 | } |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func TestWithAndSeparatorsscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestWithAndSeparators().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 41 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 42 | if got := Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().("-", 1, 2, 3); got != "1-2-3" { |
| 43 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("With() = %q", got) |
| 44 | } |
| 45 | if got := Spacescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Space().("a", "b", "c"); got != "a b c" { |
| 46 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Space() = %q", got) |
| 47 | } |
| 48 | if got := CSVscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/CSV().("a", "b", "c"); got != "a,b,c" { |
| 49 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("CSV() = %q", got) |
| 50 | } |
| 51 | if got := Commascip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Comma().("a", "b"); got != "a, b" { |
| 52 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Comma() = %q", got) |
| 53 | } |
| 54 | if got := Pathscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Path().("usr", "local", "bin"); got != "usr/local/bin" { |
| 55 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Path() = %q", got) |
| 56 | } |
| 57 | if got := Linesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Lines().("x", "y", "z"); got != "x\ny\nz" { |
| 58 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Lines() = %q", got) |
| 59 | } |
| 60 | if got := Quotescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Quote().("a", 1, true); got != `"a" "1" "true"` { |
| 61 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Quote() = %q", got) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestWrapscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestWrap().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 66 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 67 | tests := []struct { |
| 68 | name string |
| 69 | before string |
| 70 | after string |
| 71 | args []any |
| 72 | expected string |
| 73 | }{ |
| 74 | {"Empty", "<", ">", nil, "<>"}, |
| 75 | {"Single", "[", "]", []any{"test"}, "[test]"}, |
| 76 | {"MultiNoSep", "(", ")", []any{1, 2, 3}, "(123)"}, |
| 77 | } |
| 78 | for _, tt := range tests { |
| 79 | tt := tt |
| 80 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 81 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 82 | got := Wrapscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Wrap().(tt.before, tt.after, tt.args...) |
| 83 | if got != tt.expected { |
| 84 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Wrap() = %q, want %q", got, tt.expected) |
| 85 | } |
| 86 | }) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func TestWrapEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestWrapEach().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 91 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | before string |
| 95 | after string |
| 96 | args []any |
| 97 | expected string |
| 98 | }{ |
| 99 | {"Numbers", "<", ">", []any{1, 2, 3}, "<1><2><3>"}, |
| 100 | {"Mixed", "'", "'", []any{"a", 1, true}, "'a''1''true'"}, |
| 101 | } |
| 102 | for _, tt := range tests { |
| 103 | tt := tt |
| 104 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 105 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 106 | got := WrapEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/WrapEach().(tt.before, tt.after, tt.args...) |
| 107 | if got != tt.expected { |
| 108 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("WrapEach() = %q, want %q", got, tt.expected) |
| 109 | } |
| 110 | }) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | func TestWrapWithSepscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestWrapWithSep().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 115 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 116 | got := WrapWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/WrapWith().(",", "[", "]", 1, 2, 3) |
| 117 | if got != "[1,2,3]" { |
| 118 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("WrapWith: %q", got) |
| 119 | } |
| 120 | got = WrapWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/WrapWith().(" | ", "<", ">", "a", "b") |
| 121 | if got != "<a | b>" { |
| 122 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("WrapWith 2: %q", got) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestBetweenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestBetween().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 127 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 128 | got := BetweenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/BetweenWith().(",", "START", "END", 1, 2, 3) |
| 129 | if got != "START,1,2,3,END" { |
| 130 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Between: %q", got) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func TestPrefixSuffixscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestPrefixSuffix().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 135 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 136 | if got := PrefixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PrefixWith().(" ", "P:", 1, 2); got != "P: 1 2" { |
| 137 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Prefix: %q", got) |
| 138 | } |
| 139 | |
| 140 | if got := SuffixWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SuffixWith().(" ", ":S", 1, 2); got != "1 2 :S" { |
| 141 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Suffix: %q", got) |
| 142 | } |
| 143 | |
| 144 | if got := PrefixEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PrefixEach().("pre-", ",", "a", "b", "c"); got != "pre-a,pre-b,pre-c" { |
| 145 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("PrefixEach: %q", got) |
| 146 | } |
| 147 | if got := SuffixEachscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SuffixEach().("-s", " | ", "a", "b"); got != "a-s | b-s" { |
| 148 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("SuffixEach: %q", got) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func TestIndentscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestIndent().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 153 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 154 | if got := Indentscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Indent().(0, "x", "y"); got != "xy" { |
| 155 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Indent depth 0: %q", got) |
| 156 | } |
| 157 | if got := Indentscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Indent().(2, "x"); got != " x" { |
| 158 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Indent depth 2: %q", got) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func TestFlattenscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestFlatten().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 163 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 164 | tests := []struct { |
| 165 | name string |
| 166 | sep string |
| 167 | // The signature of FlattenWith is now `...any`, so the test data should be `[]any`. |
| 168 | groups []any |
| 169 | want string |
| 170 | }{ |
| 171 | {"Numbers", ",", []any{[]any{1, 2}, []any{3, 4}}, "1,2,3,4"}, |
| 172 | {"WithEmptyGroups", "-", []any{[]any{"a"}, []any{}, []any{"b", "c"}, []any{}}, "a-b-c"}, |
| 173 | {"AllEmpty", ",", []any{[]any{}, []any{}}, ""}, |
| 174 | {"SingleGroupNoSep", ",", []any{[]any{"x"}}, "x"}, |
| 175 | {"MultipleGroupsMultiElem", "|", []any{[]any{"x", "y"}, []any{"z"}}, "x|y|z"}, |
| 176 | {"DeeplyNested", ".", []any{1, []any{2, []any{3, 4}}, 5}, "1.2.3.4.5"}, |
| 177 | } |
| 178 | for _, tt := range tests { |
| 179 | tt := tt |
| 180 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 181 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 182 | // We must use the `...` spread operator to pass the elements of the slice |
| 183 | // as individual arguments to the variadic function. |
| 184 | if got := FlattenWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/FlattenWith().(tt.sep, tt.groups...); got != tt.want { |
| 185 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("FlattenWith() = %q, want %q", got, tt.want) |
| 186 | } |
| 187 | }) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func TestBuilderBasicscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestBuilderBasic().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 192 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 193 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(",") |
| 194 | defer b.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() // ok even if Pool(false) |
| 195 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(1).Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(2) |
| 196 | if got := b.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "1,2" { |
| 197 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Builder String: %q", got) |
| 198 | } |
| 199 | // Sep and AddIf |
| 200 | b2 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(" ") |
| 201 | defer b2.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 202 | b2.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("hi").Sepscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Sep().("-").Ifscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#If().(false, "no").Ifscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#If().(true, "there") |
| 203 | if got := b2.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "hi-there" { |
| 204 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Builder AddIf/Sep: %q", got) |
| 205 | } |
| 206 | // Grow shouldn’t break anything |
| 207 | b3 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().("|").Growscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Grow().(64).Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("a", "b", "c") |
| 208 | defer b3.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 209 | if got := b3.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "a|b|c" { |
| 210 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Builder Grow/Add: %q", got) |
| 211 | } |
| 212 | // StartBetween |
| 213 | b4 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(":", "A").Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("B", "C") |
| 214 | defer b4.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 215 | if got := b4.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "A:B:C" { |
| 216 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("StartBetween: %q", got) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func TestBuilderPoolingscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestBuilderPooling().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 221 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 222 | // Off by default: New returns a fresh builder. |
| 223 | Poolscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pool().(false) |
| 224 | b1 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(",") |
| 225 | if b1 == nil { |
| 226 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().("New returned nil") |
| 227 | } |
| 228 | b1.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().(1, 2) |
| 229 | out1 := b1.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().() |
| 230 | b1.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() // no-op |
| 231 | if out1 != "1,2" { |
| 232 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Pool(false) output: %q", out1) |
| 233 | } |
| 234 | |
| 235 | // Enable pool and ensure Release resets state. |
| 236 | Poolscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pool().(true) |
| 237 | b2 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(" ") |
| 238 | b2.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("x", "y") |
| 239 | if got := b2.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "x y" { |
| 240 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("pooled builder out: %q", got) |
| 241 | } |
| 242 | b2.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 243 | |
| 244 | // Re-acquire and ensure previous content is not retained. |
| 245 | b3 := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().(",") |
| 246 | if got := b3.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "" { |
| 247 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("pooled builder should be reset, got %q", got) |
| 248 | } |
| 249 | b3.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("a") |
| 250 | if got := b3.Stringscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#String().(); got != "a" { |
| 251 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("pooled builder after reuse: %q", got) |
| 252 | } |
| 253 | b3.Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 254 | } |
| 255 | |
| 256 | func TestUnsafeBytesTogglescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestUnsafeBytesToggle().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 257 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 258 | // Ensure default is off (we don't assume, we force it). |
| 259 | SetUnsafeBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SetUnsafeBytes().(false) |
| 260 | if IsUnsafeBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/IsUnsafeBytes().() { |
| 261 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().("expected IsUnsafeBytes=false") |
| 262 | } |
| 263 | b := []byte("xyz") |
| 264 | got := Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(b) |
| 265 | if got != "xyz" { |
| 266 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Join([]byte) copy mode: %q", got) |
| 267 | } |
| 268 | // Turn on and ensure content still matches. |
| 269 | SetUnsafeBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/SetUnsafeBytes().(true) |
| 270 | if !IsUnsafeBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/IsUnsafeBytes().() { |
| 271 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().("expected IsUnsafeBytes=true") |
| 272 | } |
| 273 | b2 := []byte("abc") |
| 274 | got2 := Concatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Concat().(b2) |
| 275 | if got2 != "abc" { |
| 276 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Join([]byte) unsafe mode: %q", got2) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func TestTypesCoveragescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestTypesCoverage().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 281 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 282 | var ( |
| 283 | i8 int8 = -8 |
| 284 | i16 int16 = -16 |
| 285 | i32 int32 = -32 |
| 286 | i64 int64 = -64 |
| 287 | u8 uint8 = 8 |
| 288 | u16 uint16 = 16 |
| 289 | u32 uint32 = 32 |
| 290 | u64 uint64 = 64 |
| 291 | f32 float32 = 3.5 |
| 292 | f64 float64 = 9.25 |
| 293 | ) |
| 294 | err := errorsscip-go gomod github.com/golang/go/src go1.21 errors/.Newscip-go gomod github.com/golang/go/src go1.21 errors/New().("X") |
| 295 | s := sTypescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/sType#("Y") |
| 296 | got := Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().(",", i8, i16, i32, i64, u8, u16, u32, u64, f32, f64, true, false, err, s) |
| 297 | wantPrefix := "-8,-16,-32,-64,8,16,32,64,3.5,9.25,true,false,X,S(Y)" |
| 298 | if got != wantPrefix { |
| 299 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("types coverage:\n got: %q\nwant: %q", got, wantPrefix) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | func TestConcurrencySmokescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestConcurrencySmoke().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 304 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 305 | const N = 64 |
| 306 | wg := syncscip-go gomod github.com/golang/go/src go1.21 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.21 sync/WaitGroup#{} |
| 307 | wg.Addscip-go gomod github.com/golang/go/src go1.21 sync/WaitGroup#Add().(N) |
| 308 | errs := make(chan error, N) |
| 309 | for i := 0; i < N; i++ { |
| 310 | i := i |
| 311 | go func() { |
| 312 | defer wg.Donescip-go gomod github.com/golang/go/src go1.21 sync/WaitGroup#Done().() |
| 313 | s := Withscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/With().("-", "g", i, "t", i*i) |
| 314 | if !stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(s, "g-") || !stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Containsscip-go gomod github.com/golang/go/src go1.21 strings/Contains().(s, "t-") { |
| 315 | errs <- fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("bad string: %q", s) |
| 316 | } |
| 317 | }() |
| 318 | } |
| 319 | wg.Waitscip-go gomod github.com/golang/go/src go1.21 sync/WaitGroup#Wait().() |
| 320 | close(errs) |
| 321 | for err := range errs { |
| 322 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Sanity: ensure no lingering goroutines or leaks on pool toggles (smoke). |
| 327 | func TestPoolToggleDoesNotLeakscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestPoolToggleDoesNotLeak().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 328 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 329 | // Force GC cycles around pool use; this is just a smoke test. |
| 330 | Poolscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pool().(true) |
| 331 | for i := 0; i < 100; i++ { |
| 332 | b := Newscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/New().("|") |
| 333 | b.Addscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Add().("a", i, "b").Releasescip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Builder#Release().() |
| 334 | } |
| 335 | Poolscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pool().(false) |
| 336 | runtimescip-go gomod github.com/golang/go/src go1.21 runtime/.GCscip-go gomod github.com/golang/go/src go1.21 runtime/GC().() |
| 337 | } |
| 338 | |
| 339 | func TestAppendFunctionsscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestAppendFunctions().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 340 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 341 | dst := []byte("start") |
| 342 | got := Appendscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Append().(dst, "end", 1) |
| 343 | if string(got) != "startend1" { |
| 344 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Append = %q, want startend1", string(got)) |
| 345 | } |
| 346 | |
| 347 | dst2 := []byte("start") |
| 348 | got2 := AppendWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendWith().(" ", dst2, "more", 2) |
| 349 | // The function correctly produces "start" + "more 2". The test must expect this. |
| 350 | expected := "startmore 2" |
| 351 | if string(got2) != expected { |
| 352 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("AppendWith = %q, want %q", string(got2), expected) |
| 353 | } |
| 354 | |
| 355 | dst3 := []byte("start") |
| 356 | got3 := AppendBytesscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendBytes().(dst3, []byte("bytes")) |
| 357 | if string(got3) != "startbytes" { |
| 358 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("AppendBytes = %q, want startbytes", string(got3)) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func TestAppendToFunctionsscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestAppendToFunctions().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 363 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 364 | var sb stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Builderscip-go gomod github.com/golang/go/src go1.21 strings/Builder# |
| 365 | AppendToscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendTo().(&sb, "a", 1) |
| 366 | if sb.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().() != "a1" { |
| 367 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("AppendTo = %q, want a1", sb.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().()) |
| 368 | } |
| 369 | AppendStringsscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/AppendStrings().(&sb, "b", "c") |
| 370 | if sb.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().() != "a1bc" { |
| 371 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("AppendStrings = %q, want a1bc", sb.Stringscip-go gomod github.com/golang/go/src go1.21 strings/Builder#String().()) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | func TestGroupscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestGroup().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 376 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 377 | tests := []struct { |
| 378 | name string |
| 379 | sep string |
| 380 | groups [][]any |
| 381 | want string |
| 382 | }{ |
| 383 | {"Empty", "", nil, ""}, |
| 384 | {"Single", " ", [][]any{{1, "a"}}, "1a"}, |
| 385 | {"Multiple", ",", [][]any{{"x"}, {"y", "z"}}, "x,yz"}, |
| 386 | {"WithEmpty", "-", [][]any{{"a"}, {}, {"b"}}, "a-b"}, |
| 387 | } |
| 388 | for _, tt := range tests { |
| 389 | tt := tt |
| 390 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 391 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 392 | if got := GroupWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/GroupWith().(tt.sep, tt.groups...); got != tt.want { |
| 393 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("GroupWith() = %q, want %q", got, tt.want) |
| 394 | } |
| 395 | }) |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | func TestNumberscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestNumber().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 400 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 401 | if got := Numberscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Number().(1, 2, 3); got != "123" { |
| 402 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Number() = %q, want 123", got) |
| 403 | } |
| 404 | if got := NumberWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/NumberWith().(",", 4.5, 6.7); got != "4.5,6.7" { |
| 405 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("NumberWith() = %q, want 4.5,6.7", got) |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | func TestPairTrioscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestPairTrio().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 410 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 411 | if got := Pairscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Pair().("a", "b"); got != "ab" { |
| 412 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Pair() = %q, want ab", got) |
| 413 | } |
| 414 | if got := PairWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/PairWith().("-", "c", "d"); got != "c-d" { |
| 415 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("PairWith() = %q, want c-d", got) |
| 416 | } |
| 417 | if got := Trioscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Trio().(1, 2, 3); got != "123" { |
| 418 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Trio() = %q, want 123", got) |
| 419 | } |
| 420 | if got := TrioWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TrioWith().(":", "x", "y", "z"); got != "x:y:z" { |
| 421 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("TrioWith() = %q, want x:y:z", got) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | func TestRepeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/TestRepeat().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 426 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 427 | if got := Repeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Repeat().("a", 3); got != "aaa" { |
| 428 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Repeat() = %q, want aaa", got) |
| 429 | } |
| 430 | if got := RepeatWithscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/RepeatWith().("-", "b", 2); got != "b-b" { |
| 431 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("RepeatWith() = %q, want b-b", got) |
| 432 | } |
| 433 | if got := Repeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Repeat().("c", 0); got != "" { |
| 434 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Repeat(0) = %q, want empty", got) |
| 435 | } |
| 436 | if got := Repeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Repeat().("d", -1); got != "" { |
| 437 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Repeat(-1) = %q, want empty", got) |
| 438 | } |
| 439 | if got := Repeatscip-go gomod github.com/olekukonko/cat . `github.com/olekukonko/cat`/Repeat().(1, 1); got != "1" { |
| 440 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Repeat(1) = %q, want 1", got) |
| 441 | } |
| 442 | } |