mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-06-11 13:13:13 +08:00
Entities tests fixed
This commit is contained in:
@@ -3,12 +3,11 @@ import NumberEntity from "../../js/entity/NumberEntity.js"
|
||||
|
||||
export default class Entity1 extends IEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static wrap = (entity, v) => `Entity1(${v})`
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
a: NumberEntity.withDefault(type => new type(8)),
|
||||
b: NumberEntity.withDefault(type => new type(9)),
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,12 @@ import Entity1 from "./Entity1.js"
|
||||
|
||||
export default class Entity2 extends IEntity {
|
||||
|
||||
static attributeSeparator = "\n"
|
||||
static keySeparator = ": "
|
||||
static printKey = k => ` ${k}`
|
||||
static wrap = (entity, v) => `{\n${v}\n}`
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
someNumber: NumberEntity.withDefault(type => new type(567)),
|
||||
someString: StringEntity.withDefault(type => new type("alpha")),
|
||||
someString2: StringEntity.withDefault(type => new type("beta")),
|
||||
@@ -22,12 +27,12 @@ export default class Entity2 extends IEntity {
|
||||
new NumberEntity(800),
|
||||
])),
|
||||
someArray2: ArrayEntity.of(NumberEntity).withDefault(type => new type([
|
||||
new NumberEntity(400),
|
||||
new NumberEntity(500),
|
||||
new NumberEntity(600),
|
||||
new NumberEntity(700),
|
||||
new NumberEntity(800),
|
||||
])).flagInlined(),
|
||||
new NumberEntity(-400),
|
||||
new NumberEntity(-500),
|
||||
new NumberEntity(-600),
|
||||
new NumberEntity(-700),
|
||||
new NumberEntity(-800),
|
||||
])),
|
||||
someEntity: Entity1.withDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import AlternativesEntity from "../../js/entity/AlternativesEntity.js"
|
||||
import ArrayEntity from "../../js/entity/ArrayEntity.js"
|
||||
import BooleanEntity from "../../js/entity/BooleanEntity.js"
|
||||
import IEntity from "../../js/entity/IEntity.js"
|
||||
import NullEntity from "../../js/entity/NullEntity.js"
|
||||
import NumberEntity from "../../js/entity/NumberEntity.js"
|
||||
import StringEntity from "../../js/entity/StringEntity.js"
|
||||
import Entity1 from "./Entity1.js"
|
||||
@@ -9,15 +10,20 @@ import Entity2 from "./Entity2.js"
|
||||
|
||||
export default class Entity3 extends IEntity {
|
||||
|
||||
static attributeSeparator = "\n"
|
||||
static keySeparator = ": "
|
||||
static printKey = k => ` ${k}`
|
||||
static wrap = (entity, v) => `[[\n${v}\n]]`
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
alpha: NumberEntity.withDefault(type => new type(32)),
|
||||
bravo: NumberEntity.withDefault(type => new type(78)),
|
||||
charlie: StringEntity.withDefault(type => new type("Charlie")),
|
||||
delta: StringEntity.withDefault(type => null),
|
||||
delta: StringEntity.withDefault(type => new NullEntity()),
|
||||
echo: StringEntity.withDefault(type => new type("echo")),
|
||||
foxtrot: BooleanEntity.withDefault(),
|
||||
golf: ArrayEntity.of(StringEntity).withDefault(),
|
||||
hotel: ArrayEntity.of(NumberEntity).withDefault(() => null),
|
||||
hotel: ArrayEntity.of(NumberEntity).withDefault(() => new NullEntity()),
|
||||
india: ArrayEntity.of(NumberEntity).withDefault(),
|
||||
juliett: ArrayEntity.of(StringEntity).withDefault(type => new type([
|
||||
new StringEntity("a"),
|
||||
@@ -34,11 +40,18 @@ export default class Entity3 extends IEntity {
|
||||
new BooleanEntity(true),
|
||||
])),
|
||||
lima: StringEntity,
|
||||
mike: AlternativesEntity.accepting(NumberEntity, StringEntity, ArrayEntity).withDefault(type => new StringEntity("Bar")),
|
||||
november: AlternativesEntity.accepting(NumberEntity, StringEntity, ArrayEntity).withDefault(type => new NumberEntity(0)),
|
||||
oscar: Entity1.withDefault(type => new type()),
|
||||
papa: Entity1.withDefault(type => new type({ a: 12, b: 13 })),
|
||||
quebec: NumberEntity.withDefault(), // will assign undefined because it does not satisfy the predicate,
|
||||
mike: AlternativesEntity
|
||||
.accepting(NumberEntity, StringEntity, ArrayEntity)
|
||||
.withDefault(type => new StringEntity("Bar")),
|
||||
november: AlternativesEntity
|
||||
.accepting(NumberEntity, StringEntity, ArrayEntity)
|
||||
.withDefault(type => new NumberEntity(0)),
|
||||
oscar: Entity1.withDefault(),
|
||||
papa: Entity1.withDefault(type => new type({
|
||||
a: new NumberEntity(12),
|
||||
b: new NumberEntity(13),
|
||||
})),
|
||||
quebec: NumberEntity,
|
||||
romeo: Entity1.withDefault().flagInlined(),
|
||||
sierra: Entity2.withDefault().flagInlined(),
|
||||
}
|
||||
|
||||
@@ -1,33 +1,23 @@
|
||||
import AttributeInfo from "../../js/entity/AttributeInfo.js"
|
||||
import ArrayEntity from "../../js/entity/ArrayEntity.js"
|
||||
import IEntity from "../../js/entity/IEntity.js"
|
||||
import NullEntity from "../../js/entity/NullEntity.js"
|
||||
import NumberEntity from "../../js/entity/NumberEntity.js"
|
||||
import Entity1 from "./Entity1.js"
|
||||
import Entity3 from "./Entity3.js"
|
||||
|
||||
export default class Entity4 extends IEntity {
|
||||
|
||||
static attributeSeparator = "\n"
|
||||
static keySeparator = " => "
|
||||
static printKey = k => ` \${${k}}`
|
||||
static wrap = (entity, v) => `Begin\n${v}\nEnd`
|
||||
static attributes = {
|
||||
first: new AttributeInfo({
|
||||
type: Entity3,
|
||||
default: new Entity3(),
|
||||
inlined: true,
|
||||
}),
|
||||
second: new AttributeInfo({
|
||||
default: [new Entity1({ a: 1, b: 2 }), new Entity1({ a: 11, b: 22 })],
|
||||
inlined: true,
|
||||
}),
|
||||
third: new AttributeInfo({
|
||||
type: Array,
|
||||
default: null,
|
||||
})
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
/** @type {Entity1} */ this.second
|
||||
IEntity.defineAttributes(this.second, {
|
||||
0: {
|
||||
inlined: true,
|
||||
},
|
||||
})
|
||||
...super.attributes,
|
||||
first: Entity3.withDefault().flagInlined(),
|
||||
second: ArrayEntity.of(Entity1).withDefault(type => new type([
|
||||
new (Entity1.flagInlined())({ a: new NumberEntity(1), b: new NumberEntity(2) }),
|
||||
new Entity1({ a: new NumberEntity(11), b: new NumberEntity(22) }),
|
||||
])).flagInlined(),
|
||||
third: ArrayEntity.withDefault(() => new NullEntity()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import AttributeInfo from "../../js/entity/AttributeInfo.js"
|
||||
import IntegerEntity from "../../js/entity/IntegerEntity.js"
|
||||
import ObjectEntity from "../../js/entity/ObjectEntity.js"
|
||||
import EntityF from "./EntityF.js"
|
||||
|
||||
// @ts-expect-error
|
||||
export default class Entity5 extends ObjectEntity {
|
||||
|
||||
static attributes = {
|
||||
key1: AttributeInfo.createType(String),
|
||||
key2: AttributeInfo.createType(EntityF),
|
||||
key3: new AttributeInfo({
|
||||
type: IntegerEntity,
|
||||
default: new IntegerEntity(5),
|
||||
silent: true,
|
||||
}),
|
||||
}
|
||||
static grammar = this.createGrammar()
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import IEntity from "../../js/entity/IEntity.js"
|
||||
import NumberEntity from "../../js/entity/NumberEntity.js"
|
||||
import StringEntity from "../../js/entity/StringEntity.js"
|
||||
import Grammar from "../../js/serialization/Grammar.js"
|
||||
|
||||
export default class EntityF extends IEntity {
|
||||
|
||||
static lookbehind = ["Foo", "Bar"]
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
arg1: NumberEntity,
|
||||
arg2: StringEntity,
|
||||
}
|
||||
static grammar = Grammar.createEntityGrammar(this)
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
}
|
||||
}
|
||||
12
tests/resources/serializedEntity2-1.js
Normal file
12
tests/resources/serializedEntity2-1.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export default `{
|
||||
someNumber: 567
|
||||
someString: "alpha"
|
||||
someString2: "beta"
|
||||
someBoolean: True
|
||||
someBoolean2: False
|
||||
someObjectString: "gamma"
|
||||
someArray: (400,500,600,700,800)
|
||||
someArray2: (-400,-500,-600,-700,-800)
|
||||
someEntity.a: 8
|
||||
someEntity.b: 9
|
||||
}`
|
||||
@@ -6,6 +6,6 @@ export default `{
|
||||
someBoolean2: False
|
||||
someObjectString: "gamma"
|
||||
someArray: (400,500,600,700,800)
|
||||
someArray2: (400,500,600,700,800)
|
||||
someArray2: (-400,-500,-600,-700,-800)
|
||||
someEntity: Entity1(a=8, b=9)
|
||||
}`
|
||||
|
||||
@@ -14,7 +14,6 @@ export default `[[
|
||||
november: 0
|
||||
oscar: Entity1(a=8, b=9)
|
||||
papa: Entity1(a=12, b=13)
|
||||
quebec: 6
|
||||
romeo.a: 8
|
||||
romeo.b: 9
|
||||
sierra.someNumber: 567
|
||||
@@ -24,6 +23,6 @@ export default `[[
|
||||
sierra.someBoolean2: False
|
||||
sierra.someObjectString: "gamma"
|
||||
sierra.someArray: (400,500,600,700,800)
|
||||
sierra.someArray2: (400,500,600,700,800)
|
||||
sierra.someArray2: (-400,-500,-600,-700,-800)
|
||||
sierra.someEntity: Entity1(a=8, b=9)
|
||||
]]`
|
||||
|
||||
@@ -23,7 +23,7 @@ export default `Begin
|
||||
\${first.sierra.someBoolean2} => False
|
||||
\${first.sierra.someObjectString} => "gamma"
|
||||
\${first.sierra.someArray} => (400,500,600,700,800)
|
||||
\${first.sierra.someArray2} => (400,500,600,700,800)
|
||||
\${first.sierra.someArray2} => (-400,-500,-600,-700,-800)
|
||||
\${first.sierra.someEntity} => E1[A:8 - B:9]
|
||||
\${second(0).a} => 1
|
||||
\${second(0).b} => 2
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export default `Begin Object
|
||||
key1="Value 1"
|
||||
key2=Foo(arg1=55,arg2="Argument 2")
|
||||
End Object
|
||||
`
|
||||
Reference in New Issue
Block a user