-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathformat-test.js
More file actions
85 lines (72 loc) · 3.69 KB
/
format-test.js
File metadata and controls
85 lines (72 loc) · 3.69 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
import {assert, it} from "vitest";
import * as Plot from "@observablehq/plot";
it("formatNumber(locale) does the right thing", () => {
assert.strictEqual(Plot.formatNumber()(Math.PI), "3.142");
assert.strictEqual(Plot.formatNumber()(12345), "12,345");
assert.strictEqual(Plot.formatNumber("en")(Math.PI), "3.142");
assert.strictEqual(Plot.formatNumber("en")(12345), "12,345");
assert.strictEqual(Plot.formatNumber("fr")(Math.PI), "3,142");
assert.strictEqual(Plot.formatNumber("fr")(12345), "12\u202f345");
});
it("formatMonth(locale, format) does the right thing", () => {
assert.strictEqual(Plot.formatMonth("en", "long")(0), "January");
assert.strictEqual(Plot.formatMonth("en", "short")(0), "Jan");
assert.strictEqual(Plot.formatMonth("en", "narrow")(0), "J");
});
it("formatMonth('fr', format) does the right thing", () => {
assert.strictEqual(Plot.formatMonth("fr", "long")(11), "décembre");
assert.strictEqual(Plot.formatMonth("fr", "short")(11), "déc.");
assert.strictEqual(Plot.formatMonth("fr", "narrow")(11), "D");
});
it("formatMonth(locale, format) handles undefined input", () => {
assert.strictEqual(Plot.formatMonth()(undefined), undefined);
assert.strictEqual(Plot.formatMonth()(null), undefined);
assert.strictEqual(Plot.formatMonth()(NaN), undefined);
assert.strictEqual(Plot.formatMonth()(Infinity), undefined);
assert.strictEqual(Plot.formatMonth()(1e32), undefined);
});
it("formatMonth(locale) has the expected default", () => {
assert.strictEqual(Plot.formatMonth("en")(0), "Jan");
assert.strictEqual(Plot.formatMonth("en", undefined)(0), "Jan");
});
it("formatMonth('fr') has the expected default", () => {
assert.strictEqual(Plot.formatMonth("fr")(11), "déc.");
assert.strictEqual(Plot.formatMonth("fr", undefined)(11), "déc.");
});
it("formatMonth() has the expected default", () => {
assert.strictEqual(Plot.formatMonth()(0), "Jan");
assert.strictEqual(Plot.formatMonth(undefined, "narrow")(0), "J");
assert.strictEqual(Plot.formatMonth(undefined, "short")(0), "Jan");
assert.strictEqual(Plot.formatMonth(undefined, "long")(0), "January");
});
it("formatWeekday(locale, format) does the right thing", () => {
assert.strictEqual(Plot.formatWeekday("en", "long")(0), "Sunday");
assert.strictEqual(Plot.formatWeekday("en", "short")(0), "Sun");
assert.strictEqual(Plot.formatWeekday("en", "narrow")(0), "S");
});
it.skip("formatWeekday('fr', format) does the right thing", () => {
assert.strictEqual(Plot.formatWeekday("fr", "long")(6), "samedi");
assert.strictEqual(Plot.formatWeekday("fr", "short")(6), "sam.");
assert.strictEqual(Plot.formatWeekday("fr", "narrow")(6), "S");
});
it("formatWeekday(locale) has the expected default", () => {
assert.strictEqual(Plot.formatWeekday("en")(0), "Sun");
assert.strictEqual(Plot.formatWeekday("en", undefined)(0), "Sun");
});
it.skip("formatWeekday('fr') has the expected default", () => {
assert.strictEqual(Plot.formatWeekday("fr")(6), "sam.");
assert.strictEqual(Plot.formatWeekday("fr", undefined)(6), "sam.");
});
it("formatWeekday() has the expected default", () => {
assert.strictEqual(Plot.formatWeekday()(0), "Sun");
assert.strictEqual(Plot.formatWeekday(undefined, "narrow")(0), "S");
assert.strictEqual(Plot.formatWeekday(undefined, "short")(0), "Sun");
assert.strictEqual(Plot.formatWeekday(undefined, "long")(0), "Sunday");
});
it("formatWeekday() handles undefined input", () => {
assert.strictEqual(Plot.formatWeekday()(undefined), undefined);
assert.strictEqual(Plot.formatWeekday()(null), undefined);
assert.strictEqual(Plot.formatWeekday()(NaN), undefined);
assert.strictEqual(Plot.formatWeekday()(Infinity), undefined);
assert.strictEqual(Plot.formatWeekday()(1e32), undefined);
});