-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
46 lines (38 loc) · 1.2 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
'use strict';
var test = require('ava')
, thousands = require('./');
test('should return empty string', function(t) {
t.is(thousands(''), '');
t.is(thousands(undefined), '');
});
test('should allow integers', function(t) {
t.is(thousands(0), '0');
t.is(thousands(1), '1');
t.is(thousands(1234), '1,234');
t.is(thousands(1234567), '1,234,567');
});
test('should allow negatives', function(t) {
t.is(thousands(-1), '-1');
t.is(thousands(-1234), '-1,234');
t.is(thousands(-1234567), '-1,234,567');
});
test('should allow strings', function(t) {
t.is(thousands('1'), '1');
t.is(thousands('1000'), '1,000');
t.is(thousands('1000000'), '1,000,000');
});
test('should not add commas to existing string', function(t) {
t.is(thousands('1,000'), '1,000');
t.is(thousands('1,000,000'), '1,000,000');
t.is(thousands('1,000.000'), '1,000.000');
});
test('should allow decimals', function(t) {
t.is(thousands(1.23), '1.23');
t.is(thousands(1234.56), '1,234.56');
t.is(thousands(1234567.89), '1,234,567.89');
t.is(thousands(1234.5678), '1,234.5678');
});
test('should allow custom delimiter', function(t) {
t.is(thousands(1234, ' '), '1 234');
t.is(thousands(1234567, ' '), '1 234 567');
});