Skip to content

Commit

Permalink
Additional changes to get correct amount of spaces
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Apr 19, 2024
1 parent 0b747d8 commit 5a65774
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ export namespace Tools {

headers.forEach(header => {
const fromPos = header.from - slideBytesBy;
const strValue = line.substring(fromPos, fromPos + header.length).trimEnd();
let strValue = line.substring(fromPos, fromPos + header.length);

let realValue: string | number | null = strValue;
const extendedBytes = strValue.split(``).map(c => Buffer.byteLength(c) === 1 ? 0 : 1).reduce((a: number, b: number) => a + b, 0);

slideBytesBy += strValue.split(``).map(c => Buffer.byteLength(c) === 1 ? 0 : 1).reduce((a: number, b: number) => a + b, 0);
slideBytesBy += extendedBytes;
if (extendedBytes > 0) {
strValue = strValue.substring(0, strValue.length - extendedBytes);
}

let realValue: string | number | null = strValue.trimEnd();

// is value a number?
if (strValue.startsWith(` `)) {
Expand Down
35 changes: 34 additions & 1 deletion src/testing/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const ToolsSuite: TestSuite = {
}
},
{
name: `JP result set test`, test: async () => {
name: `JP result set test (A)`, test: async () => {
const lines = [
`DB2>`,
` ?>`,
Expand Down Expand Up @@ -117,6 +117,39 @@ export const ToolsSuite: TestSuite = {
assert.strictEqual(rows[0].CREATED, 1712670631000);
assert.strictEqual(rows[0].CHANGED, 1712683676000);
}
},
{
name: `JP result set test (B)`, test: async () => {
const lines = [
`DB2>`,
` ?>`,
` ?>`,
` ?>`,
` ?>`,
``,
``,
`LIBRARY RECORD_LENGTH ASP SOURCE_FILE NAME TYPE TEXT LINES CREATED CHANGED`,
`--------- -------------------- ------ ------------ ---------- ---------- ------------------------------------------------------------------------------------------------------------------------------ -------------------- -------------------- --------------------`,
`SNDLIB 112 0 QRPGLESRC TESTEDTW RPGLE 日付と時刻を先行0付きで表示-> 8桁では無理? 9 1713451802000 1713453741000`,
``,
` 1 RECORD(S) SELECTED.`,
];

const rows = Tools.db2Parse(lines.join(`\n`));

assert.strictEqual(rows.length, 1);

assert.strictEqual(rows[0].LIBRARY, `SNDLIB`);
assert.strictEqual(rows[0].RECORD_LENGTH, 112);
assert.strictEqual(rows[0].ASP, 0);
assert.strictEqual(rows[0].SOURCE_FILE, `QRPGLESRC`);
assert.strictEqual(rows[0].NAME, `TESTEDTW`);
assert.strictEqual(rows[0].TYPE, `RPGLE`);
assert.strictEqual(rows[0].TEXT, `日付と時刻を先行0付きで表示-> 8桁では無理?`);
assert.strictEqual(rows[0].LINES, 9);
assert.strictEqual(rows[0].CREATED, 1713451802000);
assert.strictEqual(rows[0].CHANGED, 1713453741000);
}
}
]
};

0 comments on commit 5a65774

Please sign in to comment.