summaryrefslogtreecommitdiff
path: root/src/libzisp.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/libzisp.zig')
-rw-r--r--src/libzisp.zig19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libzisp.zig b/src/libzisp.zig
index d610f4e..f67f568 100644
--- a/src/libzisp.zig
+++ b/src/libzisp.zig
@@ -246,8 +246,13 @@ test "pair" {
try std.testing.expectEqual(4, value.fixnum.unpack(cdr2));
}
+fn parseString(str: []const u8) Value {
+ var fbs = std.io.fixedBufferStream(str);
+ return io.parser.parse(fbs.reader().any());
+}
+
test "parse" {
- const val = io.parser.parse("\"foo\"");
+ const val = parseString("\"foo\"");
try std.testing.expect(value.sstr.check(val));
@@ -256,7 +261,7 @@ test "parse" {
}
test "parse2" {
- const val = io.parser.parse(
+ const val = parseString(
\\ ;; Testing some crazy datum comments
\\ #;"bar"#;([x #"y"]{##`,'z}) #"foo"
\\ ;; end
@@ -273,7 +278,7 @@ test "parse2" {
}
test "parse3" {
- const val = io.parser.parse(
+ const val = parseString(
\\(foo #;x #;(x y) #;x #bar [#x #"baz"] 'bat)
);
@@ -289,7 +294,7 @@ test "parse3" {
}
test "parse4" {
- const val = io.parser.parse("(foo . #;x bar #;y)");
+ const val = parseString("(foo . #;x bar #;y)");
const s = value.sstr.unpack(value.pair.car(val));
try std.testing.expectEqualStrings("foo", s.slice());
@@ -308,7 +313,7 @@ test "parse bench" {
std.mem.doNotOptimizeAway(timer.lap());
for (0..iters) |i| {
_ = i;
- std.mem.doNotOptimizeAway(io.parser.parse(
+ std.mem.doNotOptimizeAway(parseString(
\\(a b c (x y z (a b c (x y z (a b c (x y z (a b c (x y z (a b c
\\(x y z (a b c (x y z (a b c (x y z) d e f) d e f) d e f) d e f)
\\d e f) d e f) d e f) d e f) d e f) d e f) d e f) 1 2 3))
@@ -326,7 +331,7 @@ test "unparse" {
var out: std.ArrayList(u8) = .init(gpa.allocator());
const w = out.writer();
- const v = io.parser.parse("#foo");
+ const v = parseString("#foo");
try unparse(w, v);
try std.testing.expectEqualStrings("#foo", try out.toOwnedSlice());
}
@@ -334,6 +339,6 @@ test "unparse" {
test "unparse2" {
try io.unparser.unparse(
std.io.getStdErr().writer(),
- io.parser.parse("#{foo bar['x]}"),
+ parseString("#{foo bar['x]}"),
);
}