Skip to content

Commit

Permalink
add a few tests for scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Oct 13, 2024
1 parent 47f71f8 commit e78d663
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/type/__tests__/scalars-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Type System: Specified scalar types', () => {
expect(parseValue(1)).to.equal(1);
expect(parseValue(0)).to.equal(0);
expect(parseValue(-1)).to.equal(-1);
expect(parseValue(1n)).to.equal(1);

expect(() => parseValue(9876504321)).to.throw(
'Int cannot represent non 32-bit signed integer value: 9876504321',
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('Type System: Specified scalar types', () => {
expect(serialize(1e5)).to.equal(100000);
expect(serialize(false)).to.equal(0);
expect(serialize(true)).to.equal(1);
expect(serialize(1n)).to.equal(1);

const customValueOfObj = {
value: 5,
Expand Down Expand Up @@ -280,6 +282,7 @@ describe('Type System: Specified scalar types', () => {
expect(serialize('-1.1')).to.equal(-1.1);
expect(serialize(false)).to.equal(0.0);
expect(serialize(true)).to.equal(1.0);
expect(serialize(1n)).to.equal(1n);

const customValueOfObj = {
value: 5.5,
Expand Down Expand Up @@ -380,6 +383,7 @@ describe('Type System: Specified scalar types', () => {
expect(serialize(-1.1)).to.equal('-1.1');
expect(serialize(true)).to.equal('true');
expect(serialize(false)).to.equal('false');
expect(serialize(9007199254740993n)).to.equal('9007199254740993');

const valueOf = () => 'valueOf string';
const toJSON = () => 'toJSON string';
Expand Down Expand Up @@ -493,6 +497,8 @@ describe('Type System: Specified scalar types', () => {

expect(serialize(1)).to.equal(true);
expect(serialize(0)).to.equal(false);
expect(serialize(1n)).to.equal(true);
expect(serialize(0n)).to.equal(false);
expect(serialize(true)).to.equal(true);
expect(serialize(false)).to.equal(false);
expect(
Expand Down Expand Up @@ -539,6 +545,9 @@ describe('Type System: Specified scalar types', () => {
expect(parseValue(9007199254740991)).to.equal('9007199254740991');
expect(parseValue(-9007199254740991)).to.equal('-9007199254740991');

// Can handle bigint in JS
expect(parseValue(9007199254740993n)).to.equal('9007199254740993');

expect(() => parseValue(undefined)).to.throw(
'ID cannot represent value: undefined',
);
Expand Down Expand Up @@ -614,6 +623,7 @@ describe('Type System: Specified scalar types', () => {
expect(serialize(123)).to.equal('123');
expect(serialize(0)).to.equal('0');
expect(serialize(-1)).to.equal('-1');
expect(serialize(9007199254740993n)).to.equal('9007199254740993');

const valueOf = () => 'valueOf ID';
const toJSON = () => 'toJSON ID';
Expand Down

0 comments on commit e78d663

Please sign in to comment.