Skip to content

Commit

Permalink
Fix rename of table fields
Browse files Browse the repository at this point in the history
  • Loading branch information
waldo1001 committed Nov 28, 2023
1 parent 6082dc2 commit 13d822c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 35 deletions.
50 changes: 24 additions & 26 deletions src/NAVObject.ts
Expand Up @@ -311,16 +311,18 @@ export class NAVObject {
this.tableFields.push(new NAVTableField(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix], this._workSpaceSettings[Settings.MandatoryAffixes]))
}

var reg = NAVPageField.fieldRegEx();
var result;
while ((result = reg.exec(this.NAVObjectText)) !== null) {
this.pageFields.push(new NAVPageField(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
}
if ((this.objectType.toLocaleLowerCase().startsWith('page')) || (this.objectType.toLocaleLowerCase().startsWith('report'))) { //page-stuff should only be parsed for pages
var reg = NAVPageField.fieldRegEx();
var result;
while ((result = reg.exec(this.NAVObjectText)) !== null) {
this.pageFields.push(new NAVPageField(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
}

var reg = NAVPageGroup.fieldRegEx();
var result;
while ((result = reg.exec(this.NAVObjectText)) !== null) {
this.pageGroups.push(new NAVPageGroup(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
var reg = NAVPageGroup.fieldRegEx();
var result;
while ((result = reg.exec(this.NAVObjectText)) !== null) {
this.pageGroups.push(new NAVPageGroup(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
}
}

var reg = NAVReportColumn.columnRegEx();
Expand Down Expand Up @@ -576,17 +578,16 @@ class NAVTableField {
get nameFixed(): string {
if (!this._prefix && !this._suffix && !this.hasAffixesDefined()) { return this.name }
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

if (this.hasAffixesDefined()) {
var affixNeeded = true;
this._affixes.forEach(affix => {
if (this.name.startsWith(affix) || this.name.endsWith(affix))
{
if (this.name.startsWith(affix) || this.name.endsWith(affix)) {
affixNeeded = false;
return
}
});
if (!affixNeeded) {
if (!affixNeeded) {
return this.name;
}
}
Expand Down Expand Up @@ -625,11 +626,10 @@ class NAVTableField {
this.name = result[3].trim().toString();
this.type = result[4].trim().toString();
}
}

private hasAffixesDefined() : boolean
{
return (Array.isArray(this._affixes) && this._affixes.length > 0 )
}

private hasAffixesDefined(): boolean {
return (Array.isArray(this._affixes) && this._affixes.length > 0)
}
}

Expand All @@ -642,7 +642,7 @@ class NAVPageField {
private _suffix: string;

public static fieldRegEx(): RegExp {
return /.*(field\( *"?([ a-zA-Z0-9._/&%\/()-]+)"? *; *([" a-zA-Z0-9._/&%\/()-]+(\[([1-9]\d*)\])?) *\))/g;
return /.*(field\( *"?([ a-zA-Z0-9._/&%\/()-]+)"? *; *([" a-zA-Z0-9._/&%\/()-]+(\[([1-9]\d*)\])?) *\))/g;
}

get nameFixed(): string {
Expand Down Expand Up @@ -757,13 +757,12 @@ class NAVReportColumn {
if (this.hasAffixesDefined()) {
var affixNeeded = true;
this._affixes.forEach(affix => {
if (this.name.startsWith(affix) || this.name.endsWith(affix))
{
if (this.name.startsWith(affix) || this.name.endsWith(affix)) {
affixNeeded = false;
return
}
});
if (!affixNeeded) {
if (!affixNeeded) {
return this.name;
}
}
Expand Down Expand Up @@ -803,10 +802,9 @@ class NAVReportColumn {
this.expression = result[3].trim().toString();
}
}

private hasAffixesDefined() : boolean
{
return (Array.isArray(this._affixes) && this._affixes.length > 0 )

private hasAffixesDefined(): boolean {
return (Array.isArray(this._affixes) && this._affixes.length > 0)
}

}
Expand Down
27 changes: 18 additions & 9 deletions src/test/suite/NAVObject.PrefexAndSuffix.test.ts
Expand Up @@ -155,7 +155,7 @@ suite("NAVObject ObjectNamePrefix Tests", () => {

assert.strictEqual(navObject.tableFields[0].nameFixed, testSettings[Settings.ObjectNamePrefix] + navObject.tableFields[0].name)
assert.strictEqual(navObject.tableFields[0].nameFixed.startsWith(testSettings[Settings.ObjectNamePrefix]), true)
assert.strictEqual(navObject.tableFields.length, 5) //has 5 fields
assert.strictEqual(navObject.tableFields.length, 6) //has 6 fields
navObject.tableFields.forEach(field => {
assert.strictEqual(field.nameFixed.startsWith(testSettings[Settings.ObjectNamePrefix]), true)
})
Expand All @@ -166,6 +166,15 @@ suite("NAVObject ObjectNamePrefix Tests", () => {
assert.strictEqual(field.name.startsWith(testSettings[Settings.ObjectNamePrefix]), true)
})
});
test("Table - set prefix to fields with brackets", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getTableWithBracketsInFieldName();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

let FullFixedText = navObject.NAVObjectTextFixed
});
test("Tableextension - skip setting prefix to fields", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';
Expand Down Expand Up @@ -193,7 +202,7 @@ suite("NAVObject ObjectNamePrefix Tests", () => {

assert.strictEqual(navObject.tableFields[0].nameFixed, navObject.tableFields[0].name + testSettings[Settings.ObjectNameSuffix])
assert.strictEqual(navObject.tableFields[0].nameFixed.endsWith(testSettings[Settings.ObjectNameSuffix]), true)
assert.strictEqual(navObject.tableFields.length, 5) //has 5 fields
assert.strictEqual(navObject.tableFields.length, 6) //has 6 fields
navObject.tableFields.forEach(field => {
assert.strictEqual(field.nameFixed.endsWith(testSettings[Settings.ObjectNameSuffix]), true)
})
Expand All @@ -204,8 +213,8 @@ suite("NAVObject ObjectNamePrefix Tests", () => {
assert.strictEqual(field.name.endsWith(testSettings[Settings.ObjectNameSuffix]), true)
})
});


test("Tableextension - Don't set double Affix", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';
Expand Down Expand Up @@ -277,17 +286,17 @@ suite("NAVObject ObjectNamePrefix Tests", () => {

// Non integer-prefixed actions and fields are not contained in double-quotes
assert.strictEqual(navObject.objectActions.find(a => a.name === 'Action1')
.fullActionTextFixed, " action(Action1)");
.fullActionTextFixed, " action(Action1)");

assert.strictEqual(navObject.pageFields.find(a => a.name === 'Field1')
.fullFieldTextFixed, "field(Field1; RandomSource)");
.fullFieldTextFixed, "field(Field1; RandomSource)");

// Integer-prefixed actions and fields are contained in double-quotes
assert.strictEqual(navObject.objectActions.find(a => a.name === '2Action')
.fullActionTextFixed, " action(\"2Action\")");
.fullActionTextFixed, " action(\"2Action\")");

assert.strictEqual(navObject.pageFields.find(a => a.name === '2Field')
.fullFieldTextFixed, "field(\"2Field\"; RandomSource)");
.fullFieldTextFixed, "field(\"2Field\"; RandomSource)");
});
test("Pageextension - avoid setting double prefixes to actions", () => {
let testSettings = Settings.GetConfigSettings(null)
Expand Down Expand Up @@ -390,7 +399,7 @@ suite("NAVObject ObjectNamePrefix Tests", () => {
assert.strictEqual(navObject2.reportColumns[i].name, navObject.reportColumns[i].name)
}
});

test("Reportextension - Don't set double Affix", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';
Expand Down
35 changes: 35 additions & 0 deletions src/test/suite/NAVTestObjectLibrary.ts
Expand Up @@ -507,12 +507,47 @@ export function getTableExtensionWrongFileNameAndKeyWord(): NAVTestObject {
Caption = 'page';
DataClassification = CustomerContent;
}
field(116; "page with (brackets)"; Boolean)
{
Caption = 'page with (brackes)';
DataClassification = CustomerContent;
}
}
}
`
return object;
}
export function getTableWithBracketsInFieldName(): NAVTestObject {
let object = new NAVTestObject;

object.ObjectFileName = 'SomeTableExt.al'
object.ObjectText = `table 50100 "Prefix2 MyTabl e"
{
DataClassification = ToBeClassified;
fields
{
field(1; "MyField (LCY)"; Integer)
{
Caption = 'MyField';
DataClassification = ToBeClassified;
}
}
keys
{
key(PK; "MyField")
{
Clustered = true;
}
}
}
`
return object;
}
export function getTableExtension(): NAVTestObject {
let object = new NAVTestObject;

Expand Down

0 comments on commit 13d822c

Please sign in to comment.