add location set hash tests

This commit is contained in:
Muki Kiboigo
2025-11-03 07:01:50 -08:00
parent c009669ec8
commit 3cc53b579b
2 changed files with 11 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ pub const Location = struct {
current_url; current_url;
const normalized_hash = std.mem.trimStart(u8, hash, "#"); const normalized_hash = std.mem.trimStart(u8, hash, "#");
const new_url = try std.fmt.allocPrint(page.arena, "{s}#{s}", .{ base_without_hash, normalized_hash }); const new_url = try std.fmt.allocPrint(page.session.transfer_arena, "{s}#{s}", .{ base_without_hash, normalized_hash });
return page.navigateFromWebAPI(new_url, .{ .reason = .script }, .replace); return page.navigateFromWebAPI(new_url, .{ .reason = .script }, .replace);
} }

View File

@@ -13,3 +13,13 @@
testing.expectEqual("9582", location.port); testing.expectEqual("9582", location.port);
testing.expectEqual("", location.search); testing.expectEqual("", location.search);
</script> </script>
<script id=location_hash>
location.hash = "#abcdef";
testing.expectEqual("#abcdef", location.hash);
testing.expectEqual('http://localhost:9582/src/tests/html/location.html#abcdef', location.href);
location.hash = "xyzxyz";
testing.expectEqual("#xyzxyz", location.hash);
testing.expectEqual('http://localhost:9582/src/tests/html/location.html#xyzxyz', location.href);
</script>