Files
cocos4/tests/core/serialization/deserialize-capacity.test.ts
T
minggo 2e29bce9c3 Adjust serialization (#13201)
* move serialization related file into cocos/serialization
2022-11-01 17:10:12 +08:00

26 lines
813 B
TypeScript

import { ccclass } from '../../../cocos/core/data/decorators';
import { property } from '../../../cocos/core/data/decorators/property';
import { deserialize } from '../../../cocos/serialization/deserialize';
@ccclass('Foo')
class Foo { @property foo!: Foo | null; }
const EXPECTED_CAPACITY = 900;
test(`Deserialization capacity`, () => {
const fooSerialized = createVeryDeepFoo(EXPECTED_CAPACITY);
expect(() => deserialize(fooSerialized, undefined, undefined)).not.toThrow();
});
function createVeryDeepFoo (depth: number) {
const serializedDocument: Record<string, unknown>[] = [];
for (let i = 0; i < depth; ++i) {
serializedDocument.push({
__type__: 'Foo',
foo: i === depth - 1 ? null : { __id__: i + 1 },
});
}
return serializedDocument;
}