Skip to content

Commit

Permalink
chore: add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 20, 2023
1 parent cf575ff commit 20e05d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/

/**
* Test whether a string can be safely represented with a number
* without information.
* without information loss.
*
* When approx is true, floating point numbers that lose a few digits but
* are still approximately equal in value are considered safe too.
Expand Down
3 changes: 3 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ test('isSafeNumber', () => {
expect(isSafeNumber('0.66666666666666666667')).toEqual(false)
expect(isSafeNumber('12345678901234567890')).toEqual(false)
expect(isSafeNumber('1.2345678901234567890')).toEqual(false)

// the following number loses formatting, but the value stays the same and hence is safe
expect(isSafeNumber('2.300')).toEqual(true)
})

test('isSafeNumber({ approx: false })', () => {
Expand Down

0 comments on commit 20e05d8

Please sign in to comment.