This commit is contained in:
Daniel Berg 2024-11-20 23:13:30 -05:00 committed by GitHub
commit 40c890ed12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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);

View File

@ -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" {