Skip to content

Commit b82979b

Browse files
committed
get rid of @pipe in tests
1 parent 155edcd commit b82979b

File tree

11 files changed

+69
-70
lines changed

11 files changed

+69
-70
lines changed

src/http/moon.pkg.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
],
88
"wbtest-import": [
99
"moonbitlang/async",
10-
"moonbitlang/async/pipe",
1110
"moonbitlang/async/fs"
1211
],
1312
"test-import": [

src/http/parser_wbtest.mbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn log_response(req : Response, logger : &Logger) -> Unit {
3535
async test "read_request basic" {
3636
let log = StringBuilder::new()
3737
@async.with_task_group(fn(root) {
38-
let (r, w) = @pipe.pipe()
38+
let (r, w) = @io.pipe()
3939
root.spawn_bg(fn() {
4040
defer w.close()
4141
w
@@ -64,7 +64,7 @@ async test "read_request basic" {
6464
async test "read_request fixed body" {
6565
let log = StringBuilder::new()
6666
@async.with_task_group(fn(root) {
67-
let (r, w) = @pipe.pipe()
67+
let (r, w) = @io.pipe()
6868
root.spawn_bg(fn() {
6969
defer w.close()
7070
w
@@ -96,7 +96,7 @@ async test "read_request fixed body" {
9696
async test "read_request chunked" {
9797
let log = StringBuilder::new()
9898
@async.with_task_group(fn(root) {
99-
let (r, w) = @pipe.pipe()
99+
let (r, w) = @io.pipe()
100100
root.spawn_bg(fn() {
101101
defer w.close()
102102
w
@@ -132,7 +132,7 @@ async test "read_request chunked" {
132132
async test "read_request stream" {
133133
let log = StringBuilder::new()
134134
@async.with_task_group(fn(root) {
135-
let (r, w) = @pipe.pipe()
135+
let (r, w) = @io.pipe()
136136
root.spawn_bg(fn() {
137137
defer w.close()
138138
w
@@ -184,7 +184,7 @@ async test "read_request stream" {
184184
async test "multiple request" {
185185
let log = StringBuilder::new()
186186
@async.with_task_group(fn(root) {
187-
let (r, w) = @pipe.pipe()
187+
let (r, w) = @io.pipe()
188188
root.spawn_bg(fn() {
189189
defer w.close()
190190
w
@@ -248,7 +248,7 @@ async test "multiple request" {
248248
async test "read_response basic" {
249249
let log = StringBuilder::new()
250250
@async.with_task_group(fn(root) {
251-
let (r, w) = @pipe.pipe()
251+
let (r, w) = @io.pipe()
252252
root.spawn_bg(fn() {
253253
defer w.close()
254254
w

src/http/send_wbtest.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
///|
1616
async test "send_request basic" {
1717
@async.with_task_group(fn(root) {
18-
let (r, w) = @pipe.pipe()
18+
let (r, w) = @io.pipe()
1919
root.spawn_bg(fn() {
2020
defer w.close()
2121
let sender = Sender::new(w)
@@ -46,7 +46,7 @@ async test "send_request basic" {
4646
///|
4747
async test "send_request stream" {
4848
@async.with_task_group(fn(root) {
49-
let (r, w) = @pipe.pipe()
49+
let (r, w) = @io.pipe()
5050
root.spawn_bg(fn() {
5151
defer w.close()
5252
let sender = Sender::new(w)
@@ -306,7 +306,7 @@ async test "send_request stream" {
306306
///|
307307
async test "send_request stream2" {
308308
@async.with_task_group(fn(root) {
309-
let (r, w) = @pipe.pipe()
309+
let (r, w) = @io.pipe()
310310
root.spawn_bg(fn() {
311311
defer w.close()
312312
let sender = Sender::new(w)

src/io/README.mbt.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This allows convenient conversion of received data to various formats.
6464
///|
6565
async test "data as binary" {
6666
@async.with_task_group(fn(root) {
67-
let (r, w) = @pipe.pipe()
67+
let (r, w) = @io.pipe()
6868
defer r.close()
6969
root.spawn_bg(fn() {
7070
defer w.close()
@@ -80,7 +80,7 @@ async test "data as binary" {
8080
///|
8181
async test "data as text" {
8282
@async.with_task_group(fn(root) {
83-
let (r, w) = @pipe.pipe()
83+
let (r, w) = @io.pipe()
8484
defer r.close()
8585
root.spawn_bg(fn() {
8686
defer w.close()
@@ -96,7 +96,7 @@ async test "data as text" {
9696
///|
9797
async test "data as json" {
9898
@async.with_task_group(fn(root) {
99-
let (r, w) = @pipe.pipe()
99+
let (r, w) = @io.pipe()
100100
defer r.close()
101101
root.spawn_bg(fn() {
102102
defer w.close()
@@ -120,14 +120,14 @@ The `Reader` trait exposes three complementary levels of granularity:
120120
- `read_exactly` loops until it fills the requested number of bytes or raises `ReaderClosed`, which is helpful when parsing fixed-width frames.
121121
- `read_all` drains the stream into memory, returning a `&Data` handle for convenient conversion to text, JSON, or binary.
122122

123-
Each example below shows how a reader pairs with `@pipe.pipe()` and includes inline comments that highlight the important steps.
123+
Each example below shows how a reader pairs with `@io.pipe()` and includes inline comments that highlight the important steps.
124124

125125
```moonbit
126126
///|
127127
async test "read from reader" {
128128
@async.with_task_group(fn(root) {
129129
// Create connected endpoints. `r` is a Reader, `w` is a Writer.
130-
let (r, w) = @pipe.pipe()
130+
let (r, w) = @io.pipe()
131131
defer r.close()
132132
root.spawn_bg(fn() {
133133
defer w.close()
@@ -149,23 +149,25 @@ async test "read from reader" {
149149
///|
150150
async test "read_exactly - read exact number of bytes" {
151151
@async.with_task_group(fn(root) {
152-
let (r, w) = @pipe.pipe()
152+
let (r, w) = @io.pipe()
153153
defer r.close()
154154
root.spawn_bg(fn() {
155155
defer w.close()
156156
// Produce a fixed-size frame.
157157
w.write(b"0123456789")
158158
})
159159
// Blocks until exactly 5 bytes are received or ReaderClosed is raised.
160-
let data = r.read_exactly(5)
161-
inspect(@encoding/utf8.decode(data), content="01234")
160+
let data1 = r.read_exactly(5)
161+
inspect(@encoding/utf8.decode(data1), content="01234")
162+
let data2 = r.read_exactly(5)
163+
inspect(@encoding/utf8.decode(data2), content="56789")
162164
})
163165
}
164166
165167
///|
166168
async test "read_all - read entire content" {
167169
@async.with_task_group(fn(root) {
168-
let (r, w) = @pipe.pipe()
170+
let (r, w) = @io.pipe()
169171
defer r.close()
170172
root.spawn_bg(fn() {
171173
defer w.close()
@@ -181,7 +183,7 @@ async test "read_all - read entire content" {
181183
///|
182184
async test "read_all large data" {
183185
@async.with_task_group(fn(root) {
184-
let (r, w) = @pipe.pipe()
186+
let (r, w) = @io.pipe()
185187
defer r.close()
186188
root.spawn_bg(fn() {
187189
defer w.close()
@@ -207,7 +209,7 @@ The snippets below demonstrate each mode with progressive complexity.
207209
///|
208210
async test "write to writer" {
209211
@async.with_task_group(fn(root) {
210-
let (r, w) = @pipe.pipe()
212+
let (r, w) = @io.pipe()
211213
defer r.close()
212214
root.spawn_bg(fn() {
213215
defer w.close()
@@ -225,7 +227,7 @@ async test "write to writer" {
225227
///|
226228
async test "write_once - single write operation" {
227229
@async.with_task_group(fn(root) {
228-
let (r, w) = @pipe.pipe()
230+
let (r, w) = @io.pipe()
229231
defer r.close()
230232
root.spawn_bg(fn() {
231233
defer w.close()
@@ -242,7 +244,7 @@ async test "write_once - single write operation" {
242244
///|
243245
async test "write large data" {
244246
@async.with_task_group(fn(root) {
245-
let (r, w) = @pipe.pipe()
247+
let (r, w) = @io.pipe()
246248
root.spawn_bg(fn() {
247249
defer w.close()
248250
let data = Bytes::make(1024 * 16, 0)
@@ -260,8 +262,8 @@ async test "write large data" {
260262
async test "write_reader - copy from reader to writer" {
261263
let log = StringBuilder::new()
262264
@async.with_task_group(fn(root) {
263-
let (r1, w1) = @pipe.pipe()
264-
let (r2, w2) = @pipe.pipe()
265+
let (r1, w1) = @io.pipe()
266+
let (r2, w2) = @io.pipe()
265267
root.spawn_bg(fn() {
266268
defer r2.close()
267269
defer w1.close()
@@ -307,7 +309,7 @@ async test "write_reader - copy from reader to writer" {
307309
///|
308310
async test "write string" {
309311
@async.with_task_group(fn(root) {
310-
let (r, w) = @pipe.pipe()
312+
let (r, w) = @io.pipe()
311313
defer r.close()
312314
root.spawn_bg(fn() {
313315
defer w.close()
@@ -336,7 +338,7 @@ In the examples below, pay attention to how buffering reduces the number of sysc
336338
async test "BufferedReader::read" {
337339
let log = StringBuilder::new()
338340
@async.with_task_group(fn(root) {
339-
let (r, w) = @pipe.pipe()
341+
let (r, w) = @io.pipe()
340342
root.spawn_bg(fn() {
341343
defer w.close()
342344
@async.sleep(20)
@@ -380,7 +382,7 @@ async test "BufferedReader::read" {
380382
async test "BufferedReader::read_exactly" {
381383
let log = StringBuilder::new()
382384
@async.with_task_group(fn(root) {
383-
let (r, w) = @pipe.pipe()
385+
let (r, w) = @io.pipe()
384386
root.spawn_bg(fn() {
385387
defer w.close()
386388
@async.sleep(20)
@@ -422,7 +424,7 @@ async test "BufferedReader::op_get - access byte by index" {
422424
let log = StringBuilder::new()
423425
log.write_object(
424426
try? @async.with_task_group(fn(root) {
425-
let (r, w) = @pipe.pipe()
427+
let (r, w) = @io.pipe()
426428
root.spawn_bg(fn() {
427429
defer w.close()
428430
@async.sleep(20)
@@ -470,7 +472,7 @@ async test "BufferedReader::op_as_view - slice data" {
470472
let log = StringBuilder::new()
471473
log.write_object(
472474
try? @async.with_task_group(fn(root) {
473-
let (r, w) = @pipe.pipe()
475+
let (r, w) = @io.pipe()
474476
root.spawn_bg(fn() {
475477
defer w.close()
476478
@async.sleep(20)
@@ -520,7 +522,7 @@ async test "BufferedReader::op_as_view - slice data" {
520522
///|
521523
async test "BufferedReader::drop - advance stream" {
522524
@async.with_task_group(fn(root) {
523-
let (r, w) = @pipe.pipe()
525+
let (r, w) = @io.pipe()
524526
defer r.close()
525527
root.spawn_bg(fn() {
526528
defer w.close()
@@ -539,7 +541,7 @@ async test "BufferedReader::find - search for substring" {
539541
let log = StringBuilder::new()
540542
log.write_object(
541543
try? @async.with_task_group(fn(root) {
542-
let (r, w) = @pipe.pipe()
544+
let (r, w) = @io.pipe()
543545
root.spawn_bg(fn() {
544546
defer w.close()
545547
@async.sleep(20)
@@ -592,7 +594,7 @@ async test "BufferedReader::find - search for substring" {
592594
///|
593595
async test "BufferedReader::find_opt - search for substring with explicit EOF handling" {
594596
@async.with_task_group(fn(root) {
595-
let (r, w) = @pipe.pipe()
597+
let (r, w) = @io.pipe()
596598
root.spawn_bg(fn() {
597599
defer w.close()
598600
@async.sleep(20)
@@ -638,7 +640,7 @@ async test "BufferedReader::read_line - read line by line" {
638640
async test "BufferedWriter - basic buffering" {
639641
let log = StringBuilder::new()
640642
@async.with_task_group(fn(root) {
641-
let (r, w) = @pipe.pipe()
643+
let (r, w) = @io.pipe()
642644
root.spawn_bg(fn() {
643645
defer w.close()
644646
let w = @io.BufferedWriter::new(w, size=4)
@@ -678,7 +680,7 @@ async test "BufferedWriter - basic buffering" {
678680
///|
679681
async test "BufferedWriter::new with custom size" {
680682
@async.with_task_group(fn(root) {
681-
let (r, w) = @pipe.pipe()
683+
let (r, w) = @io.pipe()
682684
defer r.close()
683685
root.spawn_bg(fn() {
684686
defer w.close()
@@ -696,7 +698,7 @@ async test "BufferedWriter::new with custom size" {
696698
///|
697699
async test "BufferedWriter::flush - commit buffered data" {
698700
@async.with_task_group(fn(root) {
699-
let (r, w) = @pipe.pipe()
701+
let (r, w) = @io.pipe()
700702
defer r.close()
701703
root.spawn_bg(fn() {
702704
defer w.close()
@@ -716,8 +718,8 @@ async test "BufferedWriter::flush - commit buffered data" {
716718
async test "BufferedWriter::write_reader - buffered copy" {
717719
let log = StringBuilder::new()
718720
@async.with_task_group(fn(root) {
719-
let (r1, w1) = @pipe.pipe()
720-
let (r2, w2) = @pipe.pipe()
721+
let (r1, w1) = @io.pipe()
722+
let (r2, w2) = @io.pipe()
721723
root.spawn_bg(fn() {
722724
defer r2.close()
723725
defer w1.close()
@@ -763,14 +765,14 @@ async test "BufferedWriter::write_reader - buffered copy" {
763765

764766
## Working with Task Groups and Pipes
765767

766-
Most examples in this package lean on `@async.with_task_group` and `@pipe.pipe()` because they expose canonical `Reader` and `Writer` handles. The pattern scales to more complex topologies where multiple producers and consumers collaborate.
768+
Most examples in this package lean on `@async.with_task_group` and `@io.pipe()` because they expose canonical `Reader` and `Writer` handles. The pattern scales to more complex topologies where multiple producers and consumers collaborate.
767769

768770
```moonbit
769771
///|
770772
async test "fan-out and fan-in" {
771773
@async.with_task_group(fn(root) {
772774
// Upstream producer pushes a header followed by the payload.
773-
let (intermediate_reader, intermediate_writer) = @pipe.pipe()
775+
let (intermediate_reader, intermediate_writer) = @io.pipe()
774776
root.spawn_bg(fn() {
775777
defer intermediate_writer.close()
776778
intermediate_writer.write(b"HDR")
@@ -781,7 +783,7 @@ async test "fan-out and fan-in" {
781783
let buffered = @io.BufferedReader::new(intermediate_reader)
782784
783785
// A downstream consumer receives the header via its own pipe.
784-
let (header_reader, header_writer) = @pipe.pipe()
786+
let (header_reader, header_writer) = @io.pipe()
785787
root.spawn_bg(fn() {
786788
defer header_writer.close()
787789
let header = buffered.read_exactly(3)

0 commit comments

Comments
 (0)