simple-fmt-tests.js
1.22 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
"use strict";
var test = require("tap").test;
var fmt = require("../");
test("fmt", function(t) {
t.equals(fmt("all your {0} are belong to {1}", "base", "us"),
"all your base are belong to us");
var obj = {
toString: function() {
return "yoyoma";
},
};
t.equals(fmt("object is called {0} and is {1} ms old", obj, 1),
"object is called yoyoma and is 1 ms old");
t.equals(fmt("no arguments => no modifs {0} {1}"),
"no arguments => no modifs {0} {1}");
t.end();
});
test("fmt.obj", function(t) {
var obj2 = {
name: "yoyoma",
age: 1,
};
t.equals(fmt.obj("object is called {name} and is {age} ms old", obj2),
"object is called yoyoma and is 1 ms old");
t.equals(fmt.obj("no matching properties => no modifs {0} {1} {name} {age}", {}),
"no matching properties => no modifs {0} {1} {name} {age}");
t.equals(fmt.obj("works for arrays too: [{2}, {1}, {0}]", ["one", "two", "three"]),
"works for arrays too: [three, two, one]");
t.end();
});
test("fmt.repeat", function(t) {
t.equals(fmt.repeat("*", 3), "***");
t.equals(fmt.repeat("*", 0), "");
t.equals(fmt.repeat("", 3), "");
t.end();
});