mirror of
https://github.com/ziglang/zig.git
synced 2024-11-21 11:32:24 +00:00
Merge 90df6f62a1
into f845fa04a0
This commit is contained in:
commit
40c890ed12
@ -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