-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-test.js
More file actions
53 lines (50 loc) · 2.7 KB
/
Copy pathstring-test.js
File metadata and controls
53 lines (50 loc) · 2.7 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
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("d3.interpolateString");
suite.addBatch({
"interpolateString": {
topic: load("interpolate/string").expression("d3.interpolateString"),
"interpolates matching numbers in both strings": function(interpolate) {
assert.strictEqual(interpolate(" 10/20 30", "50/10 100 ")(.2), "18/18 44 ");
assert.strictEqual(interpolate(" 10/20 30", "50/10 100 ")(.4), "26/16 58 ");
},
"coerces objects to strings": function(interpolate) {
assert.strictEqual(interpolate({toString: function() { return "2px"; }}, {toString: function() { return "12px"; }})(.25), "4.5px");
},
"preserves non-numbers in string b": function(interpolate) {
assert.strictEqual(interpolate(" 10/20 30", "50/10 foo ")(.2), "18/18 foo ");
assert.strictEqual(interpolate(" 10/20 30", "50/10 foo ")(.4), "26/16 foo ");
},
"preserves non-matching numbers in string b": function(interpolate) {
assert.strictEqual(interpolate(" 10/20 foo", "50/10 100 ")(.2), "18/18 100 ");
assert.strictEqual(interpolate(" 10/20 bar", "50/10 100 ")(.4), "26/16 100 ");
},
"preserves equal-value numbers in both strings": function(interpolate) {
assert.strictEqual(interpolate(" 10/20 100 20", "50/10 100, 20 ")(.2), "18/18 100, 20 ");
assert.strictEqual(interpolate(" 10/20 100 20", "50/10 100, 20 ")(.4), "26/16 100, 20 ");
},
"interpolates decimal notation correctly": function(interpolate) {
assert.strictEqual(interpolate("1.", "2.")(.5), "1.5");
},
"interpolates exponent notation correctly": function(interpolate) {
assert.strictEqual(interpolate("1e+3", "1e+4")(.5), "5500");
assert.strictEqual(interpolate("1e-3", "1e-4")(.5), "0.00055");
assert.strictEqual(interpolate("1.e-3", "1.e-4")(.5), "0.00055");
assert.strictEqual(interpolate("-1.e-3", "-1.e-4")(.5), "-0.00055");
assert.strictEqual(interpolate("+1.e-3", "+1.e-4")(.5), "0.00055");
assert.strictEqual(interpolate(".1e-2", ".1e-3")(.5), "0.00055");
},
"with no numbers, returns the target string": function(interpolate) {
assert.strictEqual(interpolate("foo", "bar")(.5), "bar");
assert.strictEqual(interpolate("foo", "")(.5), "");
assert.strictEqual(interpolate("", "bar")(.5), "bar");
assert.strictEqual(interpolate("", "")(.5), "");
},
"with two numerically-equivalent numbers, returns the default format": function(interpolate) {
assert.strictEqual(interpolate("top: 1000px;", "top: 1e3px;")(.5), "top: 1000px;");
assert.strictEqual(interpolate("top: 1e3px;", "top: 1000px;")(.5), "top: 1000px;");
}
}
});
suite.export(module);