mirror of
https://github.com/ziglang/zig.git
synced 2024-11-24 21:30:14 +00:00
Compare commits
6 Commits
40c890ed12
...
dbddeec49b
Author | SHA1 | Date | |
---|---|---|---|
|
dbddeec49b | ||
|
90df6f62a1 | ||
|
84b7364b59 | ||
|
4e17b6b4e5 | ||
|
8cfb9239e7 | ||
|
a7792b4563 |
@ -230,7 +230,7 @@ pub fn innerParse(
|
||||
const token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
|
||||
defer freeAllocated(allocator, token);
|
||||
const slice = switch (token) {
|
||||
inline .number, .allocated_number, .string, .allocated_string => |slice| slice,
|
||||
inline .number, .allocated_number => |slice| slice,
|
||||
else => return error.UnexpectedToken,
|
||||
};
|
||||
return try std.fmt.parseFloat(T, slice);
|
||||
@ -239,7 +239,7 @@ pub fn innerParse(
|
||||
const token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
|
||||
defer freeAllocated(allocator, token);
|
||||
const slice = switch (token) {
|
||||
inline .number, .allocated_number, .string, .allocated_string => |slice| slice,
|
||||
inline .number, .allocated_number => |slice| slice,
|
||||
else => return error.UnexpectedToken,
|
||||
};
|
||||
return sliceToInt(T, slice);
|
||||
|
@ -384,8 +384,11 @@ test "parse" {
|
||||
try testing.expectEqual("foo".*, try parseFromSliceLeaky([3]u8, testing.allocator, "[102, 111, 111]", .{}));
|
||||
try testing.expectEqual(undefined, try parseFromSliceLeaky([0]u8, testing.allocator, "[]", .{}));
|
||||
|
||||
try testing.expectEqual(12345678901234567890, try parseFromSliceLeaky(u64, testing.allocator, "\"12345678901234567890\"", .{}));
|
||||
try testing.expectEqual(123.456, try parseFromSliceLeaky(f64, testing.allocator, "\"123.456\"", .{}));
|
||||
try testing.expectEqual("12345678901234567890".*, try parseFromSliceLeaky([20]u8, testing.allocator, "\"12345678901234567890\"", .{}));
|
||||
try testing.expectEqual(12345678901234567890, try parseFromSliceLeaky(u64, testing.allocator, "12345678901234567890", .{}));
|
||||
|
||||
try testing.expectEqual("123.456".*, try parseFromSliceLeaky([7]u8, testing.allocator, "\"123.456\"", .{}));
|
||||
try testing.expectEqual(123.456, try parseFromSliceLeaky(f64, testing.allocator, "123.456", .{}));
|
||||
}
|
||||
|
||||
test "parse into enum" {
|
||||
|
Loading…
Reference in New Issue
Block a user