format.spec.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. import {expect} from 'chai';
  2. import {format} from './format.js';
  3. describe('format', function () {
  4. describe('pattern', function () {
  5. it('uses the given pattern of a string as is', function () {
  6. const res = format('foo');
  7. expect(res).to.be.eq('foo');
  8. });
  9. it('uses the given pattern of an empty string as is', function () {
  10. const res = format('');
  11. expect(res).to.be.eq('');
  12. });
  13. it('converts the given pattern of a number to a string', function () {
  14. const res = format(10);
  15. expect(res).to.be.eq('10');
  16. });
  17. it('converts the given pattern of zero to a string', function () {
  18. const res = format(0);
  19. expect(res).to.be.eq('0');
  20. });
  21. it('converts the given pattern of NaN to a string', function () {
  22. const res = format(NaN);
  23. expect(res).to.be.eq('NaN');
  24. });
  25. it('converts the given pattern of Infinity to a string', function () {
  26. const res = format(Infinity);
  27. expect(res).to.be.eq('Infinity');
  28. });
  29. it('converts the given pattern of true to a string', function () {
  30. const res = format(true);
  31. expect(res).to.be.eq('true');
  32. });
  33. it('converts the given pattern of false to a string', function () {
  34. const res = format(false);
  35. expect(res).to.be.eq('false');
  36. });
  37. it('converts the given pattern of an array to a string', function () {
  38. const res = format([1, 2, 3]);
  39. expect(res).to.be.eq('1,2,3');
  40. });
  41. it('converts the given pattern of an empty array to a string', function () {
  42. const res = format([]);
  43. expect(res).to.be.eq('');
  44. });
  45. it('converts the given pattern of a key-value object to a string', function () {
  46. const res = format({foo: 'bar'});
  47. expect(res).to.be.eq('[object Object]');
  48. });
  49. it('converts the given pattern of an object without keys to a string', function () {
  50. const res = format({});
  51. expect(res).to.be.eq('[object Object]');
  52. });
  53. it('converts the given pattern of a date instance to a string', function () {
  54. const date = new Date();
  55. const res = format(date);
  56. expect(res).to.be.eq(date.toISOString());
  57. });
  58. it('converts the given pattern of a map instance to a string', function () {
  59. const res = format(new Map());
  60. expect(res).to.be.eq('[object Map]');
  61. });
  62. it('converts the given pattern of a class instance to a string', function () {
  63. class MyClass {}
  64. const res = format(MyClass);
  65. expect(res).to.be.eq('class MyClass {}');
  66. });
  67. it('converts the given pattern of a function to a string', function () {
  68. const res = format(function () {});
  69. expect(res).to.be.eq('function () {}');
  70. });
  71. it('converts the given pattern of an anonymous function to a string', function () {
  72. const res = format(() => undefined);
  73. expect(res).to.be.eq('() => undefined');
  74. });
  75. it('converts the given pattern of a named function to a string', function () {
  76. function foo() {}
  77. const res = format(foo);
  78. expect(res).to.be.eq('function foo() {}');
  79. });
  80. it('converts the given pattern of an anonymous class to a string', function () {
  81. const res = format(class {});
  82. expect(res).to.be.eq('class {}');
  83. });
  84. it('converts the given pattern of a named class to a string', function () {
  85. class MyClass {}
  86. const res = format(MyClass);
  87. expect(res).to.be.eq('class MyClass {}');
  88. });
  89. it('converts the given pattern of a class constructor to a string', function () {
  90. class MyClass {}
  91. const res = format(MyClass.constructor);
  92. expect(res).to.be.eq('function Function() { [native code] }');
  93. });
  94. it('converts the given pattern of a symbol to a string', function () {
  95. const res = format('%s', Symbol());
  96. expect(res).to.be.eq('Symbol()');
  97. });
  98. it('converts the given pattern of a named symbol to a string', function () {
  99. const res = format('%s', Symbol('foo'));
  100. expect(res).to.be.eq('Symbol(foo)');
  101. });
  102. it('converts undefined pattern to a string', function () {
  103. const res = format(undefined);
  104. expect(res).to.be.eq('undefined');
  105. });
  106. it('converts null pattern to a string', function () {
  107. const res = format(null);
  108. expect(res).to.be.eq('null');
  109. });
  110. });
  111. describe('%s', function () {
  112. it('returns a string representation of the non-pattern string', function () {
  113. const res = format('foo');
  114. expect(res).to.be.eq('foo');
  115. });
  116. it('returns a string representation of the escaped pattern', function () {
  117. const res = format('%%s', 'foo');
  118. expect(res).to.be.eq('%s foo');
  119. });
  120. it('returns a string representation of the multiple strings', function () {
  121. const res = format('%s:%s', 'foo', 'bar');
  122. expect(res).to.be.eq('foo:bar');
  123. });
  124. it('returns a string representation of the given string', function () {
  125. const res = format('%s', 'foo');
  126. expect(res).to.be.eq('foo');
  127. });
  128. it('returns a string representation of the given empty string', function () {
  129. const res = format('%s', '');
  130. expect(res).to.be.eq('');
  131. });
  132. it('returns a string representation of the given number', function () {
  133. const res = format('%s', 10);
  134. expect(res).to.be.eq('10');
  135. });
  136. it('returns a string representation of the given zero', function () {
  137. const res = format('%s', 0);
  138. expect(res).to.be.eq('0');
  139. });
  140. it('returns a string representation of the given NaN', function () {
  141. const res = format('%s', NaN);
  142. expect(res).to.be.eq('NaN');
  143. });
  144. it('returns a string representation of the given Infinity', function () {
  145. const res = format('%s', Infinity);
  146. expect(res).to.be.eq('Infinity');
  147. });
  148. it('returns a string representation of the given true', function () {
  149. const res = format('%s', true);
  150. expect(res).to.be.eq('true');
  151. });
  152. it('returns a string representation of the given false', function () {
  153. const res = format('%s', false);
  154. expect(res).to.be.eq('false');
  155. });
  156. it('returns a string representation of the given array', function () {
  157. const res = format('%s', [1, 2, 3]);
  158. expect(res).to.be.eq('1,2,3');
  159. });
  160. it('returns a string representation of the given empty array', function () {
  161. const res = format('%s', []);
  162. expect(res).to.be.eq('');
  163. });
  164. it('returns a string representation of the given key-value object', function () {
  165. const res = format('%s', {foo: 'bar'});
  166. expect(res).to.be.eq('[object Object]');
  167. });
  168. it('returns a string representation of the given object without keys', function () {
  169. const res = format('%s', {});
  170. expect(res).to.be.eq('[object Object]');
  171. });
  172. it('returns a string representation of the given date instance', function () {
  173. const date = new Date();
  174. const res = format('%s', date);
  175. expect(res).to.be.eq(date.toString());
  176. });
  177. it('returns a string representation of the given map instance', function () {
  178. const res = format('%s', new Map());
  179. expect(res).to.be.eq('[object Map]');
  180. });
  181. it('returns a string representation of the given class instance', function () {
  182. class MyClass {}
  183. const res = format('%s', new MyClass());
  184. expect(res).to.be.eq('[object Object]');
  185. });
  186. it('returns a string representation of the given function', function () {
  187. const res = format('%s', function () {});
  188. expect(res).to.be.eq('function () {}');
  189. });
  190. it('returns a string representation of the given anonymous function', function () {
  191. const res = format('%s', () => undefined);
  192. expect(res).to.be.eq('() => undefined');
  193. });
  194. it('returns a string representation of the given named function', function () {
  195. function foo() {}
  196. const res = format('%s', foo);
  197. expect(res).to.be.eq('function foo() {}');
  198. });
  199. it('returns a string representation of the given anonymous class', function () {
  200. const res = format('%s', class {});
  201. expect(res).to.be.eq('class {}');
  202. });
  203. it('returns a string representation of the given named class', function () {
  204. class MyClass {}
  205. const res = format('%s', MyClass);
  206. expect(res).to.be.eq('class MyClass {}');
  207. });
  208. it('returns a string representation of the given class constructor', function () {
  209. class MyClass {}
  210. const res = format('%s', MyClass.constructor);
  211. expect(res).to.be.eq('function Function() { [native code] }');
  212. });
  213. it('returns a string representation of the given symbol', function () {
  214. const res = format('%s', Symbol());
  215. expect(res).to.be.eq('Symbol()');
  216. });
  217. it('returns a string representation of the given named symbol', function () {
  218. const res = format('%s', Symbol('foo'));
  219. expect(res).to.be.eq('Symbol(foo)');
  220. });
  221. it('returns a string representation of the given undefined', function () {
  222. const res = format('%s', undefined);
  223. expect(res).to.be.eq('undefined');
  224. });
  225. it('returns a string representation of the given null', function () {
  226. const res = format('%s', null);
  227. expect(res).to.be.eq('null');
  228. });
  229. });
  230. describe('%d', function () {
  231. it('returns a string representation of the given string', function () {
  232. const res = format('%d', 'foo');
  233. expect(res).to.be.eq('NaN');
  234. });
  235. it('returns a string representation of the given empty string', function () {
  236. const res = format('%d', '');
  237. expect(res).to.be.eq('0');
  238. });
  239. it('returns a string representation of the given number', function () {
  240. const res = format('%d', 10);
  241. expect(res).to.be.eq('10');
  242. });
  243. it('returns a string representation of the given zero', function () {
  244. const res = format('%d', 0);
  245. expect(res).to.be.eq('0');
  246. });
  247. it('returns a string representation of the given NaN', function () {
  248. const res = format('%d', NaN);
  249. expect(res).to.be.eq('NaN');
  250. });
  251. it('returns a string representation of the given Infinity', function () {
  252. const res = format('%d', Infinity);
  253. expect(res).to.be.eq('Infinity');
  254. });
  255. it('returns a string representation of the given true', function () {
  256. const res = format('%d', true);
  257. expect(res).to.be.eq('1');
  258. });
  259. it('returns a string representation of the given false', function () {
  260. const res = format('%d', false);
  261. expect(res).to.be.eq('0');
  262. });
  263. it('returns a string representation of the given array', function () {
  264. const res = format('%d', [1, 2, 3]);
  265. expect(res).to.be.eq('NaN');
  266. });
  267. it('returns a string representation of the given empty array', function () {
  268. const res = format('%d', []);
  269. expect(res).to.be.eq('0');
  270. });
  271. it('returns a string representation of the given key-value object', function () {
  272. const res = format('%d', {foo: 'bar'});
  273. expect(res).to.be.eq('NaN');
  274. });
  275. it('returns a string representation of the given object without keys', function () {
  276. const res = format('%d', {});
  277. expect(res).to.be.eq('NaN');
  278. });
  279. it('returns a string representation of the given date instance', function () {
  280. const date = new Date();
  281. const res = format('%d', date);
  282. expect(res).to.be.eq(String(date.getTime()));
  283. });
  284. it('returns a string representation of the given map instance', function () {
  285. const res = format('%d', new Map());
  286. expect(res).to.be.eq('NaN');
  287. });
  288. it('returns a string representation of the given class instance', function () {
  289. class MyClass {}
  290. const res = format('%d', new MyClass());
  291. expect(res).to.be.eq('NaN');
  292. });
  293. it('returns a string representation of the given function', function () {
  294. const res = format('%d', function () {});
  295. expect(res).to.be.eq('NaN');
  296. });
  297. it('returns a string representation of the given anonymous function', function () {
  298. const res = format('%d', () => undefined);
  299. expect(res).to.be.eq('NaN');
  300. });
  301. it('returns a string representation of the given named function', function () {
  302. function foo() {}
  303. const res = format('%d', foo);
  304. expect(res).to.be.eq('NaN');
  305. });
  306. it('returns a string representation of the given anonymous class', function () {
  307. const res = format('%d', class {});
  308. expect(res).to.be.eq('NaN');
  309. });
  310. it('returns a string representation of the given named class', function () {
  311. class MyClass {}
  312. const res = format('%d', MyClass);
  313. expect(res).to.be.eq('NaN');
  314. });
  315. it('returns a string representation of the given class constructor', function () {
  316. class MyClass {}
  317. const res = format('%d', MyClass.constructor);
  318. expect(res).to.be.eq('NaN');
  319. });
  320. it('returns a string representation of the given undefined', function () {
  321. const res = format('%d', undefined);
  322. expect(res).to.be.eq('NaN');
  323. });
  324. it('returns a string representation of the given null', function () {
  325. const res = format('%d', null);
  326. expect(res).to.be.eq('0');
  327. });
  328. });
  329. describe('%j', function () {
  330. it('returns a string representation of the given string', function () {
  331. const res = format('%j', 'foo');
  332. expect(res).to.be.eq('"foo"');
  333. });
  334. it('returns a string representation of the given empty string', function () {
  335. const res = format('%j', '');
  336. expect(res).to.be.eq('""');
  337. });
  338. it('returns a string representation of the given number', function () {
  339. const res = format('%j', 10);
  340. expect(res).to.be.eq('10');
  341. });
  342. it('returns a string representation of the given zero', function () {
  343. const res = format('%j', 0);
  344. expect(res).to.be.eq('0');
  345. });
  346. it('returns a string representation of the given NaN', function () {
  347. const res = format('%j', NaN);
  348. expect(res).to.be.eq('null');
  349. });
  350. it('returns a string representation of the given Infinity', function () {
  351. const res = format('%j', Infinity);
  352. expect(res).to.be.eq('null');
  353. });
  354. it('returns a string representation of the given true', function () {
  355. const res = format('%j', true);
  356. expect(res).to.be.eq('true');
  357. });
  358. it('returns a string representation of the given false', function () {
  359. const res = format('%j', false);
  360. expect(res).to.be.eq('false');
  361. });
  362. it('returns a string representation of the given array', function () {
  363. const res = format('%j', [1, 2, 3]);
  364. expect(res).to.be.eq('[1,2,3]');
  365. });
  366. it('returns a string representation of the given empty array', function () {
  367. const res = format('%j', []);
  368. expect(res).to.be.eq('[]');
  369. });
  370. it('returns a string representation of the given key-value object', function () {
  371. const res = format('%j', {foo: 'bar'});
  372. expect(res).to.be.eq('{"foo":"bar"}');
  373. });
  374. it('returns a string representation of the given object without keys', function () {
  375. const res = format('%j', {});
  376. expect(res).to.be.eq('{}');
  377. });
  378. it('returns a string representation of the given date instance', function () {
  379. const date = new Date();
  380. const res = format('%j', date);
  381. expect(res).to.be.eq(`"${date.toISOString()}"`);
  382. });
  383. it('returns a string representation of the given map instance', function () {
  384. const res = format('%j', new Map());
  385. expect(res).to.be.eq('{}');
  386. });
  387. it('returns a string representation of the given class instance', function () {
  388. class MyClass {}
  389. const res = format('%j', new MyClass());
  390. expect(res).to.be.eq('{}');
  391. });
  392. it('returns a string representation of the given function', function () {
  393. const res = format('%j', function () {});
  394. expect(res).to.be.eq('undefined');
  395. });
  396. it('returns a string representation of the given anonymous function', function () {
  397. const res = format('%j', () => undefined);
  398. expect(res).to.be.eq('undefined');
  399. });
  400. it('returns a string representation of the given named function', function () {
  401. function foo() {}
  402. const res = format('%j', foo);
  403. expect(res).to.be.eq('undefined');
  404. });
  405. it('returns a string representation of the given anonymous class', function () {
  406. const res = format('%j', class {});
  407. expect(res).to.be.eq('undefined');
  408. });
  409. it('returns a string representation of the given named class', function () {
  410. class MyClass {}
  411. const res = format('%j', MyClass);
  412. expect(res).to.be.eq('undefined');
  413. });
  414. it('returns a string representation of the given class constructor', function () {
  415. class MyClass {}
  416. const res = format('%j', MyClass.constructor);
  417. expect(res).to.be.eq('undefined');
  418. });
  419. it('returns a string representation of the given symbol', function () {
  420. const res = format('%j', Symbol());
  421. expect(res).to.be.eq('undefined');
  422. });
  423. it('returns a string representation of the given named symbol', function () {
  424. const res = format('%j', Symbol('foo'));
  425. expect(res).to.be.eq('undefined');
  426. });
  427. it('returns a string representation of the given undefined', function () {
  428. const res = format('%j', undefined);
  429. expect(res).to.be.eq('undefined');
  430. });
  431. it('returns a string representation of the given null', function () {
  432. const res = format('%j', null);
  433. expect(res).to.be.eq('null');
  434. });
  435. });
  436. describe('%v', function () {
  437. it('returns a string representation of the given string', function () {
  438. const res = format('%v', 'foo');
  439. expect(res).to.be.eq('"foo"');
  440. });
  441. it('returns a string representation of the given empty string', function () {
  442. const res = format('%v', '');
  443. expect(res).to.be.eq('""');
  444. });
  445. it('returns a string representation of the given number', function () {
  446. const res = format('%v', 10);
  447. expect(res).to.be.eq('10');
  448. });
  449. it('returns a string representation of the given zero', function () {
  450. const res = format('%v', 0);
  451. expect(res).to.be.eq('0');
  452. });
  453. it('returns a string representation of the given NaN', function () {
  454. const res = format('%v', NaN);
  455. expect(res).to.be.eq('NaN');
  456. });
  457. it('returns a string representation of the given Infinity', function () {
  458. const res = format('%v', Infinity);
  459. expect(res).to.be.eq('Infinity');
  460. });
  461. it('returns a string representation of the given true', function () {
  462. const res = format('%v', true);
  463. expect(res).to.be.eq('true');
  464. });
  465. it('returns a string representation of the given false', function () {
  466. const res = format('%v', false);
  467. expect(res).to.be.eq('false');
  468. });
  469. it('returns a string representation of the given array', function () {
  470. const res = format('%v', [1, 2, 3]);
  471. expect(res).to.be.eq('Array');
  472. });
  473. it('returns a string representation of the given empty array', function () {
  474. const res = format('%v', []);
  475. expect(res).to.be.eq('Array');
  476. });
  477. it('returns a string representation of the given key-value object', function () {
  478. const res = format('%v', {foo: 'bar'});
  479. expect(res).to.be.eq('Object');
  480. });
  481. it('returns a string representation of the given object without keys', function () {
  482. const res = format('%v', {});
  483. expect(res).to.be.eq('Object');
  484. });
  485. it('returns a string representation of the given object without prototype', function () {
  486. const res = format('%v', Object.create(null));
  487. expect(res).to.be.eq('Object');
  488. });
  489. it('returns a string representation of the given date instance', function () {
  490. const res = format('%v', new Date());
  491. expect(res).to.be.eq('Date');
  492. });
  493. it('returns a string representation of the given map instance', function () {
  494. const res = format('%v', new Map());
  495. expect(res).to.be.eq('Map');
  496. });
  497. it('returns a string representation of the given class instance', function () {
  498. class MyClass {}
  499. const res = format('%v', new MyClass());
  500. expect(res).to.be.eq('MyClass (instance)');
  501. });
  502. it('returns a string representation of the given function', function () {
  503. const res = format('%v', function () {});
  504. expect(res).to.be.eq('Function');
  505. });
  506. it('returns a string representation of the given anonymous function', function () {
  507. const res = format('%v', () => undefined);
  508. expect(res).to.be.eq('Function');
  509. });
  510. it('returns a string representation of the given named function', function () {
  511. function foo() {}
  512. const res = format('%v', foo);
  513. expect(res).to.be.eq('Function');
  514. });
  515. it('returns a string representation of the given anonymous class', function () {
  516. const res = format('%v', class {});
  517. expect(res).to.be.eq('Class');
  518. });
  519. it('returns a string representation of the given named class', function () {
  520. class MyClass {}
  521. const res = format('%v', MyClass);
  522. expect(res).to.be.eq('MyClass');
  523. });
  524. it('returns a string representation of the given class constructor', function () {
  525. class MyClass {}
  526. const res = format('%v', MyClass.constructor);
  527. expect(res).to.be.eq('Function');
  528. });
  529. it('returns a string representation of the given symbol', function () {
  530. const res = format('%v', Symbol());
  531. expect(res).to.be.eq('Symbol');
  532. });
  533. it('returns a string representation of the given named symbol', function () {
  534. const res = format('%v', Symbol('foo'));
  535. expect(res).to.be.eq('Symbol');
  536. });
  537. it('returns a string representation of the given undefined', function () {
  538. const res = format('%v', undefined);
  539. expect(res).to.be.eq('undefined');
  540. });
  541. it('returns a string representation of the given null', function () {
  542. const res = format('%v', null);
  543. expect(res).to.be.eq('null');
  544. });
  545. });
  546. describe('%l', function () {
  547. describe('non-array values', function () {
  548. it('returns a string representation of the given string', function () {
  549. const res = format('%l', 'foo');
  550. expect(res).to.be.eq('"foo"');
  551. });
  552. it('returns a string representation of the given empty string', function () {
  553. const res = format('%l', '');
  554. expect(res).to.be.eq('""');
  555. });
  556. it('returns a string representation of the given number', function () {
  557. const res = format('%l', 10);
  558. expect(res).to.be.eq('10');
  559. });
  560. it('returns a string representation of the given zero', function () {
  561. const res = format('%l', 0);
  562. expect(res).to.be.eq('0');
  563. });
  564. it('returns a string representation of the given NaN', function () {
  565. const res = format('%l', NaN);
  566. expect(res).to.be.eq('NaN');
  567. });
  568. it('returns a string representation of the given Infinity', function () {
  569. const res = format('%l', Infinity);
  570. expect(res).to.be.eq('Infinity');
  571. });
  572. it('returns a string representation of the given true', function () {
  573. const res = format('%l', true);
  574. expect(res).to.be.eq('true');
  575. });
  576. it('returns a string representation of the given false', function () {
  577. const res = format('%l', false);
  578. expect(res).to.be.eq('false');
  579. });
  580. it('returns a string representation of the given key-value object', function () {
  581. const res = format('%l', {foo: 'bar'});
  582. expect(res).to.be.eq('Object');
  583. });
  584. it('returns a string representation of the given object without keys', function () {
  585. const res = format('%l', {});
  586. expect(res).to.be.eq('Object');
  587. });
  588. it('returns a string representation of the given object without prototype', function () {
  589. const res = format('%l', Object.create(null));
  590. expect(res).to.be.eq('Object');
  591. });
  592. it('returns a string representation of the given date instance', function () {
  593. const res = format('%l', new Date());
  594. expect(res).to.be.eq('Date');
  595. });
  596. it('returns a string representation of the given map instance', function () {
  597. const res = format('%l', new Map());
  598. expect(res).to.be.eq('Map');
  599. });
  600. it('returns a string representation of the given class instance', function () {
  601. class MyClass {}
  602. const res = format('%l', new MyClass());
  603. expect(res).to.be.eq('MyClass (instance)');
  604. });
  605. it('returns a string representation of the given function', function () {
  606. const res = format('%l', function () {});
  607. expect(res).to.be.eq('Function');
  608. });
  609. it('returns a string representation of the given anonymous function', function () {
  610. const res = format('%l', () => undefined);
  611. expect(res).to.be.eq('Function');
  612. });
  613. it('returns a string representation of the given named function', function () {
  614. function foo() {}
  615. const res = format('%l', foo);
  616. expect(res).to.be.eq('Function');
  617. });
  618. it('returns a string representation of the given anonymous class', function () {
  619. const res = format('%l', class {});
  620. expect(res).to.be.eq('Class');
  621. });
  622. it('returns a string representation of the given named class', function () {
  623. class MyClass {}
  624. const res = format('%l', MyClass);
  625. expect(res).to.be.eq('MyClass');
  626. });
  627. it('returns a string representation of the given class constructor', function () {
  628. class MyClass {}
  629. const res = format('%l', MyClass.constructor);
  630. expect(res).to.be.eq('Function');
  631. });
  632. it('returns a string representation of the given symbol', function () {
  633. const res = format('%l', Symbol());
  634. expect(res).to.be.eq('Symbol');
  635. });
  636. it('returns a string representation of the given named symbol', function () {
  637. const res = format('%l', Symbol('foo'));
  638. expect(res).to.be.eq('Symbol');
  639. });
  640. it('returns a string representation of the given undefined', function () {
  641. const res = format('%l', undefined);
  642. expect(res).to.be.eq('undefined');
  643. });
  644. it('returns a string representation of the given null', function () {
  645. const res = format('%l', null);
  646. expect(res).to.be.eq('null');
  647. });
  648. });
  649. describe('array values', function () {
  650. it('adds a separator between the given elements', function () {
  651. const res = format('%l', ['foo', 1, true]);
  652. expect(res).to.be.eq('"foo", 1, true');
  653. });
  654. it('returns a string representation of the given empty array', function () {
  655. const res = format('%l', []);
  656. expect(res).to.be.eq('Array');
  657. });
  658. it('returns an element representation of the given string', function () {
  659. const res = format('%l', ['foo']);
  660. expect(res).to.be.eq('"foo"');
  661. });
  662. it('returns an element representation of the given empty string', function () {
  663. const res = format('%l', ['']);
  664. expect(res).to.be.eq('""');
  665. });
  666. it('returns an element representation of the given number', function () {
  667. const res = format('%l', [10]);
  668. expect(res).to.be.eq('10');
  669. });
  670. it('returns an element representation of the given zero', function () {
  671. const res = format('%l', [0]);
  672. expect(res).to.be.eq('0');
  673. });
  674. it('returns an element representation of the given NaN', function () {
  675. const res = format('%l', [NaN]);
  676. expect(res).to.be.eq('NaN');
  677. });
  678. it('returns an element representation of the given Infinity', function () {
  679. const res = format('%l', [Infinity]);
  680. expect(res).to.be.eq('Infinity');
  681. });
  682. it('returns an element representation of the given true', function () {
  683. const res = format('%l', [true]);
  684. expect(res).to.be.eq('true');
  685. });
  686. it('returns an element representation of the given false', function () {
  687. const res = format('%l', [false]);
  688. expect(res).to.be.eq('false');
  689. });
  690. it('returns an element representation of the given key-value object', function () {
  691. const res = format('%l', [{foo: 'bar'}]);
  692. expect(res).to.be.eq('Object');
  693. });
  694. it('returns an element representation of the given object without keys', function () {
  695. const res = format('%l', [{}]);
  696. expect(res).to.be.eq('Object');
  697. });
  698. it('returns an element representation of the given object without prototype', function () {
  699. const res = format('%l', [Object.create(null)]);
  700. expect(res).to.be.eq('Object');
  701. });
  702. it('returns an element representation of the given date instance', function () {
  703. const res = format('%l', [new Date()]);
  704. expect(res).to.be.eq('Date');
  705. });
  706. it('returns an element representation of the given map instance', function () {
  707. const res = format('%l', [new Map()]);
  708. expect(res).to.be.eq('Map');
  709. });
  710. it('returns an element representation of the given class instance', function () {
  711. class MyClass {}
  712. const res = format('%l', [new MyClass()]);
  713. expect(res).to.be.eq('MyClass (instance)');
  714. });
  715. it('returns an element representation of the given function', function () {
  716. const res = format('%l', [function () {}]);
  717. expect(res).to.be.eq('Function');
  718. });
  719. it('returns an element representation of the given anonymous function', function () {
  720. const res = format('%l', [() => undefined]);
  721. expect(res).to.be.eq('Function');
  722. });
  723. it('returns an element representation of the given named function', function () {
  724. function foo() {}
  725. const res = format('%l', [foo]);
  726. expect(res).to.be.eq('Function');
  727. });
  728. it('returns an element representation of the given anonymous class', function () {
  729. const res = format('%l', [class {}]);
  730. expect(res).to.be.eq('Class');
  731. });
  732. it('returns an element representation of the given named class', function () {
  733. class MyClass {}
  734. const res = format('%l', [MyClass]);
  735. expect(res).to.be.eq('MyClass');
  736. });
  737. it('returns an element representation of the given class constructor', function () {
  738. class MyClass {}
  739. const res = format('%l', [MyClass.constructor]);
  740. expect(res).to.be.eq('Function');
  741. });
  742. it('returns an element representation of the given symbol', function () {
  743. const res = format('%l', [Symbol()]);
  744. expect(res).to.be.eq('Symbol');
  745. });
  746. it('returns an element representation of the given named symbol', function () {
  747. const res = format('%l', [Symbol('foo')]);
  748. expect(res).to.be.eq('Symbol');
  749. });
  750. it('returns an element representation of the given undefined', function () {
  751. const res = format('%l', [undefined]);
  752. expect(res).to.be.eq('undefined');
  753. });
  754. it('returns an element representation of the given null', function () {
  755. const res = format('%l', [null]);
  756. expect(res).to.be.eq('null');
  757. });
  758. });
  759. });
  760. });