From 842aa456be2d4c2dc96c84baa3300b8c24744771 Mon Sep 17 00:00:00 2001 From: "Craig Macomber (Microsoft)" <42876482+CraigMacomber@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:24:04 -0700 Subject: [PATCH] tree: Expose testSimpleTrees (#22729) ## Description testTree did not expose any trees in a format suitable for testing with simple-tree: this has been fixed which should allow more cases to use the suite of test trees. --- packages/dds/tree/src/test/testTrees.ts | 72 +++++++++++++++---------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/packages/dds/tree/src/test/testTrees.ts b/packages/dds/tree/src/test/testTrees.ts index b7f6c1f9e8fe..b735607fb2fb 100644 --- a/packages/dds/tree/src/test/testTrees.ts +++ b/packages/dds/tree/src/test/testTrees.ts @@ -45,6 +45,15 @@ import { fieldJsonCursor } from "./json/jsonCursor.js"; import { brand } from "../util/index.js"; import type { Partial } from "@sinclair/typebox"; +interface TestSimpleTree { + readonly name: string; + readonly schema: ImplicitFieldSchema; + /** + * InsertableTreeFieldFromImplicitField + */ + readonly root: InsertableTreeFieldFromImplicitField; +} + interface TestTree { readonly name: string; readonly schemaData: TreeStoredSchema; @@ -55,12 +64,16 @@ interface TestTree { function testSimpleTree( name: string, schema: TSchema, - rootNode: InsertableTreeFieldFromImplicitField, -): TestTree { - const cursor = cursorFromInsertable(schema, rootNode); + root: InsertableTreeFieldFromImplicitField, +): TestSimpleTree { + return { name, schema, root }; +} + +function convertSimpleTreeTest(data: TestSimpleTree): TestTree { + const cursor = cursorFromInsertable(data.schema, data.root); return test( - name, - toStoredSchema(schema), + data.name, + toStoredSchema(data.schema), cursor === undefined ? [] : [jsonableTreeFromCursor(cursor)], ); } @@ -162,12 +175,37 @@ const library = { ]), } satisfies Partial; -export const testTrees: readonly TestTree[] = [ +export const testSimpleTrees: readonly TestSimpleTree[] = [ testSimpleTree("empty", factory.optional([]), undefined), testSimpleTree("null", factory.null, null), testSimpleTree("minimal", Minimal, {}), testSimpleTree("numeric", factory.number, 5), testSimpleTree("handle", factory.handle, new MockHandle(5)), + testSimpleTree("true boolean", factory.boolean, true), + testSimpleTree("false boolean", factory.boolean, false), + testSimpleTree("hasMinimalValueField", HasMinimalValueField, { field: {} }), + testSimpleTree("hasNumericValueField", HasNumericValueField, { field: 5 }), + testSimpleTree("hasPolymorphicValueField", HasPolymorphicValueField, { field: 5 }), + testSimpleTree("hasOptionalField-empty", HasOptionalField, {}), + testSimpleTree("numericMap-empty", NumericMap, {}), + testSimpleTree("numericMap-full", NumericMap, { a: 5, b: 6 }), + testSimpleTree("recursiveType-empty", RecursiveType, new RecursiveType({})), + testSimpleTree( + "recursiveType-recursive", + RecursiveType, + new RecursiveType({ field: new RecursiveType({}) }), + ), + testSimpleTree( + "recursiveType-deeper", + RecursiveType, + new RecursiveType({ + field: new RecursiveType({ field: new RecursiveType({ field: new RecursiveType({}) }) }), + }), + ), +]; + +export const testTrees: readonly TestTree[] = [ + ...testSimpleTrees.map(convertSimpleTreeTest), test( "numericSequence", { @@ -196,12 +234,7 @@ export const testTrees: readonly TestTree[] = [ }, policy: defaultSchemaPolicy, }, - testSimpleTree("true boolean", factory.boolean, true), - testSimpleTree("false boolean", factory.boolean, false), - testSimpleTree("hasMinimalValueField", HasMinimalValueField, { field: {} }), - testSimpleTree("hasNumericValueField", HasNumericValueField, { field: 5 }), - testSimpleTree("hasPolymorphicValueField", HasPolymorphicValueField, { field: 5 }), - testSimpleTree("hasOptionalField-empty", HasOptionalField, {}), + test( "allTheFields-minimal", { @@ -238,21 +271,6 @@ export const testTrees: readonly TestTree[] = [ }, ], ), - testSimpleTree("numericMap-empty", NumericMap, {}), - testSimpleTree("numericMap-full", NumericMap, { a: 5, b: 6 }), - testSimpleTree("recursiveType-empty", RecursiveType, new RecursiveType({})), - testSimpleTree( - "recursiveType-recursive", - RecursiveType, - new RecursiveType({ field: new RecursiveType({}) }), - ), - testSimpleTree( - "recursiveType-deeper", - RecursiveType, - new RecursiveType({ - field: new RecursiveType({ field: new RecursiveType({ field: new RecursiveType({}) }) }), - }), - ), ]; // TODO: integrate data sources for wide and deep trees from ops size testing and large data generators for cursor performance testing.