diff --git a/resources/yaml-test-suite/98YD.yml b/resources/yaml-test-suite/98YD.yml new file mode 100644 index 0000000..b5b0fcd --- /dev/null +++ b/resources/yaml-test-suite/98YD.yml @@ -0,0 +1,11 @@ +elemennts: + - name: Spec Example 5.5. Comment Indicator + from: http://www.yaml.org/spec/1.2/spec.html#id2773032 + tags: spec comment empty + yaml: | + # Comment only. + tree: | + +STR + -STR + json: "" + dump: "" diff --git a/src/root.zig b/src/root.zig index 06e4cb1..b99f422 100644 --- a/src/root.zig +++ b/src/root.zig @@ -362,6 +362,8 @@ pub fn Ymlz(comptime Destination: type) type { const expression = try self.parseSimpleExpression(raw_line, depth); const value = self.getExpressionValue(expression); + if (value.len == 0) return value; + switch (value[0]) { '|' => { return self.parseMultilineString(depth + 1, true); @@ -491,6 +493,7 @@ pub fn Ymlz(comptime Destination: type) type { test { _ = Suspense; + _ = @import("tests.zig"); } test "should be able to parse simple types" { diff --git a/src/tests.zig b/src/tests.zig new file mode 100644 index 0000000..ba4d3f9 --- /dev/null +++ b/src/tests.zig @@ -0,0 +1,33 @@ +const std = @import("std"); + +const expect = std.testing.expect; + +const Ymlz = @import("root.zig").Ymlz; + +test "98YD" { + const Element = struct { + name: []const u8, + from: []const u8, + tags: []const u8, + yaml: []const u8, + tree: []const u8, + json: []const u8, + dump: []const u8, + }; + + const Experiment = struct { + elements: []Element, + }; + + const yml_file_location = try std.fs.cwd().realpathAlloc( + std.testing.allocator, + "./resources/yaml-test-suite/98YD.yml", + ); + defer std.testing.allocator.free(yml_file_location); + + var ymlz = try Ymlz(Experiment).init(std.testing.allocator); + const result = try ymlz.loadFile(yml_file_location); + defer ymlz.deinit(result); + + try expect(std.mem.eql(u8, result.elements[0].name, "Spec Example 5.5. Comment Indicator")); +}