Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/lib/Decimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import Utils from "../Utils.mjs";
* fromDecimal("10:20:30", "Colon");
*/
export function fromDecimal(data, delim="Auto") {
delim = Utils.charRep(delim);
const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.charRep(delim);
const output = [];
let byteStr = data.split(delim);
let byteStr = data.split(delimRegex);
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);

Expand Down
6 changes: 6 additions & 0 deletions tests/node/tests/operations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ Top Drawer`, {
assert.strictEqual(chef.fromDecimal("72 101 108 108 111").toString(), "Hello");
}),

it("From decimal with Auto delimiter", () => {
assert.strictEqual(chef.fromDecimal("72,101,108,108,111").toString(), "Hello");
assert.strictEqual(chef.fromDecimal("72:101:108:108:111").toString(), "Hello");
assert.strictEqual(chef.fromDecimal("72;101;108;108;111").toString(), "Hello");
}),
Comment on lines +535 to +539
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test to check the functionality of handling negative numbers? From reading your code, I believe that the output of chef.fromDecimal("-72 101 108 -108 -111") would be [-72, 101, 108, -108, -111] and it would be good to confirm whether that is or is not the case in a test.


it("From hex", () => {
assert.strictEqual(chef.fromHex("52 69 6e 67 20 41 6e 79 20 42 65 6c 6c 73 3f").toString(), "Ring Any Bells?");
}),
Expand Down
Loading