Skip to content

Commit

Permalink
tree: Expose testSimpleTrees (#22729)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
CraigMacomber authored Oct 4, 2024
1 parent 964e3ef commit 842aa45
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions packages/dds/tree/src/test/testTrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TSchema>
*/
readonly root: InsertableTreeFieldFromImplicitField;
}

interface TestTree {
readonly name: string;
readonly schemaData: TreeStoredSchema;
Expand All @@ -55,12 +64,16 @@ interface TestTree {
function testSimpleTree<TSchema extends ImplicitFieldSchema>(
name: string,
schema: TSchema,
rootNode: InsertableTreeFieldFromImplicitField<TSchema>,
): TestTree {
const cursor = cursorFromInsertable(schema, rootNode);
root: InsertableTreeFieldFromImplicitField<TSchema>,
): 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)],
);
}
Expand Down Expand Up @@ -162,12 +175,37 @@ const library = {
]),
} satisfies Partial<TreeStoredSchema>;

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",
{
Expand Down Expand Up @@ -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",
{
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 842aa45

Please sign in to comment.