1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const assert = require("assert");
|
20 | const mocha_1 = require("mocha");
|
21 | const strings_1 = require("../strings");
|
22 | mocha_1.describe('#format()', async function () {
|
23 | mocha_1.it('no format providers', async function () {
|
24 | for (let i = 0; i < 100; i++) {
|
25 | const FORMAT_STR_PARTS = [];
|
26 | const FORMAT_ARGS = [];
|
27 | const EXPECTED_STR_PARTS = [];
|
28 | for (let j = 0; j <= i; j++) {
|
29 | FORMAT_STR_PARTS.push(`{${j}}`);
|
30 | FORMAT_ARGS.push(j * 5979);
|
31 | EXPECTED_STR_PARTS.push(`${j * 5979}`);
|
32 | }
|
33 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
34 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
35 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
36 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
37 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
38 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
39 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
40 | }
|
41 | });
|
42 | mocha_1.it('lower', async function () {
|
43 | const EXPECTED_STR = 'tm MK TM mk';
|
44 | const ACTUAL_STR = strings_1.format('{0:lower} {1} {0} {1:lower}', 'TM', 'MK');
|
45 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
46 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
47 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
48 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
49 | });
|
50 | mocha_1.it('upper', async function () {
|
51 | const EXPECTED_STR = 'TM mk Tm MK';
|
52 | const ACTUAL_STR = strings_1.format('{0:upper} {1} {0} {1:upper}', 'Tm', 'mk');
|
53 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
54 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
55 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
56 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
57 | });
|
58 | mocha_1.it('ending_space', async function () {
|
59 | for (let i = 0; i < 100; i++) {
|
60 | const FORMAT_STR_PARTS = [];
|
61 | const FORMAT_ARGS = [];
|
62 | const EXPECTED_STR_PARTS = [];
|
63 | for (let j = 0; j <= i; j++) {
|
64 | FORMAT_STR_PARTS.push(`{${j}:ending_space}`);
|
65 | FORMAT_ARGS.push(j * 5979);
|
66 | EXPECTED_STR_PARTS.push(`${j * 5979} `);
|
67 | }
|
68 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
69 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
70 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
71 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
72 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
73 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
74 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
75 | }
|
76 | });
|
77 | mocha_1.it('leading_space', async function () {
|
78 | for (let i = 0; i < 100; i++) {
|
79 | const FORMAT_STR_PARTS = [];
|
80 | const FORMAT_ARGS = [];
|
81 | const EXPECTED_STR_PARTS = [];
|
82 | for (let j = 0; j <= i; j++) {
|
83 | FORMAT_STR_PARTS.push(`{${j}:leading_space}`);
|
84 | FORMAT_ARGS.push(j * 5979);
|
85 | EXPECTED_STR_PARTS.push(` ${j * 5979}`);
|
86 | }
|
87 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
88 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
89 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
90 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
91 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
92 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
93 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
94 | }
|
95 | });
|
96 | mocha_1.it('trim', async function () {
|
97 | for (let i = 0; i < 100; i++) {
|
98 | const FORMAT_STR_PARTS = [];
|
99 | const FORMAT_ARGS = [];
|
100 | const EXPECTED_STR_PARTS = [];
|
101 | for (let j = 0; j <= i; j++) {
|
102 | FORMAT_STR_PARTS.push(`{${j}:trim}`);
|
103 | FORMAT_ARGS.push(`${j % 2 === 0 ? ' ' : ''}${j * 5979}${j % 2 === 0 ? ' ' : ''}`);
|
104 | EXPECTED_STR_PARTS.push(`${j * 5979}`);
|
105 | }
|
106 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
107 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
108 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
109 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
110 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
111 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
112 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
113 | }
|
114 | });
|
115 | mocha_1.it('surround', async function () {
|
116 | for (let i = 0; i < 100; i++) {
|
117 | const FORMAT_STR_PARTS = [];
|
118 | const FORMAT_ARGS = [];
|
119 | const EXPECTED_STR_PARTS = [];
|
120 | for (let j = 0; j <= i; j++) {
|
121 | FORMAT_STR_PARTS.push(`{${j}:surround}`);
|
122 | FORMAT_ARGS.push(`${j * 5979}`);
|
123 | EXPECTED_STR_PARTS.push(`'${j * 5979}'`);
|
124 | }
|
125 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
126 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
127 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
128 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
129 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
130 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
131 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
132 | }
|
133 | });
|
134 | mocha_1.it('trim,surround', async function () {
|
135 | for (let i = 0; i < 100; i++) {
|
136 | const FORMAT_STR_PARTS = [];
|
137 | const FORMAT_ARGS = [];
|
138 | const EXPECTED_STR_PARTS = [];
|
139 | for (let j = 0; j <= i; j++) {
|
140 | FORMAT_STR_PARTS.push(`{${j}:trim,surround}`);
|
141 | FORMAT_ARGS.push(`${j % 2 === 0 ? ' ' : ''}${j * 5979}${j % 2 === 0 ? ' ' : ''}`);
|
142 | EXPECTED_STR_PARTS.push(`'${j * 5979}'`);
|
143 | }
|
144 | const FORMAT_STR = FORMAT_STR_PARTS.join(' --- ');
|
145 | const ACTUAL_STR = strings_1.format.apply(null, [FORMAT_STR].concat(FORMAT_ARGS));
|
146 | const EXPECTED_STR = EXPECTED_STR_PARTS.join(' --- ');
|
147 | assert.equal(ACTUAL_STR.length, EXPECTED_STR.length);
|
148 | assert.strictEqual(ACTUAL_STR.length, EXPECTED_STR.length);
|
149 | assert.equal(ACTUAL_STR, EXPECTED_STR);
|
150 | assert.strictEqual(ACTUAL_STR, EXPECTED_STR);
|
151 | }
|
152 | });
|
153 | });
|
154 |
|
\ | No newline at end of file |