-
Notifications
You must be signed in to change notification settings - Fork 55
/
teststreamseq.nim
67 lines (46 loc) · 1.13 KB
/
teststreamseq.nim
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{.used.}
# Nim-Libp2p
# Copyright (c) 2023 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
import unittest2
import stew/byteutils
import ../libp2p/stream/streamseq
suite "StreamSeq":
test "basics":
var s: StreamSeq
check:
s.data().len == 0
s.add([byte 0, 1, 2, 3])
check:
@(s.data()) == [byte 0, 1, 2, 3]
s.prepare(10)[0 ..< 3] = [byte 4, 5, 6]
check:
@(s.data()) == [byte 0, 1, 2, 3]
s.commit(3)
check:
@(s.data()) == [byte 0, 1, 2, 3, 4, 5, 6]
s.consume(1)
check:
@(s.data()) == [byte 1, 2, 3, 4, 5, 6]
s.consume(6)
check:
@(s.data()) == []
s.add([])
check:
@(s.data()) == []
var o: seq[byte]
check:
0 == s.consumeTo(o)
s.add([byte 1, 2, 3])
o.setLen(2)
o.setLen(s.consumeTo(o))
check:
o == [byte 1, 2]
o.setLen(s.consumeTo(o))
check:
o == [byte 3]