ref: f90519332a6d24444a54c2b0943f705e8579550f
dir: /libstd/test/bytebuf.myr/
use "bytebuf.use"
/* support */
use "die.use"
use "fmt.use"
use "sleq.use"
const main = {
var bb, v
bb = std.mkbytebuf()
std.bytebufputc(bb, 'a')
std.assert(bb.len == 1, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "a"), \
"byte buf contents not \"a\"\n")
std.bytebufputs(bb, "bc")
std.assert(bb.len == 3, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abc"), \
"byte buf contents not \"abc\"\n")
std.bytebufputb(bb, 'd' castto(byte))
std.assert(bb.len == 4, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcd"), \
"byte buf contents not \"abcd\"\n")
std.bytebufputle8(bb, 'e' castto(int64))
std.assert(bb.len == 5, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcde"), \
"byte buf contents not \"abcde\"\n")
std.bytebufputbe8(bb, 'e' castto(int64))
std.assert(bb.len == 6, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdee"), \
"byte buf contents not \"abcdee\"\n")
std.bytebufputle16(bb, ('f' | ('g' << 8)) castto(int64))
std.assert(bb.len == 8, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefg"), \
"byte buf contents not \"abcdeefg\"\n")
std.bytebufputbe16(bb, ('f' | ('g' << 8)) castto(int64))
std.assert(bb.len == 10, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefggf"), \
"byte buf contents not \"abcdeefggf\"\n")
std.bytebufputle32(bb, ('h' | ('i' << 8) | ('j' << 16) | ('k' << 24)) castto(int64))
std.assert(bb.len == 14, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefggfhijk"), \
"byte buf contents not \"abcdeefggfhijk\"\n")
std.bytebufputbe32(bb, ('h' | ('i' << 8) | ('j' << 16) | ('k' << 24)) castto(int64))
std.assert(bb.len == 18, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefggfhijkkjih"), \
"byte buf contents not \"abcdeefggfhijkkji\"\n")
v = ('l' | ('m' << 8) | ('n' << 16) | ('o' << 24)) castto(int64)
v |= v << 32
std.bytebufputle64(bb, v)
std.assert(bb.len == 26, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefggfhijkkjihlmnolmno"), \
"byte buf contents not \"abcdeefggfhijkkjihlmnolmno\"\n")
v = ('l' | ('m' << 8) | ('n' << 16) | ('o' << 24)) castto(int64)
v |= v << 32
std.bytebufputbe64(bb, v)
std.assert(bb.len == 34, "byte buf size wrong\n")
std.assert(std.sleq(bb.buf[:bb.len], "abcdeefggfhijkkjihlmnolmnoonmlonml"), \
"byte buf contents not \"abcdeefggfhijkkjilmnolmnoonmlonml\"\n")
}