Skip to content

Commit 8c3f725

Browse files
committed
Append tests for format.compile() function
1 parent d32386b commit 8c3f725

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

test/test.js

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,95 @@
7373
});
7474
});
7575

76-
}(this));
76+
describe('format.compile', function () {
77+
it('1 replace', function () {
78+
var f = format.compile('%s');
79+
expect(f('hello')).to.eql('hello');
80+
});
81+
it('2 insert', function () {
82+
var f = format.compile('%shello');
83+
expect(f('hello')).to.eql('hellohello');
84+
});
85+
it('3 append', function () {
86+
var f = format.compile('hello%s');
87+
expect(f('hello')).to.eql('hellohello');
88+
});
89+
it('4 insert2', function () {
90+
var f = format.compile('hello%shello');
91+
expect(f('hello')).to.eql('hellohellohello');
92+
});
93+
it('5 join', function () {
94+
var f = format.compile('%s%s');
95+
expect(f('he', 'llo')).to.eql('hello');
96+
});
97+
it('6 replace2', function () {
98+
var f = format.compile(' %s %s ');
99+
expect(f('he', 'llo')).to.eql(' he llo ');
100+
});
101+
it('7 %s', function () {
102+
var f = format.compile('%s');
103+
expect(f('%s')).to.eql('%s');
104+
});
105+
it('8 number', function () {
106+
var f = format.compile('%s');
107+
expect(f(100)).to.eql('100');
108+
});
109+
it('9 boolean', function () {
110+
var f = format.compile('%s');
111+
expect(f(true)).to.eql('true');
112+
});
113+
it('10 date', function () {
114+
var f = format.compile('%s');
115+
expect(f(new Date(2015, 5, 28))).to.contain('Sun Jun 28 2015 00:00:00');
116+
});
117+
it('11 array', function () {
118+
var f = format.compile('%s');
119+
expect(f([1, 2, 3])).to.eql('1,2,3');
120+
});
121+
it('12 object', function () {
122+
var f = format.compile('%s');
123+
expect(f({ key: 'value' })).to.eql('[object Object]');
124+
});
125+
it('13 NaN', function () {
126+
var f = format.compile('%s');
127+
expect(f(NaN)).to.eql('NaN');
128+
});
129+
it('14 function', function () {
130+
var f = format.compile('%s');
131+
expect(f(function () {})).to.eql('function () {}');
132+
});
133+
it('15 null', function () {
134+
var f = format.compile('%s');
135+
expect(f(null)).to.eql('null');
136+
});
137+
it('16 undefined', function () {
138+
var f = format.compile('%s');
139+
expect(f(undefined)).to.eql('undefined');
140+
});
141+
it('17 excess', function () {
142+
var f = format.compile('%s %s %s %s');
143+
expect(f('1', '2', '3', '4', '5')).to.eql('1 2 3 4');
144+
});
145+
it('18 deficiency', function () {
146+
var f = format.compile('%s %s %s %s');
147+
expect(f('1', '2', '3')).to.eql('1 2 3 %s');
148+
});
149+
it('19 no values', function () {
150+
var f = format.compile('%s %s %s %s');
151+
expect(f()).to.eql('%s %s %s %s');
152+
});
153+
it('20 %', function () {
154+
var f = format.compile('%');
155+
expect(f()).to.eql('%');
156+
});
157+
it('21 empty', function () {
158+
var f = format.compile();
159+
expect(f()).to.eql('');
160+
});
161+
it('22 not supported', function () {
162+
var f = format.compile('%d, %j');
163+
expect(f(10, { key: 'value' })).to.eql('%d, %j');
164+
});
165+
});
77166

167+
}(this));

0 commit comments

Comments
 (0)