forked from d3/d3-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultLocale-test.js
48 lines (43 loc) · 1.17 KB
/
defaultLocale-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
var tape = require("tape"),
d3 = require("../");
var enUs = {
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["$", ""]
};
var frFr = {
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0€"]
};
tape("d3.formatDefaultLocale(definition) returns the new default locale", function(test) {
var locale = d3.formatDefaultLocale(frFr);
try {
test.equal(locale.format("$,.2f")(12345678.90), "12.345.678,90 €");
test.end();
} finally {
d3.formatDefaultLocale(enUs);
}
});
tape("d3.formatDefaultLocale(definition) affects d3.format", function(test) {
var locale = d3.formatDefaultLocale(frFr);
try {
test.equal(d3.format, locale.format);
test.equal(d3.format("$,.2f")(12345678.90), "12.345.678,90 €");
test.end();
} finally {
d3.formatDefaultLocale(enUs);
}
});
tape("d3.formatDefaultLocale(definition) affects d3.formatPrefix", function(test) {
var locale = d3.formatDefaultLocale(frFr);
try {
test.equal(d3.formatPrefix, locale.formatPrefix);
test.equal(d3.formatPrefix(",.2", 1e3)(12345678.90), "12.345,68k");
test.end();
} finally {
d3.formatDefaultLocale(enUs);
}
});