forked from VovanR/format-thousands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
73 lines (57 loc) · 1.65 KB
/
test.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
72
73
import test from 'ava';
import fn from './';
const NBSP = String.fromCharCode(160);
test('is function', t => {
t.is(typeof fn, 'function');
});
test('should return `1`', t => {
t.is(fn(1), '1');
});
test('should return `0`', t => {
t.is(fn(0), '0');
});
test('should return `12`', t => {
t.is(fn(12), '12');
});
test('should return `123`', t => {
t.is(fn(123), '123');
});
test('should return `1 000`', t => {
t.is(fn(1000), `1${NBSP}000`);
});
test('should return `10 000`', t => {
t.is(fn(10000), `10${NBSP}000`);
});
test('should set default thousands separator', t => {
t.is(fn(1234567890), `1${NBSP}234${NBSP}567${NBSP}890`);
});
test('should set custom thousands separator', t => {
t.is(fn(1234567890, '_'), '1_234_567_890');
t.is(fn(1234567890, {separator: '_'}), '1_234_567_890');
});
test('should not set separator if length < 5', t => {
var options = {formatFourDigits: false};
t.is(fn(1000, options), '1000');
t.is(fn(10000, options), `10${NBSP}000`);
});
test('should set separator if length < 5', t => {
var options = {formatFourDigits: true};
t.is(fn(1000, options), `1${NBSP}000`);
t.is(fn(10000, options), `10${NBSP}000`);
});
test('should return empty string if fired without args', t => {
t.is(fn(), '');
});
test('should not format `null` and `undefined`', t => {
t.is(fn(null), '');
t.is(fn(undefined), '');
});
test('should not format frac', t => {
t.is(fn(10000.0001, ' '), '10 000.0001');
t.is(fn(-1000000000.545, ' '), '-1 000 000 000.545');
t.is(fn(123456.1234567, ' '), '123 456.1234567');
});
test('should not format sign', t => {
t.is(fn(-100000, ' '), '-100 000');
t.is(fn(-100000000.545, ' '), '-100 000 000.545');
});