Skip to content

Commit

Permalink
Infer base for int
Browse files Browse the repository at this point in the history
  • Loading branch information
djboni authored and kubkon committed Feb 7, 2024
1 parent c67849c commit 9308a64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/yaml.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ pub const Value = union(enum) {
const raw = tree.getRaw(node.start, node.end);

try_int: {
// TODO infer base for int
const int = std.fmt.parseInt(i64, raw, 10) catch break :try_int;
const int = std.fmt.parseInt(i64, raw, 0) catch break :try_int;
return Value{ .int = int };
}

Expand Down
19 changes: 19 additions & 0 deletions src/yaml/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ test "list of mixed sign integer" {
try testing.expectEqualSlices(i8, &[_]i8{ 0, -1, 2 }, &arr);
}

test "several integer bases" {
const source =
\\- 10
\\- -10
\\- 0x10
\\- -0X10
\\- 0o10
\\- -0O10
;

var yaml = try Yaml.load(testing.allocator, source);
defer yaml.deinit();

try testing.expectEqual(yaml.docs.items.len, 1);

const arr = try yaml.parse([6]i8);
try testing.expectEqualSlices(i8, &[_]i8{ 10, -10, 16, -16, 8, -8 }, &arr);
}

test "simple map untyped" {
const source =
\\a: 0
Expand Down

0 comments on commit 9308a64

Please sign in to comment.