mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-15 01:24:41 +08:00
Tests for various entity classes and update entity class implementations
This commit is contained in:
@@ -28,7 +28,9 @@ export default class AlternativesEntity extends IEntity {
|
||||
* @param {Types} types
|
||||
*/
|
||||
static accepting(...types) {
|
||||
const result = /** @type {typeof AlternativesEntity & { alternatives: Types }} */(this.asUniqueClass())
|
||||
const result = /** @type {typeof AlternativesEntity & { alternatives: Types }} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.alternatives = types
|
||||
result.grammar = result.createGrammar()
|
||||
return result
|
||||
|
||||
@@ -2,19 +2,20 @@ import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
/** @template {typeof IEntity} T */
|
||||
/** @template {IEntity} T */
|
||||
export default class ArrayEntity extends IEntity {
|
||||
|
||||
/** @type {typeof IEntity} */
|
||||
static type
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @param {ExtractType<T>[]} values */
|
||||
/** @param {T[]} values */
|
||||
constructor(values = []) {
|
||||
super()
|
||||
this.values = values
|
||||
}
|
||||
|
||||
/** @returns {P<ArrayEntity<IEntity>>} */
|
||||
static createGrammar(elementGrammar = this.type?.grammar ?? P.lazy(() => Grammar.unknownValue)) {
|
||||
return this.inlined
|
||||
? elementGrammar
|
||||
@@ -35,10 +36,10 @@ export default class ArrayEntity extends IEntity {
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @param {NonNullable<T>} type
|
||||
* @param {T} type
|
||||
*/
|
||||
static of(type) {
|
||||
const result = /** @type {typeof ArrayEntity<T> & { type: ExtractType<T>, grammar: P<ArrayEntity<T>> }} */(
|
||||
const result = /** @type {{type: T, grammar: P<ArrayEntity<ExtractType<T>>> } & typeof ArrayEntity<ExtractType<T>>} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.type = /** @type {ExtractType<T>} */(type)
|
||||
@@ -49,4 +50,16 @@ export default class ArrayEntity extends IEntity {
|
||||
valueOf() {
|
||||
return this.values
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
) {
|
||||
let result = this.values.map(v => v?.toString()).join(this.Self().attributeSeparator)
|
||||
if (this.Self().trailing) {
|
||||
result += this.Self().attributeSeparator
|
||||
}
|
||||
return `(${result})`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ export default class ByteEntity extends IntegerEntity {
|
||||
|
||||
static grammar = P.numberByte.map(v => new this(v))
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
}
|
||||
set value(value) {
|
||||
if (value % 1 == 0 && value >= 0 && value < 1 << 8) {
|
||||
super.value = value
|
||||
|
||||
@@ -6,6 +6,7 @@ import StringEntity from "./StringEntity.js"
|
||||
|
||||
export default class FormatTextEntity extends IPrintableEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static lookbehind = ["LOCGEN_FORMAT_NAMED", "LOCGEN_FORMAT_ORDERED"]
|
||||
/** @type {P<FormatTextEntity>} */
|
||||
static grammar = P.lazy(() => P.seq(
|
||||
@@ -53,4 +54,16 @@ export default class FormatTextEntity extends IPrintableEntity {
|
||||
: ""
|
||||
return result
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
) {
|
||||
const separator = this.Self().attributeSeparator
|
||||
return this.lookbehind + "("
|
||||
+ this.values.map(v => v.toString(insideString)).join(separator)
|
||||
+ (this.Self().trailing ? separator : "")
|
||||
+ ")"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export default class IEntity {
|
||||
static wrap = this.defaultWrapped
|
||||
|
||||
static attributeSeparator = ","
|
||||
static keySeparator = "="
|
||||
|
||||
/** @type {(k: String) => String} */
|
||||
static printKey = k => k
|
||||
@@ -103,7 +104,6 @@ export default class IEntity {
|
||||
*/
|
||||
static asUniqueClass() {
|
||||
if (this.name.length) {
|
||||
// @ts-expect-error
|
||||
return class extends this { }
|
||||
}
|
||||
return this
|
||||
@@ -281,9 +281,9 @@ export default class IEntity {
|
||||
if (Self.quoted) {
|
||||
keyValue = `"${keyValue}"`
|
||||
}
|
||||
result += Self.attributeSeparator.includes("\n") ? indentation : ""
|
||||
result += (Self.attributeSeparator.includes("\n") ? indentation : "") + keyValue + Self.keySeparator
|
||||
}
|
||||
let serialization = value.toString(insideString, indentation, printKey)
|
||||
let serialization = value?.toString(insideString, indentation, printKey)
|
||||
if (Self.serialized) {
|
||||
serialization = `"${serialization.replaceAll(/(?<=(?:[^\\]|^)(?:\\\\)*?)"/, '\\"')}"`
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@ export default class IntegerEntity extends NumberEntity {
|
||||
|
||||
static grammar = P.numberInteger.map(v => new this(v))
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
}
|
||||
set value(value) {
|
||||
if (value >= -(1 << 31) && value < 1 << 31) {
|
||||
if (value >= 1 << 31 && value < -(1 << 31)) {
|
||||
value = Math.floor(value)
|
||||
super.value = value
|
||||
}
|
||||
|
||||
@@ -2,64 +2,44 @@ import P from "parsernostrum"
|
||||
import Utility from "../Utility.js"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IPrintableEntity from "./IPrintableEntity.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
|
||||
export default class LocalizedTextEntity extends IPrintableEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static printKey = k => ""
|
||||
static lookbehind = "NSLOCTEXT"
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
namespace: StringEntity.withDefault(),
|
||||
key: StringEntity.withDefault(),
|
||||
value: StringEntity.withDefault(),
|
||||
}
|
||||
static grammar = P.regArray(new RegExp(
|
||||
String.raw`${this.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(,\s+)?`
|
||||
String.raw`${LocalizedTextEntity.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(?<namespace>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<key>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<value>${Grammar.Regex.InsideString.source})"\s*`
|
||||
+ String.raw`(?<trailing>,\s+)?`
|
||||
+ String.raw`\)`,
|
||||
"m"
|
||||
)).map(matchResult => {
|
||||
const self = matchResult[4] ? this.flagTrailing() : this
|
||||
return new self(
|
||||
Utility.unescapeString(matchResult[1]),
|
||||
Utility.unescapeString(matchResult[2]),
|
||||
Utility.unescapeString(matchResult[3]),
|
||||
)
|
||||
)).map(({ groups: { namespace, key, value, trailing } }) => {
|
||||
const self = trailing ? this.flagTrailing() : this
|
||||
return new self({
|
||||
namespace: new (this.attributes.namespace)(Utility.unescapeString(namespace)),
|
||||
key: new (this.attributes.namespace)(Utility.unescapeString(key)),
|
||||
value: new (this.attributes.namespace)(Utility.unescapeString(value)),
|
||||
})
|
||||
}).label("LocalizedTextEntity")
|
||||
|
||||
#namespace
|
||||
get namespace() {
|
||||
return this.#namespace
|
||||
}
|
||||
set namespace(value) {
|
||||
this.#namespace = value
|
||||
}
|
||||
|
||||
#key
|
||||
get key() {
|
||||
return this.#key
|
||||
}
|
||||
set key(value) {
|
||||
this.#key = value
|
||||
}
|
||||
|
||||
#value
|
||||
get value() {
|
||||
return this.#value
|
||||
}
|
||||
set value(value) {
|
||||
this.#value = value
|
||||
}
|
||||
|
||||
constructor(namespace = "", key = "", value = "") {
|
||||
super()
|
||||
this.namespace = namespace
|
||||
this.key = key
|
||||
this.value = value
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.namespace>} */ this.namespace
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.key>} */ this.key
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.value>} */ this.value
|
||||
}
|
||||
|
||||
print() {
|
||||
return Utility.capitalFirstLetter(this.value)
|
||||
}
|
||||
|
||||
toString() {
|
||||
const trailer = this.Self().trailing ? ", " : ""
|
||||
return `${this.lookbehind}(${this.namespace}, ${this.key}, ${this.value}${trailer})`
|
||||
return Utility.capitalFirstLetter(this.value.valueOf())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ export default class NaturalNumberEntity extends IntegerEntity {
|
||||
|
||||
static grammar = P.numberNatural.map(v => new this(v))
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
}
|
||||
set value(value) {
|
||||
value = Math.round(Utility.clamp(this.value, 0))
|
||||
super.value = value
|
||||
}
|
||||
|
||||
constructor(value = 0) {
|
||||
super(value)
|
||||
}
|
||||
}
|
||||
|
||||
16
js/entity/NullEntity.js
Normal file
16
js/entity/NullEntity.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import P from "parsernostrum"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class NullEntity extends IEntity {
|
||||
|
||||
static grammar = P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`))
|
||||
.map(v => new this())
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
printKey = this.Self().printKey,
|
||||
) {
|
||||
return "()"
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import NumberEntity from "../entity/NumberEntity.js"
|
||||
import StringEntity from "../entity/StringEntity.js"
|
||||
import ArrayEntity from "../entity/ArrayEntity.js"
|
||||
import AlternativesEntity from "../entity/AlternativesEntity.js"
|
||||
import NullEntity from "../entity/NullEntity.js"
|
||||
|
||||
export default function initializeSerializerFactory() {
|
||||
|
||||
@@ -56,7 +57,7 @@ export default function initializeSerializerFactory() {
|
||||
BooleanEntity.grammar,
|
||||
GuidEntity.grammar,
|
||||
Parsernostrum.str("None").map(() => ObjectReferenceEntity.createNoneInstance()),
|
||||
Grammar.null,
|
||||
NullEntity.grammar,
|
||||
NumberEntity.grammar,
|
||||
ObjectReferenceEntity.fullReferenceGrammar,
|
||||
StringEntity.grammar,
|
||||
|
||||
@@ -22,193 +22,262 @@ import VectorEntity from "../js/entity/VectorEntity.js"
|
||||
import Grammar from "../js/serialization/Grammar.js"
|
||||
import SerializerFactory from "../js/serialization/SerializerFactory.js"
|
||||
import initializeSerializerFactory from "../js/serialization/initializeSerializerFactory.js"
|
||||
import NaturalNumberEntity from "../js/entity/NaturalNumberEntity.js"
|
||||
import NullEntity from "../js/entity/NullEntity.js"
|
||||
import AlternativesEntity from "../js/entity/AlternativesEntity.js"
|
||||
|
||||
test.beforeAll(() => initializeSerializerFactory())
|
||||
|
||||
test.describe.configure({ mode: "parallel" })
|
||||
|
||||
test("ArrayEntity", () => {
|
||||
let grammar = ArrayEntity.grammar
|
||||
|
||||
expect(grammar.parse("()")).toEqual(new ArrayEntity([]))
|
||||
expect(grammar.parse("( )")).toEqual(new ArrayEntity([]))
|
||||
expect(grammar.parse("(1, 2, 3, 4, 5, 6)")).toEqual(new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new NumberEntity(2),
|
||||
new NumberEntity(3),
|
||||
new NumberEntity(4),
|
||||
new NumberEntity(5),
|
||||
new NumberEntity(6),
|
||||
]))
|
||||
expect(ArrayEntity.of(NumberEntity).grammar.parse("(2,4,6,8)")).toEqual(new ArrayEntity([
|
||||
new NumberEntity(2),
|
||||
new NumberEntity(4),
|
||||
new NumberEntity(6),
|
||||
new NumberEntity(8),
|
||||
]))
|
||||
expect(ArrayEntity.of(IntegerEntity).grammar.parse("(-0, -1, -2)")).toEqual(new ArrayEntity([
|
||||
new IntegerEntity(0),
|
||||
new IntegerEntity(-1),
|
||||
new IntegerEntity(-2),
|
||||
]))
|
||||
expect(() => ArrayEntity.of(IntegerEntity).grammar.parse("(-1, -2.1, -3)")).toThrowError()
|
||||
expect(grammar.parse(`(
|
||||
"alpha",
|
||||
"beta",
|
||||
123,
|
||||
3BEF2168446CAA32D5B54289FAB2F0BA,
|
||||
Some(a=1, b="2")
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new StringEntity("alpha"),
|
||||
new StringEntity("beta"),
|
||||
new NumberEntity(123),
|
||||
new GuidEntity("3BEF2168446CAA32D5B54289FAB2F0BA"),
|
||||
new (UnknownKeysEntity.withLookbehind("Some"))({
|
||||
a: new NumberEntity(1),
|
||||
b: new StringEntity("2"),
|
||||
})
|
||||
]))
|
||||
expect(grammar.parse(`(
|
||||
A(first = (9,8,7,6,5), second = 00000000000000000000000000000000),
|
||||
B(key="hello"),
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: new StringEntity("A"),
|
||||
first: new ArrayEntity([
|
||||
new NumberEntity(9),
|
||||
new NumberEntity(8),
|
||||
new NumberEntity(7),
|
||||
new NumberEntity(6),
|
||||
new NumberEntity(5),
|
||||
{
|
||||
const grammar = ArrayEntity.grammar
|
||||
let value = grammar.parse("()")
|
||||
expect(value).toEqual(new ArrayEntity([]))
|
||||
value = grammar.parse("( )")
|
||||
expect(value.toString()).toEqual("()")
|
||||
expect(value).toEqual(new ArrayEntity([]))
|
||||
value = grammar.parse("(1, 2, 3, 4, 5, 6)")
|
||||
expect(value.toString()).toEqual("(1,2,3,4,5,6)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new NumberEntity(2),
|
||||
new NumberEntity(3),
|
||||
new NumberEntity(4),
|
||||
new NumberEntity(5),
|
||||
new NumberEntity(6),
|
||||
]))
|
||||
expect(value.Self().className()).toEqual("ArrayEntity")
|
||||
value.values.map(v => v.Self().className()).forEach(v => expect(v).toEqual("NumberEntity"))
|
||||
value = grammar.parse("(1, 2, )")
|
||||
expect(value.toString()).toEqual("(1,2,)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new NumberEntity(2),
|
||||
]))
|
||||
}
|
||||
{
|
||||
const grammar = ArrayEntity.of(NumberEntity).grammar
|
||||
let value = grammar.parse("(2,4,6,8)")
|
||||
expect(value.toString()).toEqual("(2,4,6,8)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new NumberEntity(2),
|
||||
new NumberEntity(4),
|
||||
new NumberEntity(6),
|
||||
new NumberEntity(8),
|
||||
]))
|
||||
}
|
||||
{
|
||||
const grammar = ArrayEntity.of(IntegerEntity).grammar
|
||||
let value = grammar.parse("(-0, -1, -2)")
|
||||
expect(value.toString()).toEqual("(0,-1,-2)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new IntegerEntity(0),
|
||||
new IntegerEntity(-1),
|
||||
new IntegerEntity(-2),
|
||||
]))
|
||||
value.values.map(v => v.Self().className()).forEach(v => expect(v).toEqual("IntegerEntity"))
|
||||
value = grammar.parse("(-0, -1, -2,)")
|
||||
expect(value.toString()).toEqual("(0,-1,-2,)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new IntegerEntity(0),
|
||||
new IntegerEntity(-1),
|
||||
new IntegerEntity(-2),
|
||||
]))
|
||||
expect(() => grammar.parse("(-1, -2.1, -3)")).toThrowError()
|
||||
}
|
||||
{
|
||||
const grammar = ArrayEntity.grammar
|
||||
let value = grammar.parse(`(
|
||||
"alpha",
|
||||
"beta",
|
||||
123,
|
||||
3BEF2168446CAA32D5B54289FAB2F0BA,
|
||||
Some(a=1, b="number:\\"2\\"")
|
||||
)`)
|
||||
expect(value.toString()).toEqual('("alpha","beta",123,3BEF2168446CAA32D5B54289FAB2F0BA,Some(a=1,b="number:\\"2\\""))')
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new StringEntity("alpha"),
|
||||
new StringEntity("beta"),
|
||||
new NumberEntity(123),
|
||||
new GuidEntity("3BEF2168446CAA32D5B54289FAB2F0BA"),
|
||||
new (UnknownKeysEntity.withLookbehind("Some"))({
|
||||
a: new NumberEntity(1),
|
||||
b: new StringEntity('number:"2"'),
|
||||
})
|
||||
]))
|
||||
expect(value.values.map(v => v.Self().className())).toEqual([
|
||||
"StringEntity",
|
||||
"StringEntity",
|
||||
"NumberEntity",
|
||||
"GuidEntity",
|
||||
"UnknownKeysEntity",
|
||||
])
|
||||
value = grammar.parse(`(
|
||||
A(first = (9,8,7,6,5), second = 00000000000000000000000000000000),
|
||||
B(key="hello"),
|
||||
)`)
|
||||
expect(value.toString()).toEqual('(A(first=(9,8,7,6,5),second=00000000000000000000000000000000),B(key="hello"),)')
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: new StringEntity("A"),
|
||||
first: new ArrayEntity([
|
||||
new NumberEntity(9),
|
||||
new NumberEntity(8),
|
||||
new NumberEntity(7),
|
||||
new NumberEntity(6),
|
||||
new NumberEntity(5),
|
||||
]),
|
||||
second: new GuidEntity("00000000000000000000000000000000"),
|
||||
}),
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: new StringEntity("B"),
|
||||
key: new StringEntity("hello"),
|
||||
})
|
||||
]))
|
||||
}
|
||||
{
|
||||
// Nested
|
||||
let value = ArrayEntity.of(AlternativesEntity.accepting(
|
||||
IntegerEntity,
|
||||
ArrayEntity.of(IntegerEntity)
|
||||
)).grammar.parse("((1, 2), (3, 4), 5)")
|
||||
expect(value.toString()).toEqual("((1,2),(3,4),5)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([new IntegerEntity(1), new IntegerEntity(2)]),
|
||||
new ArrayEntity([new IntegerEntity(3), new IntegerEntity(4)]),
|
||||
new IntegerEntity(5),
|
||||
]))
|
||||
}
|
||||
{
|
||||
const grammar = ArrayEntity.grammar
|
||||
let value = grammar.parse('(((1, "2"), (3, 4)), "5")')
|
||||
expect(value.toString()).toEqual('(((1,"2"),(3,4)),"5")')
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([
|
||||
new ArrayEntity([new NumberEntity(1), new StringEntity("2")]),
|
||||
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)])
|
||||
]),
|
||||
second: new GuidEntity("00000000000000000000000000000000"),
|
||||
}),
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: new StringEntity("B"),
|
||||
key: new StringEntity("hello"),
|
||||
})
|
||||
]))
|
||||
|
||||
// Nested
|
||||
expect(grammar.parse("((1, 2), (3, 4))")).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
|
||||
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)]),
|
||||
]))
|
||||
expect(grammar.parse('(((1, 2), (3, 4)), 5)')).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([
|
||||
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
|
||||
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)])
|
||||
]),
|
||||
new NumberEntity(5)
|
||||
]))
|
||||
expect(grammar.parse(`(
|
||||
One(a = (1,(2,(3,(4)))), b = ()),
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: "One",
|
||||
a: new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(2),
|
||||
new StringEntity("5")
|
||||
]))
|
||||
}
|
||||
{
|
||||
let value = ArrayEntity.grammar.parse(`(
|
||||
One(a = (1,(2,(3,(4)))), b = ()),
|
||||
)`)
|
||||
expect(value.toString()).toEqual("(One(a=(1,(2,(3,(4)))),b=()),)")
|
||||
expect(value).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: "One",
|
||||
a: new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(3),
|
||||
new NumberEntity(2),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(4),
|
||||
new NumberEntity(3),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(4),
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
b: null,
|
||||
}),
|
||||
]))
|
||||
]),
|
||||
b: new NullEntity(),
|
||||
}),
|
||||
]))
|
||||
}
|
||||
})
|
||||
|
||||
test("Boolean", () => {
|
||||
let grammar = BooleanEntity.grammar
|
||||
expect(grammar.parse("true")).toEqual(new BooleanEntity(true))
|
||||
expect(grammar.parse("True")).toEqual(new BooleanEntity(true))
|
||||
expect(grammar.parse("false")).toEqual(new BooleanEntity(false))
|
||||
expect(grammar.parse("False")).toEqual(new BooleanEntity(false))
|
||||
let value = grammar.parse("true")
|
||||
expect(value).toEqual(new BooleanEntity(true))
|
||||
expect(value).toBeInstanceOf(BooleanEntity)
|
||||
expect(value.toString()).toEqual("True")
|
||||
value = grammar.parse("True")
|
||||
expect(value).toEqual(new BooleanEntity(true))
|
||||
expect(value.toString()).toEqual("True")
|
||||
value = grammar.parse("false")
|
||||
expect(value).toEqual(new BooleanEntity(false))
|
||||
expect(value.toString()).toEqual("False")
|
||||
value = grammar.parse("False")
|
||||
expect(value).toEqual(new BooleanEntity(false))
|
||||
expect(value.toString()).toEqual("False")
|
||||
})
|
||||
|
||||
test("FormatTextEntity", () => {
|
||||
let grammar = FormatTextEntity.grammar
|
||||
expect(
|
||||
grammar.parse(`LOCGEN_FORMAT_NAMED(NSLOCTEXT("KismetSchema", "SplitPinFriendlyNameFormat", "{PinDisplayName} {ProtoPinDisplayName}"), "PinDisplayName", "Out Hit", "ProtoPinDisplayName", "Blocking Hit")`)
|
||||
.print()
|
||||
).toBe("Out Hit Blocking Hit")
|
||||
expect(
|
||||
grammar.parse(`LOCGEN_FORMAT_NAMED(NSLOCTEXT("KismetSchema", "SplitPinFriendlyNameFormat", "{PinDisplayName} {ProtoPinDisplayName}"), "PinDisplayName", "Out Hit", "ProtoPinDisplayName", "Hit Bone Name")`)
|
||||
.print()
|
||||
).toBe("Out Hit Hit Bone Name")
|
||||
expect(
|
||||
grammar.parse(String.raw`LOCGEN_FORMAT_ORDERED(
|
||||
NSLOCTEXT(
|
||||
"PCGSettings",
|
||||
"OverridableParamPinTooltip",
|
||||
"{0}Attribute type is \"{1}\" and its exact name is \"{2}\""
|
||||
),
|
||||
"If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\n",
|
||||
"float",
|
||||
"InRangeMin"
|
||||
)`)
|
||||
.print()
|
||||
|
||||
).toBe(`If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\nAttribute type is "float" and its exact name is "InRangeMin"`)
|
||||
let value = grammar.parse('LOCGEN_FORMAT_NAMED(NSLOCTEXT("KismetSchema", "SplitPinFriendlyNameFormat", "{PinDisplayName} {ProtoPinDisplayName}"), "PinDisplayName", "Out Hit", "ProtoPinDisplayName", "Blocking Hit")')
|
||||
expect(value.print()).toEqual("Out Hit Blocking Hit")
|
||||
expect(value.toString())
|
||||
.toEqual('LOCGEN_FORMAT_NAMED(NSLOCTEXT("KismetSchema", "SplitPinFriendlyNameFormat", "{PinDisplayName} {ProtoPinDisplayName}"), "PinDisplayName", "Out Hit", "ProtoPinDisplayName", "Blocking Hit")')
|
||||
|
||||
value = grammar.parse(String.raw`LOCGEN_FORMAT_ORDERED(
|
||||
NSLOCTEXT(
|
||||
"PCGSettings",
|
||||
"OverridableParamPinTooltip",
|
||||
"{0}Attribute type is \"{1}\" and its exact name is \"{2}\""
|
||||
),
|
||||
"If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\n",
|
||||
"float",
|
||||
"InRangeMin"
|
||||
)`)
|
||||
expect(value.print())
|
||||
.toEqual(`If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\nAttribute type is "float" and its exact name is "InRangeMin"`)
|
||||
expect(value.toString())
|
||||
.toEqual(String.raw`LOCGEN_FORMAT_ORDERED(NSLOCTEXT("PCGSettings", "OverridableParamPinTooltip", "{0}Attribute type is \"{1}\" and its exact name is \"{2}\""), "If InRangeMin = InRangeMax, then that density value is mapped to the average of OutRangeMin and OutRangeMax\n", "float", "InRangeMin")`)
|
||||
})
|
||||
|
||||
test("GuidEntity", () => {
|
||||
let serializer = SerializerFactory.getSerializer(GuidEntity)
|
||||
let grammar = GuidEntity.grammar
|
||||
|
||||
let guid = serializer.read("0556a3ecabf648d0a5c07b2478e9dd32")
|
||||
expect(guid).toBeInstanceOf(GuidEntity)
|
||||
expect(guid.value).toBe("0556a3ecabf648d0a5c07b2478e9dd32")
|
||||
let value = grammar.parse("0556a3ecabf648d0a5c07b2478e9dd32")
|
||||
expect(value).toBeInstanceOf(GuidEntity)
|
||||
expect(value).toEqual(new GuidEntity("0556a3ecabf648d0a5c07b2478e9dd32"))
|
||||
expect(value.toString()).toEqual("0556a3ecabf648d0a5c07b2478e9dd32")
|
||||
|
||||
guid = serializer.read("64023BC344E0453DBB583FAC411489BC")
|
||||
expect(guid).toBeInstanceOf(GuidEntity)
|
||||
expect(guid.value).toBe("64023BC344E0453DBB583FAC411489BC")
|
||||
value = grammar.parse("64023BC344E0453DBB583FAC411489BC")
|
||||
expect(value).toBeInstanceOf(GuidEntity)
|
||||
expect(value).toEqual(new GuidEntity("64023BC344E0453DBB583FAC411489BC"))
|
||||
expect(value.toString()).toEqual("64023BC344E0453DBB583FAC411489BC")
|
||||
|
||||
guid = serializer.read("6edC4a425ca948da8bC78bA52DED6C6C")
|
||||
expect(guid).toBeInstanceOf(GuidEntity)
|
||||
expect(guid.value).toBe("6edC4a425ca948da8bC78bA52DED6C6C")
|
||||
value = grammar.parse("6edC4a425ca948da8bC78bA52DED6C6C")
|
||||
expect(value).toBeInstanceOf(GuidEntity)
|
||||
expect(value).toEqual(new GuidEntity("6edC4a425ca948da8bC78bA52DED6C6C"))
|
||||
expect(value.toString()).toEqual("6edC4a425ca948da8bC78bA52DED6C6C")
|
||||
|
||||
expect(() => serializer.read("172087193 9B04362973544B3564FDB2C")).toThrow()
|
||||
expect(() => serializer.read("E25F14F8F3E9441AB07153E7DA2BA2B")).toThrow()
|
||||
expect(() => serializer.read("A78988B0097E48418C8CB87EC5A67ABF7")).toThrow()
|
||||
expect(() => grammar.parse("172087193 9B04362973544B3564FDB2C")).toThrow()
|
||||
expect(() => grammar.parse("E25F14F8F3E9441AB07153E7DA2BA2B")).toThrow()
|
||||
expect(() => grammar.parse("A78988B0097E48418C8CB87EC5A67ABF7")).toThrow()
|
||||
})
|
||||
|
||||
test("IntegerEntity", () => {
|
||||
let serializer = SerializerFactory.getSerializer(IntegerEntity)
|
||||
let grammar = IntegerEntity.grammar
|
||||
|
||||
let integer = serializer.read("0")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(0)
|
||||
let integer = grammar.parse("0")
|
||||
expect(integer).toEqual(new IntegerEntity(0))
|
||||
expect(integer).not.toEqual(new NaturalNumberEntity(0))
|
||||
|
||||
integer = serializer.read("+0")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(0)
|
||||
integer = grammar.parse("+0")
|
||||
expect(integer).toEqual(new IntegerEntity(0))
|
||||
|
||||
integer = serializer.read("-0")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(0)
|
||||
integer = grammar.parse("-0")
|
||||
expect(integer).toEqual(new IntegerEntity(0))
|
||||
|
||||
integer = serializer.read("99")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(99)
|
||||
integer = grammar.parse("99")
|
||||
expect(integer).toEqual(new IntegerEntity(99))
|
||||
|
||||
integer = serializer.read("-8685")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(-8685)
|
||||
integer = grammar.parse("-8685")
|
||||
expect(integer).toEqual(new IntegerEntity(-8685))
|
||||
|
||||
integer = serializer.read("+555")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(555)
|
||||
integer = grammar.parse("+555")
|
||||
expect(integer).toEqual(new IntegerEntity(555))
|
||||
|
||||
integer = serializer.read("1000000000")
|
||||
expect(integer).toBeInstanceOf(IntegerEntity)
|
||||
expect(integer.value).toStrictEqual(1000000000)
|
||||
integer = grammar.parse("1000000000")
|
||||
expect(integer).toEqual(new IntegerEntity(1000000000))
|
||||
|
||||
expect(() => serializer.read("1.2").value).toThrow()
|
||||
expect(() => grammar.parse("1.2").value).toThrow()
|
||||
})
|
||||
|
||||
test("KeyBindingEntity", () => {
|
||||
Reference in New Issue
Block a user