Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more serializer/deserializer tests. #559

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 16 additions & 3 deletions test/unit/serializer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,40 @@ test('Basic', (t) => {
});

test('Long numerals', (t) => {
t.plan(7);
t.plan(12);
const s = new Serializer();
const longPositive = BigInt(Number.MAX_SAFE_INTEGER) * 2n; // eslint-disable-line no-undef
const longNegative = BigInt(Number.MIN_SAFE_INTEGER) * 2n; // eslint-disable-line no-undef

const json =
`{` +
// The space before and after the values, and the lack of spaces before comma are intentional
`"\\":${longPositive}": "[ ${longNegative.toString()}, ${longPositive.toString()} ]", ` +
`"positive": ${longPositive.toString()}, ` +
`"array": [ ${longNegative.toString()}, ${longPositive.toString()} ], ` +
`"negative": ${longNegative.toString()},` +
`"hardcoded": 102931203123987` +
`"hardcoded": 102931203123987,` +
`"a": "෴102931203123988",` +
`"b": "߷102931203123989",` +
`"c": "֍102931203123990",` +
`"d": "෴֍߷102931203123991",` +
`"e": "123෴֍߷102931203123991"` +
`}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you want to add the expected outputs like t.equal(obj.hardcoded, 102931203123987); on line 71?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will be adding similar ones in my other PR. I would recommend we hold off on these.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.


const obj = s.deserialize(json);
const res = s.serialize(obj);
t.equal(obj.positive, longPositive);
t.equal(obj.negative, longNegative);
t.same(obj.array, [longNegative, longPositive]);
// The space before and after the values, and the lack of spaces before comma are intentional
t.equal(obj['":' + longPositive], `[ ${longNegative.toString()}, ${longPositive.toString()} ]`);
t.equal(obj.hardcoded, 102931203123987);
t.equal(obj.a, '෴102931203123988');
t.equal(obj.b, '߷102931203123989');
t.equal(obj.c, '֍102931203123990');
t.equal(obj.d, '෴֍߷102931203123991');
t.equal(obj.e, '123෴֍߷102931203123991');

const res = s.serialize(obj);
t.equal(res.replace(/\s+/g, ''), json.replace(/\s+/g, ''));
t.match(res, `"[ ${longNegative.toString()}, ${longPositive.toString()} ]"`);
});
Expand Down