Skip to content

Commit

Permalink
Start adding more tests and find more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pwbh committed Sep 6, 2024
1 parent 7b0fcc4 commit ec7335f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions resources/yaml-test-suite/98YD.yml
Original file line number Diff line number Diff line change
@@ -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: ""
3 changes: 3 additions & 0 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -491,6 +493,7 @@ pub fn Ymlz(comptime Destination: type) type {

test {
_ = Suspense;
_ = @import("tests.zig");
}

test "should be able to parse simple types" {
Expand Down
33 changes: 33 additions & 0 deletions src/tests.zig
Original file line number Diff line number Diff line change
@@ -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"));
}

0 comments on commit ec7335f

Please sign in to comment.