summaryrefslogtreecommitdiff
path: root/lib/bio/test/bio-skipto.myr
blob: 862a896cec2685e691fe3fa3d4b76d9750a9c528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std
use bio

const main = {
	var buf : byte[16]
	var f

	/* use the expected write data as read data */
	f = std.try(bio.open("data/bio-skipto", bio.Rd))

	/* read bar from foobar */
	bio.skipto(f, "foo")
	bio.read(f, buf[:3])
	std.assert(std.eq(buf[:3], "bar"), "did not read bar afer foo")

	/* we're past foobar, read to eof */
	bio.skipto(f, "foo")
	match bio.read(f, buf[:3])
	| `std.Err `bio.Eof:	/* ok */
	| `std.Ok _:		std.fatal("expected EOF")
	| `std.Err e:		std.fatal("expected EOF, got {}\n", e)
	;;
	
	/* Ensure we find a delimiter if it spans a 16k boundary */
	f = std.try(bio.open("data/bio-skipto-16kspan", bio.Rd))
	if !bio.skipto(f, "ABCDE")
		std.fatal("failed to find ABCDE spanning boundary")
	;;

	/* Ensure we find a delimiter if it ends on a 16k boundary */
	f = std.try(bio.open("data/bio-skipto-16kbound", bio.Rd))
	if !bio.skipto(f, "ABCDE")
		std.fatal("failed to find ABCDE at end of buffer")
	;;
	
	std.put("success: all reads matched\n")
}