Skip to content

Commit

Permalink
Merge pull request #1166 from microsoft/andrueastman/multiDimensionAr…
Browse files Browse the repository at this point in the history
…rays

Validates multidimensional collections scenarios using UntypedNode
  • Loading branch information
andrueastman authored May 6, 2024
2 parents 7782053 + ddfdfed commit d05233a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/serialization/json/test/common/JsonParseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ describe("JsonParseNode", () => {
},
},
},
table: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
};

const result = new JsonParseNode(jsonObject).getObjectValue(
Expand All @@ -237,5 +242,19 @@ describe("JsonParseNode", () => {
locationProperties["displayName"].getValue(),
"Microsoft Building 25",
);
const table = result.table as UntypedNode;
if (isUntypedArray(table)) {
table.getValue().forEach((row) => {
if (isUntypedArray(row)) {
row.getValue().forEach((cell) => {
assert.isTrue(isUntypedNumber(cell));
});
} else {
assert.fail("Expected row to be an array");
}
});
} else {
assert.fail("Expected table to be an array");
}
});
});
7 changes: 7 additions & 0 deletions packages/serialization/json/test/common/untypedTestEntiy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface UntypedTestEntity {
location?: UntypedNode | undefined;
keywords?: UntypedNode | undefined;
detail?: UntypedNode | undefined;
table?: UntypedNode | undefined;
additionalData?: Record<string, unknown>;
}

Expand Down Expand Up @@ -46,6 +47,11 @@ export function deserializeUntypedTestEntity(
createUntypedNodeFromDiscriminatorValue,
);
},
table: (n) => {
untypedTestEntity.table = n.getObjectValue<UntypedNode>(
createUntypedNodeFromDiscriminatorValue,
);
},
};
}

Expand All @@ -58,5 +64,6 @@ export function serializeUntypedTestEntity(
writer.writeObjectValue("location", untypedTestEntity.location);
writer.writeObjectValue("keywords", untypedTestEntity.keywords);
writer.writeObjectValue("detail", untypedTestEntity.detail);
writer.writeObjectValue("table", untypedTestEntity.table);
writer.writeAdditionalData(untypedTestEntity.additionalData);
}

0 comments on commit d05233a

Please sign in to comment.