forked from d3/d3-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-type-x-test.js
91 lines (75 loc) · 2.98 KB
/
format-type-x-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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var tape = require("tape"),
format = require("../");
tape("format(\"x\") returns the expected hexadecimal (lowercase) string", function(test) {
test.equal(format.format("x")(0xdeadbeef), "deadbeef");
test.end();
});
tape("format(\"#x\") returns the expected hexadecimal (lowercase) string with prefix", function(test) {
test.equal(format.format("#x")(0xdeadbeef), "0xdeadbeef");
test.end();
});
tape("format(\",x\") groups thousands", function(test) {
test.equal(format.format(",x")(0xdeadbeef), "de,adb,eef");
test.end();
});
tape("format(\",x\") groups thousands", function(test) {
test.equal(format.format(",x")(0xdeadbeef), "de,adb,eef");
test.end();
});
tape("format(\"#,x\") does not group the prefix", function(test) {
test.equal(format.format("#,x")(0xadeadbeef), "0xade,adb,eef");
test.end();
});
tape("format(\"+#x\") puts the sign before the prefix", function(test) {
test.equal(format.format("+#x")(0xdeadbeef), "+0xdeadbeef");
test.equal(format.format("+#x")(-0xdeadbeef), "-0xdeadbeef");
test.equal(format.format(" #x")(0xdeadbeef), " 0xdeadbeef");
test.equal(format.format(" #x")(-0xdeadbeef), "-0xdeadbeef");
test.end();
});
tape("format(\"$,x\") formats hexadecimal currency", function(test) {
test.equal(format.format("$,x")(0xdeadbeef), "$de,adb,eef");
test.end();
});
tape("format(\"[.precision]x\") always has precision zero", function(test) {
test.equal(format.format(".2x")(0xdeadbeef), "deadbeef");
test.equal(format.format(".2x")(-4.2), "-4");
test.end();
});
tape("format(\"x\") rounds non-integers", function(test) {
test.equal(format.format("x")(2.4), "2");
test.end();
});
tape("format(\"x\") can format negative zero as zero", function(test) {
test.equal(format.format("x")(-0), "0");
test.equal(format.format("x")(-1e-12), "0");
test.end();
});
tape("format(\"x\") does not consider -0xeee to be positive", function(test) {
test.equal(format.format("x")(-0xeee), "-eee");
test.end();
});
tape("format(\"X\") returns the expected hexadecimal (uppercase) string", function(test) {
test.equal(format.format("X")(0xdeadbeef), "DEADBEEF");
test.end();
});
tape("format(\"#X\") returns the expected hexadecimal (uppercase) string with prefix", function(test) {
test.equal(format.format("#X")(0xdeadbeef), "0xDEADBEEF");
test.end();
});
tape("format(\"X\") can format negative zero as zero", function(test) {
test.equal(format.format("X")(-0), "0");
test.equal(format.format("X")(-1e-12), "0");
test.end();
});
tape("format(\"X\") does not consider -0xeee to be positive", function(test) {
test.equal(format.format("X")(-0xeee), "-EEE");
test.end();
});
tape("format(\"#[width]x\") considers the prefix", function(test) {
test.equal(format.format("20x")(0xdeadbeef), " deadbeef");
test.equal(format.format("#20x")(0xdeadbeef), " 0xdeadbeef");
test.equal(format.format("020x")(0xdeadbeef), "000000000000deadbeef");
test.equal(format.format("#020x")(0xdeadbeef), "0x0000000000deadbeef");
test.end();
});