-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbigints.js
71 lines (57 loc) · 2.38 KB
/
bigints.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import inspect from '../lib/index.js'
import { expect } from 'chai'
describe('bigints', () => {
it('returns number as passed in', () => {
expect(inspect(1n)).to.equal('1n')
expect(inspect(0n)).to.equal('0n')
})
it('uses scientific notation where possible', () => {
expect(inspect(1e300)).to.equal('1e+300')
})
describe('colors', () => {
it('returns string with yellow color, if colour is set to true', () => {
expect(inspect(1n, { colors: true })).to.equal('\u001b[33m1n\u001b[39m')
})
})
describe('truncate', () => {
it('returns the full representation when truncate is over string length', () => {
expect(inspect(3141592654n, { truncate: 11 })).to.equal('3141592654n')
})
it('truncates numbers longer than truncate (10)', () => {
expect(inspect(3141592654n, { truncate: 10 })).to.equal('31415926…n')
})
it('truncates numbers longer than truncate (9)', () => {
expect(inspect(3141592654n, { truncate: 9 })).to.equal('3141592…n')
})
it('truncates numbers longer than truncate (8)', () => {
expect(inspect(3141592654n, { truncate: 8 })).to.equal('314159…n')
})
it('truncates numbers longer than truncate (7)', () => {
expect(inspect(3141592654n, { truncate: 7 })).to.equal('31415…n')
})
it('truncates numbers longer than truncate (6)', () => {
expect(inspect(3141592654n, { truncate: 6 })).to.equal('3141…n')
})
it('truncates numbers longer than truncate (5)', () => {
expect(inspect(3141592654n, { truncate: 5 })).to.equal('314…n')
})
it('truncates numbers longer than truncate (4)', () => {
expect(inspect(3141592654n, { truncate: 4 })).to.equal('31…n')
})
it('truncates numbers longer than truncate (3)', () => {
expect(inspect(3141592654n, { truncate: 3 })).to.equal('3…n')
})
it('truncates numbers longer than truncate (2)', () => {
expect(inspect(3141592654n, { truncate: 2 })).to.equal('…')
})
it('truncates numbers longer than truncate (1)', () => {
expect(inspect(3141592654n, { truncate: 1 })).to.equal('…')
})
it('disregards truncate when it cannot truncate further (0)', () => {
expect(inspect(3141592654n, { truncate: 0 })).to.equal('…')
})
it('does not truncate if tail is same length as value', () => {
expect(inspect(3n, { truncate: 0 })).to.equal('3n')
})
})
})