mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Serialization test
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import ComplexEntity from "../fixtures/ComplexEntity"
|
||||
import GeneralSerializer from "../../js/serialization/GeneralSerializer.js"
|
||||
import initializeSerializerFactory from "../../js/serialization/initializeSerializerFactory.js"
|
||||
import SerializerFactory from "../../js/serialization/SerializerFactory.js"
|
||||
import SimpleEntity from "../fixtures/SimpleEntity"
|
||||
import SimpleObject from "../fixtures/SimpleObject"
|
||||
|
||||
@@ -12,7 +15,22 @@ describe("Entity initialization", () => {
|
||||
|
||||
context("SimpleEntity", () => {
|
||||
const entity = new SimpleEntity()
|
||||
it("has 8 keys", () => expect(Object.keys(entity).length).to.equal(8))
|
||||
before(() => {
|
||||
initializeSerializerFactory()
|
||||
SerializerFactory.registerSerializer(
|
||||
SimpleEntity,
|
||||
new GeneralSerializer(
|
||||
v => `{\n${v}\n}`,
|
||||
SimpleEntity,
|
||||
" ",
|
||||
"\n",
|
||||
false,
|
||||
": ",
|
||||
undefined
|
||||
)
|
||||
)
|
||||
})
|
||||
it("has 7 keys", () => expect(Object.keys(entity).length).to.equal(7))
|
||||
it("has someNumber equal to 567", () => expect(entity)
|
||||
.to.have.property("someNumber")
|
||||
.which.is.a("number")
|
||||
@@ -78,6 +96,19 @@ describe("Entity initialization", () => {
|
||||
it("compares equal entities as equal", () => expect(other1.equals(other2))
|
||||
.to.be.true
|
||||
)
|
||||
it("can serialize", () => {
|
||||
expect(SerializerFactory.getSerializer(SimpleEntity).serialize(entity))
|
||||
.to.equal(`{
|
||||
someNumber: 567
|
||||
someString: "alpha"
|
||||
someString2: "beta"
|
||||
someBoolean: True
|
||||
someBoolean2: False
|
||||
someObjectString: "gamma"
|
||||
someArray: (400,500,600,700,800,)
|
||||
}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
context("ComplexEntity", () => {
|
||||
@@ -100,7 +131,35 @@ describe("Entity initialization", () => {
|
||||
"oscar",
|
||||
"papa",
|
||||
"quebec",
|
||||
"romeo",
|
||||
]
|
||||
before(() => {
|
||||
initializeSerializerFactory()
|
||||
SerializerFactory.registerSerializer(
|
||||
ComplexEntity,
|
||||
new GeneralSerializer(
|
||||
v => `[[\n${v}\n]]`,
|
||||
ComplexEntity,
|
||||
" ",
|
||||
"\n",
|
||||
false,
|
||||
": ",
|
||||
undefined
|
||||
)
|
||||
)
|
||||
SerializerFactory.registerSerializer(
|
||||
SimpleObject,
|
||||
new GeneralSerializer(
|
||||
v => `SimpleObject(${v})`,
|
||||
SimpleObject,
|
||||
"",
|
||||
", ",
|
||||
false,
|
||||
"=",
|
||||
undefined
|
||||
)
|
||||
)
|
||||
})
|
||||
it(`has ${keys.length} keys`, () => expect(Object.keys(entity).length).to.equal(keys.length))
|
||||
it("has specific keys names", () => expect(Object.keys(entity)).to.be.deep.equal(keys))
|
||||
it("has alpha equal to 32", () => expect(entity)
|
||||
@@ -203,5 +262,28 @@ describe("Entity initialization", () => {
|
||||
entity.quebec = 6
|
||||
expect(entity.quebec, "assigned 6").to.be.equal(6)
|
||||
})
|
||||
it("can serialize", () => {
|
||||
expect(SerializerFactory.getSerializer(ComplexEntity).serialize(entity))
|
||||
.to.equal(`[[
|
||||
alpha: 32
|
||||
bravo: 78
|
||||
charlie: "Charlie"
|
||||
delta: ()
|
||||
echo: "echo"
|
||||
foxtrot: False
|
||||
golf: ()
|
||||
hotel: ()
|
||||
india: ()
|
||||
juliett: ("a","b","c","d","e",)
|
||||
kilo: (True,False,False,True,True,)
|
||||
mike: "Bar"
|
||||
november: 0
|
||||
oscar: SimpleObject(a=8, b=9)
|
||||
papa: SimpleObject(a=12, b=13)
|
||||
romeo.a: 8
|
||||
romeo.b: 9
|
||||
]]`
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import IEntity from "../../js/entity/IEntity"
|
||||
import UnionType from "../../js/entity/UnionType"
|
||||
import Utility from "../../js/Utility"
|
||||
import SimpleObject from "./SimpleObject"
|
||||
import UnionType from "../../js/entity/UnionType"
|
||||
|
||||
export default class ComplexEntity extends IEntity {
|
||||
|
||||
@@ -61,12 +60,16 @@ export default class ComplexEntity extends IEntity {
|
||||
type: SimpleObject,
|
||||
},
|
||||
papa: {
|
||||
default: () => new SimpleObject(12, 13),
|
||||
default: () => new SimpleObject({ a: 12, b: 13 }),
|
||||
},
|
||||
quebec: {
|
||||
default: 0, // will assign undefined because it does not satisfy the predicate
|
||||
predicate: v => v >= 1 && v <= 10,
|
||||
},
|
||||
romeo: {
|
||||
type: SimpleObject,
|
||||
inline: true,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -24,9 +24,6 @@ export default class SimpleEntity extends IEntity {
|
||||
someArray: {
|
||||
default: [400, 500, 600, 700, 800],
|
||||
},
|
||||
someSet: {
|
||||
default: new Set([10, 20, 30, 40, 50, 60, 70]),
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
export default class SimpleObject {
|
||||
import IEntity from "../../js/entity/IEntity.js"
|
||||
|
||||
constructor(a = 8, b = 9) {
|
||||
this.a = a
|
||||
this.b = b
|
||||
export default class SimpleObject extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
a: {
|
||||
type: Number,
|
||||
},
|
||||
b: {
|
||||
type: Number,
|
||||
},
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
values.a ??= 8
|
||||
values.b ??= 9
|
||||
super(values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ export default class IEntity {
|
||||
ignored: false,
|
||||
serialized: false,
|
||||
expected: false,
|
||||
inline: false,
|
||||
}
|
||||
|
||||
constructor(values = {}, suppressWarns = false) {
|
||||
|
||||
79
js/entity/PinCategoryEntity.js
Executable file
79
js/entity/PinCategoryEntity.js
Executable file
@@ -0,0 +1,79 @@
|
||||
import FunctionReferenceEntity from "./FunctionReferenceEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity.js"
|
||||
import PathSymbolEntity from "./PathSymbolEntity.js"
|
||||
|
||||
export default class PinTypeEntity extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
PinCategory: {
|
||||
default: "",
|
||||
},
|
||||
PinSubCategory: {
|
||||
default: "",
|
||||
},
|
||||
PinSubCategoryObject: {
|
||||
type: ObjectReferenceEntity,
|
||||
},
|
||||
PinSubCategoryMemberReference: {
|
||||
type: FunctionReferenceEntity,
|
||||
default: null,
|
||||
},
|
||||
PinValueType: {
|
||||
type: PinTypeEntity,
|
||||
default: null,
|
||||
},
|
||||
ContainerType: {
|
||||
type: PathSymbolEntity,
|
||||
},
|
||||
bIsReference: {
|
||||
default: false,
|
||||
},
|
||||
bIsConst: {
|
||||
default: false,
|
||||
},
|
||||
bIsWeakPointer: {
|
||||
default: false,
|
||||
},
|
||||
bIsUObjectWrapper: {
|
||||
default: false,
|
||||
},
|
||||
bSerializeAsSinglePrecisionFloat: {
|
||||
default: false,
|
||||
},
|
||||
}
|
||||
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
|
||||
constructor(values = {}, suppressWarns = false) {
|
||||
super(values, suppressWarns)
|
||||
/** @type {String} */ this.PinCategory
|
||||
/** @type {String} */ this.PinSubCategory
|
||||
/** @type {ObjectReferenceEntity} */ this.PinSubCategoryObject
|
||||
/** @type {FunctionReferenceEntity} */ this.PinSubCategoryMemberReference
|
||||
/** @type {PinTypeEntity} */ this.PinValueType
|
||||
/** @type {PathSymbolEntity} */ this.ContainerType
|
||||
/** @type {Boolean} */ this.bIsReference
|
||||
/** @type {Boolean} */ this.bIsConst
|
||||
/** @type {Boolean} */ this.bIsWeakPointer
|
||||
/** @type {Boolean} */ this.bIsUObjectWrapper
|
||||
/** @type {Boolean} */ this.bIsUObjectWrapper
|
||||
}
|
||||
|
||||
/** @param {PinCategoryEntity} other */
|
||||
copyTypeFrom(other) {
|
||||
this.PinCategory = other.PinCategory
|
||||
this.PinSubCategory = other.PinSubCategory
|
||||
this.PinSubCategoryObject = other.PinSubCategoryObject
|
||||
this.PinSubCategoryMemberReference = other.PinSubCategoryMemberReference
|
||||
this.PinValueType = other.PinValueType
|
||||
this.ContainerType = other.ContainerType
|
||||
this.bIsReference = other.bIsReference
|
||||
this.bIsConst = other.bIsConst
|
||||
this.bIsWeakPointer = other.bIsWeakPointer
|
||||
this.bIsUObjectWrapper = other.bIsUObjectWrapper
|
||||
this.bSerializeAsSinglePrecisionFloat = other.bSerializeAsSinglePrecisionFloat
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user