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

@@ -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)
}