From 87a37b96b687effe33175b486d11a17224bab6c3 Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Mon, 9 Jun 2025 16:06:43 +0300 Subject: [PATCH] fix(List): toString is different from toJSON --- src/containers/Sequence.js | 8 ++++++-- test/List.test.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/containers/Sequence.js b/src/containers/Sequence.js index f5376df..1f90b9c 100644 --- a/src/containers/Sequence.js +++ b/src/containers/Sequence.js @@ -120,13 +120,17 @@ export class SequenceContainer { } toJSON() { - return this.toString() + let res = [] + for (const value of this) { + res.push(JSON.stringify(value)) + } + return '[ ' + res.join(', ') + ' ]' } toString() { let res = [] for (const value of this) { - res.push(JSON.stringify(value)) + res.push(value.toString()) } return '[ ' + res.join(', ') + ' ]' } diff --git a/test/List.test.js b/test/List.test.js index 0be45dd..b022b15 100644 --- a/test/List.test.js +++ b/test/List.test.js @@ -134,4 +134,5 @@ test('pushBack, pushFront, popBack, popFront, back, front', () => { test('toJSON, toString', () => { expect(List.from([1, 2]).toJSON()).toEqual('[ 1, 2 ]') + expect(List.from([0n]).toString()).toEqual('[ 0 ]') }) \ No newline at end of file