(t *testing.T)
| 194 | } |
| 195 | |
| 196 | func TestMergeNamed_SourceEOF(t *testing.T) { |
| 197 | r1, w1 := Pipe[string](2) |
| 198 | r2, w2 := Pipe[string](2) |
| 199 | |
| 200 | go func() { |
| 201 | w1.Send("a", nil) |
| 202 | w1.Close() |
| 203 | }() |
| 204 | go func() { |
| 205 | w2.Send("b", nil) |
| 206 | w2.Send("c", nil) |
| 207 | w2.Close() |
| 208 | }() |
| 209 | |
| 210 | merged := MergeNamed(map[string]*Reader[string]{ |
| 211 | "stream1": r1, |
| 212 | "stream2": r2, |
| 213 | }) |
| 214 | defer merged.Close() |
| 215 | |
| 216 | var values []string |
| 217 | var eofSources []string |
| 218 | |
| 219 | for { |
| 220 | v, err := merged.Recv() |
| 221 | if errors.Is(err, io.EOF) { |
| 222 | break |
| 223 | } |
| 224 | if name, ok := GetSourceName(err); ok { |
| 225 | eofSources = append(eofSources, name) |
| 226 | continue |
| 227 | } |
| 228 | if err != nil { |
| 229 | t.Fatalf("unexpected error: %v", err) |
| 230 | } |
| 231 | values = append(values, v) |
| 232 | } |
| 233 | |
| 234 | if len(values) != 3 { |
| 235 | t.Errorf("expected 3 values, got %d: %v", len(values), values) |
| 236 | } |
| 237 | |
| 238 | // 至少应该报告一个源 EOF |
| 239 | if len(eofSources) == 0 { |
| 240 | t.Error("expected at least one source EOF") |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | func TestTransform_Basic(t *testing.T) { |
| 245 | reader := FromSlice([]int{1, 2, 3, 4, 5}) |
nothing calls this directly
no test coverage detected