Skip to content

Commit

Permalink
postmerge #158
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Oct 16, 2023
1 parent ff94b3c commit 00ab9e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colyseus/schema",
"version": "2.0.18",
"version": "2.0.19",
"description": "Binary state serializer with delta encoding for games",
"bin": {
"schema-codegen": "./bin/schema-codegen"
Expand Down
13 changes: 11 additions & 2 deletions test/ArraySchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,18 +563,27 @@ describe("ArraySchema Tests", () => {
sinon.assert.callCount(onRemoveSpy, 2);
});

it("should work with in operator", () => {
it("should support 'in' operator", () => {
const state = new State();
state.arrayOfPlayers = new ArraySchema<Player>();
state.arrayOfPlayers.push(new Player("One", 10, 0));
state.arrayOfPlayers.push(new Player("Two", 30, 0));
state.arrayOfPlayers.push(new Player("Three", 20, 0));

assert.ok(0 in state.arrayOfPlayers === true);
assert.ok(2 in state.arrayOfPlayers === true);
assert.ok(3 in state.arrayOfPlayers === false);
assert.ok(Symbol.iterator in state.arrayOfPlayers === true);
assert.ok("length" in state.arrayOfPlayers === true);

// decoded
const decodedState = Reflection.decode<State>(Reflection.encode(state));
decodedState.decode(state.encode());
assert.ok(0 in decodedState.arrayOfPlayers === true);
assert.ok(2 in decodedState.arrayOfPlayers === true);
assert.ok(3 in decodedState.arrayOfPlayers === false);
assert.ok(Symbol.iterator in decodedState.arrayOfPlayers === true);
assert.ok("length" in decodedState.arrayOfPlayers === true);
});

it("should allow sort", () => {
Expand Down
12 changes: 12 additions & 0 deletions test/Schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,18 @@ describe("Schema Usage", () => {


describe("deep structures / re-assignents", () => {
it("should allow to assign complex structures on constructor", () => {
const arrayOfPlayers = new ArraySchema<Player>();
arrayOfPlayers.push(new Player("One", 1, 1));
arrayOfPlayers.push(new Player("Two", 2, 2));

const state = new State({ arrayOfPlayers, });
const decodedState = new State();
decodedState.decode(state.encodeAll());

assert.strictEqual(2, decodedState.arrayOfPlayers.length);
});

it("should allow re-assigning child schema type", () => {
const state = new DeepState();
const deepMap = new DeepMap();
Expand Down

0 comments on commit 00ab9e8

Please sign in to comment.