More tests for grammar

This commit is contained in:
barsdeveloper
2023-04-09 18:25:46 +02:00
parent ce1f875f46
commit 2a7f208070
21 changed files with 174 additions and 95 deletions

View File

@@ -1,9 +1,9 @@
/// <reference types="cypress" />
import Configuration from "../../js/Configuration"
import Utility from "../../js/Utility"
import PinElement from "../../js/element/PinElement"
import LinearColorEntity from "../../js/entity/LinearColorEntity"
import Configuration from "../../js/Configuration.js"
import LinearColorEntity from "../../js/entity/LinearColorEntity.js"
import PinElement from "../../js/element/PinElement.js"
import Utility from "../../js/Utility.js"
/** @type {Blueprint} */
let blueprint

View File

@@ -1,9 +1,9 @@
/// <reference types="cypress" />
import Entity1 from "../fixtures/Entity1"
import Entity2 from "../fixtures/Entity2"
import Entity1 from "../fixtures/Entity1.js"
import Entity2 from "../fixtures/Entity2.js"
import entity2Value from "../fixtures/serializedEntity2.js"
import Entity3 from "../fixtures/Entity3"
import Entity3 from "../fixtures/Entity3.js"
import entity3Value from "../fixtures/serializedEntity3.js"
import Entity4 from "../fixtures/Entity4.js"
import entity4Value from "../fixtures/serializedEntity4.js"

View File

@@ -1,9 +1,9 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities"
import Blueprint from "../../js/Blueprint"
import Configuration from "../../js/Configuration"
import SVGIcon from "../../js/SVGIcon"
import { generateNodeTest } from "../fixtures/testUtilities.js"
import Blueprint from "../../js/Blueprint.js"
import Configuration from "../../js/Configuration.js"
import SVGIcon from "../../js/SVGIcon.js"
const tests = [
{

View File

@@ -1,8 +1,8 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities"
import Configuration from "../../js/Configuration"
import SVGIcon from "../../js/SVGIcon"
import { generateNodeTest } from "../fixtures/testUtilities.js"
import Configuration from "../../js/Configuration.js"
import SVGIcon from "../../js/SVGIcon.js"
const tests = [
{

View File

@@ -1,9 +1,9 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities"
import Blueprint from "../../js/Blueprint"
import Configuration from "../../js/Configuration"
import SVGIcon from "../../js/SVGIcon"
import { generateNodeTest } from "../fixtures/testUtilities.js"
import Blueprint from "../../js/Blueprint.js"
import Configuration from "../../js/Configuration.js"
import SVGIcon from "../../js/SVGIcon.js"
const tests = [
{

View File

@@ -1,8 +1,6 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities"
import Configuration from "../../js/Configuration"
import SVGIcon from "../../js/SVGIcon"
import { generateNodeTest } from "../fixtures/testUtilities.js"
const tests = [
{

View File

@@ -1,8 +1,8 @@
/// <reference types="cypress" />
import { generateNodeTest } from "../fixtures/testUtilities"
import Configuration from "../../js/Configuration"
import SVGIcon from "../../js/SVGIcon"
import { generateNodeTest } from "../fixtures/testUtilities.js"
import Configuration from "../../js/Configuration.js"
import SVGIcon from "../../js/SVGIcon.js"
const tests = [
{

View File

@@ -1,14 +1,19 @@
/// <reference types="cypress" />
import GuidEntity from "../../js/entity/GuidEntity"
import initializeSerializerFactory from "../../js/serialization/initializeSerializerFactory"
import IntegerEntity from "../../js/entity/IntegerEntity"
import KeyBindingEntity from "../../js/entity/KeyBindingEntity"
import LinearColorEntity from "../../js/entity/LinearColorEntity"
import SerializerFactory from "../../js/serialization/SerializerFactory"
import Utility from "../../js/Utility"
import Vector2DEntity from "../../js/entity/Vector2DEntity"
import VectorEntity from "../../js/entity/VectorEntity"
import Grammar from "../../js/serialization/Grammar.js"
import GuidEntity from "../../js/entity/GuidEntity.js"
import initializeSerializerFactory from "../../js/serialization/initializeSerializerFactory.js"
import IntegerEntity from "../../js/entity/IntegerEntity.js"
import KeyBindingEntity from "../../js/entity/KeyBindingEntity.js"
import LinearColorEntity from "../../js/entity/LinearColorEntity.js"
import ObjectReferenceEntity from "../../js/entity/ObjectReferenceEntity.js"
import RotatorEntity from "../../js/entity/RotatorEntity.js"
import SerializerFactory from "../../js/serialization/SerializerFactory.js"
import SymbolEntity from "../../js/entity/SymbolEntity.js"
import UnknownKeysEntity from "../../js/entity/UnknownKeysEntity.js"
import Utility from "../../js/Utility.js"
import Vector2DEntity from "../../js/entity/Vector2DEntity.js"
import VectorEntity from "../../js/entity/VectorEntity.js"
initializeSerializerFactory()
@@ -23,7 +28,7 @@ describe("Serializer", () => {
it("Parses False", () => expect(serializer.read("False")).to.be.false)
})
context("Integer", () => {
context("IntegerEntity", () => {
let serializer = SerializerFactory.getSerializer(IntegerEntity)
it("Parses 0", () => expect(serializer.read("0"))
@@ -80,7 +85,8 @@ describe("Serializer", () => {
expect(serializer.read('"hello world 123 - éèàò@ç ^ ^^^"'))
.to.be.equal("hello world 123 - éèàò@ç ^ ^^^")
)
it(String.raw`Parses "\""`, () => expect(serializer.read(String.raw`"\""`)).to.be.equal('"'))
it('Parses "\\""', () => expect(serializer.read('"\\""')).to.be.equal('"'))
it('Throws when not a string', () => expect(() => serializer.read("Hello")).to.throw())
})
context("KeyBindingEntity", () => {
@@ -109,7 +115,7 @@ describe("Serializer", () => {
)
})
context("Guid", () => {
context("GuidEntity", () => {
let serializer = SerializerFactory.getSerializer(GuidEntity)
it("Parses 0556a3ecabf648d0a5c07b2478e9dd32", () =>
@@ -141,7 +147,7 @@ describe("Serializer", () => {
)
})
context("Vector", () => {
context("VectorEntity", () => {
let serializer = SerializerFactory.getSerializer(VectorEntity)
it("Parses simple vector", () => expect(serializer.read("(X=1,Y=2,Z=3.5)"))
@@ -185,7 +191,7 @@ describe("Serializer", () => {
)
})
context("Vector2D", () => {
context("Vector2DEntity", () => {
let serializer = SerializerFactory.getSerializer(Vector2DEntity)
it("Parses simple vector", () => expect(serializer.read("(X=78,Y=56.3)"))
@@ -222,7 +228,7 @@ describe("Serializer", () => {
)
})
context("Linear color", () => {
context("LinearColorEntity", () => {
let serializer = SerializerFactory.getSerializer(LinearColorEntity)
it("check white color", () => {
@@ -271,4 +277,74 @@ describe("Serializer", () => {
.to.throw()
)
})
context("UnknownKeysValue", () => {
let parser = Grammar.unknownValue
it("Parses String", () => expect(parser.parse('"Hello"').value.constructor).equals(String))
it("Parses null", () => expect(parser.parse("()").value).to.be.null)
it("Parses Number", () => expect(parser.parse("8345").value.constructor).equals(Number))
it("Parses Boolean", () => expect(parser.parse("True").value.constructor).equals(Boolean))
it("Parses Boolean 2", () => expect(parser.parse("False").value.constructor).equals(Boolean))
it("Parses GuidEntity", () =>
expect(parser.parse("F0223D3742E67C0D9FEFB2A64946B7F0").value.constructor).equals(GuidEntity)
)
it("Parses SymbolEntity", () => expect(parser.parse("SYMBOL1").value.constructor).equals(SymbolEntity))
it("Parses SymbolEntity 2", () => expect(parser.parse("Symbol_2_3_4").value.constructor).equals(SymbolEntity))
it("Parses Vector2DEntity", () =>
expect(parser.parse("(X=-0.495, Y=0, )").value.constructor).equals(Vector2DEntity)
)
it("Parses VectorEntity", () =>
expect(parser.parse("(X=-0.495,Y=+765.0,Z=7)").value.constructor).equals(VectorEntity)
)
it("Parses RotatorEntity", () =>
expect(parser.parse("(R=1.000000,P=7.6,Y=+88.99)").value.constructor).equals(RotatorEntity)
)
it("Parses LinearColorEntity", () =>
expect(parser.parse("(R=0.000000,G=0.660000,B=1.000000,A=1.000000)").value.constructor)
.equals(LinearColorEntity)
)
it("Parses ObjectReferenceEntity", () =>
expect(parser.parse(`Class'"/Script/Engine.KismetSystemLibrary"'`).value.constructor)
.equals(ObjectReferenceEntity)
)
it("Parses Numbers array", () =>
expect(parser.parse("(1,2,3,4,5,6,7,8,9)").value).to.be.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
)
it("Parses Strings array", () =>
expect(parser.parse(`( "Hello", "World", )`).value).to.be.deep.equal(["Hello", "World"])
)
it("Parses Heterogeneous array", () =>
expect(parser.parse(`( "Alpha", 123, Beta, "Gamma", "Delta", 99 )`).value)
.to.be.deep.equal(["Alpha", 123, { value: "Beta" }, "Gamma", "Delta", 99])
)
})
context("UnknownKeysEntity", () => {
let serializer = SerializerFactory.getSerializer(UnknownKeysEntity)
it('Parses LookbehindValue(FirstKey=1,SecondKey=SOME_SYMBOL2,ThirdKey="Hello")', () =>
expect(serializer.read('LookbehindValue(FirstKey=1,SecondKey=SOME_SYMBOL2,ThirdKey="Hello")').equals(
new UnknownKeysEntity({
lookbehind: "LookbehindValue",
FirstKey: 1,
SecondKey: new SymbolEntity("SOME_SYMBOL2"),
ThirdKey: "Hello",
})
)).to.be.true
)
it('Parses (A = (-1,-2,-3), B = SomeFunction(B1 = "b1", B2 = (X=101,Y=102,Z=103)))', () =>
expect(serializer.read('(A = (-1,-2,-3), B = SomeFunction(B1 = "b1", B2 = (X=101,Y=102,Z=103)))').equals(
new UnknownKeysEntity({
lookbehind: "",
A: [-1, -2, -3],
B: new UnknownKeysEntity({
lookbehind: "SomeFunction",
B1: "b1",
B2: new VectorEntity({ X: 101, Y: 102, Z: 103 }),
}),
})
)).to.be.true
)
})
})

View File

@@ -1,7 +1,6 @@
/// <reference types="cypress" />
import IEntity from "../../js/entity/IEntity"
import Utility from "../../js/Utility"
import Utility from "../../js/Utility.js"
describe("Utility class", () => {
before(() => {

View File

@@ -1,5 +1,5 @@
import Entity1 from "./Entity1.js"
import IEntity from "../../js/entity/IEntity"
import IEntity from "../../js/entity/IEntity.js"
export default class Entity2 extends IEntity {

View File

@@ -1,7 +1,7 @@
import Entity1 from "./Entity1"
import Entity1 from "./Entity1.js"
import Entity2 from "./Entity2.js"
import IEntity from "../../js/entity/IEntity"
import UnionType from "../../js/entity/UnionType"
import IEntity from "../../js/entity/IEntity.js"
import UnionType from "../../js/entity/UnionType.js"
export default class Entity3 extends IEntity {

View File

@@ -13,14 +13,6 @@ export default class Entity4 extends IEntity {
default: [new Entity1({ a: 1, b: 2 }), new Entity1({ a: 11, b: 22 })],
inlined: true,
},
third: {
type: [{
type: Entity1,
inlined: true,
}],
default: [new Entity1({ a: -1, b: -2 })],
inlined: true,
}
}
static {

View File

@@ -1,27 +1,29 @@
export default `[[
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: Entity1(a=8, b=9)
papa: Entity1(a=12, b=13)
romeo.a: 8
romeo.b: 9
sierra.someNumber: 567
sierra.someString: "alpha"
sierra.someString2: "beta"
sierra.someBoolean: True
sierra.someBoolean2: False
sierra.someObjectString: "gamma"
sierra.someArray: (400,500,600,700,800,)
sierra.someEntity: Entity1(a=8, b=9)
]]`
export default `Begin
\${first.alpha} => 32
\${first.bravo} => 78
\${first.charlie} => "Charlie"
\${first.delta} => ()
\${first.echo} => "echo"
\${first.foxtrot} => False
\${first.golf} => ()
\${first.hotel} => ()
\${first.india} => ()
\${first.juliett} => ("a","b","c","d","e",)
\${first.kilo} => (True,False,False,True,True,)
\${first.mike} => "Bar"
\${first.november} => 0
\${first.oscar} => Entity1(a=8, b=9)
\${first.papa} => Entity1(a=12, b=13)
\${first.romeo.a} => 8
\${first.romeo.b} => 9
\${first.sierra.someNumber} => 567
\${first.sierra.someString} => "alpha"
\${first.sierra.someString2} => "beta"
\${first.sierra.someBoolean} => True
\${first.sierra.someBoolean2} => False
\${first.sierra.someObjectString} => "gamma"
\${first.sierra.someArray} => (400,500,600,700,800,)
\${first.sierra.someEntity} => Entity1(a=8, b=9)
\${second(0)} => Entity1(a=1, b=2)
\${second(1)} => Entity1(a=11, b=22)
End`

View File

@@ -1,7 +1,7 @@
/// <reference types="cypress" />
import Blueprint from "../../js/Blueprint"
import Utility from "../../js/Utility"
import Blueprint from "../../js/Blueprint.js"
import Utility from "../../js/Utility.js"
/** @param {String[]} words */
export function getFirstWordOrder(words) {

18
dist/ueblueprint.js vendored
View File

@@ -1016,7 +1016,7 @@ class IEntity {
if (defaultValue === undefined) {
defaultValue = Utility.sanitize(new /** @type {AnyValueConstructor<*>} */(defaultType)());
}
if (!attribute.showDefault) {
if (!attribute.showDefault && !attribute.ignored) {
assignAttribute(undefined); // Declare undefined to preserve the order of attributes
continue
}
@@ -1080,7 +1080,7 @@ class IEntity {
/** @param {IEntity} other */
equals(other) {
const thisKeys = Object.keys(this);
const otherKeys = Object.keys(this);
const otherKeys = Object.keys(other);
if (thisKeys.length != otherKeys.length) {
return false
}
@@ -1154,6 +1154,7 @@ class SymbolEntity extends IEntity {
this.cleanupAttributes(this.attributes);
}
/** @param {String | Object} values */
constructor(values) {
super(values);
/** @type {String} */ this.value;
@@ -3252,7 +3253,7 @@ class UnknownKeysEntity extends IEntity {
lookbehind: {
default: "",
showDefault: false,
ignore: true,
ignored: true,
},
}
@@ -3476,6 +3477,9 @@ class Grammar {
case SymbolEntity:
result = this.symbolEntity;
break
case UnknownKeysEntity:
result = this.unknownKeysEntity;
break
case UserDefinedPinEntity:
result = this.userDefinedPinEntity;
break
@@ -3797,17 +3801,19 @@ class Grammar {
this.null,
this.number,
this.string,
this.fullReferenceEntity,
this.localizedTextEntity,
this.invariantTextEntity,
this.formatTextEntity,
this.pinReferenceEntity,
this.vectorEntity,
this.rotatorEntity,
this.linearColorEntity,
this.vector2DEntity,
this.objectReferenceEntity,
this.unknownKeysEntity,
this.symbol,
this.symbolEntity,
this.grammarFor(undefined, [PinReferenceEntity]),
this.grammarFor(undefined, [new UnionType(Number, String, SymbolEntity)]),
)
)
@@ -4066,7 +4072,7 @@ class Serializer {
}
if (trailingSeparator && result.length) {
// append separator at the end if asked and there was printed content
result += this.attributeSeparator;
result += attributeSeparator;
}
return wrap(result, entity.constructor)
}

File diff suppressed because one or more lines are too long

View File

@@ -149,7 +149,7 @@ export default class IEntity {
if (defaultValue === undefined) {
defaultValue = Utility.sanitize(new /** @type {AnyValueConstructor<*>} */(defaultType)())
}
if (!attribute.showDefault) {
if (!attribute.showDefault && !attribute.ignored) {
assignAttribute(undefined) // Declare undefined to preserve the order of attributes
continue
}
@@ -213,7 +213,7 @@ export default class IEntity {
/** @param {IEntity} other */
equals(other) {
const thisKeys = Object.keys(this)
const otherKeys = Object.keys(this)
const otherKeys = Object.keys(other)
if (thisKeys.length != otherKeys.length) {
return false
}

View File

@@ -12,6 +12,7 @@ export default class SymbolEntity extends IEntity {
this.cleanupAttributes(this.attributes)
}
/** @param {String | Object} values */
constructor(values) {
super(values)
/** @type {String} */ this.value

View File

@@ -6,7 +6,7 @@ export default class UnknownKeysEntity extends IEntity {
lookbehind: {
default: "",
showDefault: false,
ignore: true,
ignored: true,
},
}

View File

@@ -245,6 +245,9 @@ export default class Grammar {
case SymbolEntity:
result = this.symbolEntity
break
case UnknownKeysEntity:
result = this.unknownKeysEntity
break
case UserDefinedPinEntity:
result = this.userDefinedPinEntity
break
@@ -566,17 +569,19 @@ export default class Grammar {
this.null,
this.number,
this.string,
this.fullReferenceEntity,
this.localizedTextEntity,
this.invariantTextEntity,
this.formatTextEntity,
this.pinReferenceEntity,
this.vectorEntity,
this.rotatorEntity,
this.linearColorEntity,
this.vector2DEntity,
this.objectReferenceEntity,
this.unknownKeysEntity,
this.symbol,
this.symbolEntity,
this.grammarFor(undefined, [PinReferenceEntity]),
this.grammarFor(undefined, [new UnionType(Number, String, SymbolEntity)]),
)
)

View File

@@ -115,7 +115,7 @@ export default class Serializer {
}
if (trailingSeparator && result.length) {
// append separator at the end if asked and there was printed content
result += this.attributeSeparator
result += attributeSeparator
}
return wrap(result, entity.constructor)
}