summaryrefslogtreecommitdiff
path: root/libstd/test/strbuf.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-20 20:27:37 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-20 20:27:37 -0700
commitb65a821ba2d8c753e974b02e541229dfd6754a6a (patch)
tree9b765e33439e2f75cb8c1c70698958c67c38331c /libstd/test/strbuf.myr
parent7596ee5f651a67a62de4b009d8647f5b2cf729fb (diff)
downloadmc-b65a821ba2d8c753e974b02e541229dfd6754a6a.tar.gz
Add support for fixed size str buffers.
Diffstat (limited to 'libstd/test/strbuf.myr')
-rw-r--r--libstd/test/strbuf.myr16
1 files changed, 16 insertions, 0 deletions
diff --git a/libstd/test/strbuf.myr b/libstd/test/strbuf.myr
index 92c5a7c..2643da5 100644
--- a/libstd/test/strbuf.myr
+++ b/libstd/test/strbuf.myr
@@ -2,6 +2,7 @@ use std
const main = {
var sb
+ var buf : byte[16]
sb = std.mksb()
std.assert(std.sleq(std.sbpeek(sb), ""), "mismatched empty str\n")
@@ -20,5 +21,20 @@ const main = {
std.assert(std.sleq(std.sbpeek(sb), "hello, 世界"), "mismatched unicode\n")
std.sbputb(sb, 10)
std.assert(std.sleq(std.sbpeek(sb), "hello, 世界\n"), "mismatched byte\n")
+
+ sb = std.mkbufsb(buf[:])
+ std.assert(std.sbputs(sb, "hello"), "failed to add hello\n") /* 5 characters */
+ std.assert(std.sbputs(sb, "hello"), "failed to add hello\n") /* 10 characters */
+ std.assert(std.sbputs(sb, "hello"), "failed to add hello\n") /* 15 characters */
+ std.assert(!std.sbputs(sb, "hello"), "erronous success\n") /* 16 characters */
+ std.assert(std.sleq(std.sbpeek(sb), "hellohellohelloh"), "failed to copy as much as possible\n")
+ std.sbtrim(sb, -1)
+ std.assert(std.sleq(std.sbpeek(sb), "hellohellohello"), "failed rtrim\n")
+ std.sbputc(sb, '世')
+ std.assert(std.sleq(std.sbpeek(sb), "hellohellohello"), "modified overflowed putc\n")
+ std.sbtrim(sb, -2)
+ std.assert(std.sleq(std.sbpeek(sb), "hellohellohel"), "failed rtrim\n")
+ std.sbputc(sb, '世')
+ std.assert(std.sleq(std.sbpeek(sb), "hellohellohel世"), "failed to append with putc\n")
}