-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make serialized layer conversion work for version 1/0 and v2 layers
- Loading branch information
Showing
9 changed files
with
107 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
import { Layer } from "#asciiflow/client/layer"; | ||
import { layerToText } from "#asciiflow/client/text_utils"; | ||
import { Vector } from "#asciiflow/client/vector"; | ||
import { expect } from "chai"; | ||
import { describe, it } from "mocha"; | ||
|
||
describe("layer", () => { | ||
|
||
it("converts v1 to v2", () => { | ||
const v1Encoded = | ||
'{"x":987,"y":286,"text":" ┼ \\n┼┼┼┼┼┼┼┼┼┼┼┼\\n┼ ┼ Hi ┼\\n┼ ┼ ┼\\n┼ ┼┼┼┼┼┼►┼\\n┼ ┼\\n┼┼┼┼┼┼┼┼┼┼┼┼"}'; | ||
const decoded = Layer.deserialize(v1Encoded); | ||
const asText = layerToText(decoded); | ||
expect(asText).equals(` │ | ||
┌───┼──────┐ | ||
│ │ Hi │ | ||
│ │ │ | ||
│ └─────►│ | ||
│ │ | ||
└──────────┘`); | ||
}); | ||
|
||
it("serialize and deserialize v2", () => { | ||
const layer = new Layer(); | ||
// This should stay as is and not be processed. by the legacy render layer. | ||
layer.set(new Vector(5, 10), "++"); | ||
const encoded = Layer.serialize(layer); | ||
expect(JSON.parse(encoded).version).equals(2); | ||
const decoded = Layer.deserialize(encoded); | ||
const asText = layerToText(decoded); | ||
expect(asText).equals(`++`); | ||
}); | ||
}); |
This file contains 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 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 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 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 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 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
File renamed without changes.
This file contains 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