File size: 1,061 Bytes
23ac194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'

const { test } = require('node:test')
const build = require('..')

test('Finite numbers', t => {
  const values = [-5, 0, -0, 1.33, 99, 100.0,
    Math.E, Number.EPSILON,
    Number.MAX_SAFE_INTEGER, Number.MAX_VALUE,
    Number.MIN_SAFE_INTEGER, Number.MIN_VALUE]

  t.plan(values.length)

  const schema = {
    type: 'number'
  }

  const stringify = build(schema)

  values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
})

test('Infinite integers', t => {
  const values = [Infinity, -Infinity]

  t.plan(values.length)

  const schema = {
    type: 'integer'
  }

  const stringify = build(schema)

  values.forEach(v => {
    try {
      stringify(v)
    } catch (err) {
      t.assert.equal(err.message, `The value "${v}" cannot be converted to an integer.`)
    }
  })
})

test('Infinite numbers', t => {
  const values = [Infinity, -Infinity]

  t.plan(values.length)

  const schema = {
    type: 'number'
  }

  const stringify = build(schema)

  values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
})