This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
fix: fix serialization of Point and Location types #854
Merged
mattjohnsonpint
merged 2 commits into
main
from
mjp/hyp-3404-serialization-bug-in-db-types
May 22, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
sdk/assemblyscript/src/assembly/__tests__/database.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2025 Hypermode Inc. | ||
| * Licensed under the terms of the Apache License, Version 2.0 | ||
| * See the LICENSE file that accompanied this code for further details. | ||
| * | ||
| * SPDX-FileCopyrightText: 2025 Hypermode Inc. <[email protected]> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { expect, it, run } from "as-test"; | ||
| import { JSON } from "json-as"; | ||
| import { Point, Location } from "../database"; | ||
|
|
||
| it("should serialize a Point object", () => { | ||
| const point = new Point(1, 2); | ||
| const json = JSON.stringify(point); | ||
| expect(json).toBe(`"(1.0,2.0)"`); | ||
| }); | ||
|
|
||
| it("should deserialize a Point object", () => { | ||
| const json = `"(1.0,2.0)"`; | ||
| const point = JSON.parse<Point>(json); | ||
| expect(point.x).toBe(1); | ||
| expect(point.y).toBe(2); | ||
| }); | ||
|
|
||
| it("should serialize a Location object", () => { | ||
| const location = new Location(1, 2); | ||
| const json = JSON.stringify(location); | ||
| expect(json).toBe(`"(1.0,2.0)"`); | ||
| }); | ||
|
|
||
| it("should deserialize a Location object", () => { | ||
| const json = `"(1.0,2.0)"`; | ||
| const location = JSON.parse<Location>(json); | ||
| expect(location.longitude).toBe(1); | ||
| expect(location.latitude).toBe(2); | ||
| }); | ||
|
|
||
| run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright 2025 Hypermode Inc. | ||
| * Licensed under the terms of the Apache License, Version 2.0 | ||
| * See the LICENSE file that accompanied this code for further details. | ||
| * | ||
| * SPDX-FileCopyrightText: 2025 Hypermode Inc. <[email protected]> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { readFileSync } from "fs"; | ||
| import { instantiate } from "../build/database.spec.js"; | ||
| const binary = readFileSync("./build/database.spec.wasm"); | ||
| const module = new WebAssembly.Module(binary); | ||
| instantiate(module, { | ||
| env: {}, | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.