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 index_1 = require("../index");
|
22 | mocha_1.describe('#toStringSafe()', function () {
|
23 | mocha_1.describe('(null)', function () {
|
24 | mocha_1.it('should return empty string when the value is (null)', function () {
|
25 | const RES = index_1.toStringSafe(null);
|
26 | assert.ok('string' === typeof RES);
|
27 | assert.equal(RES, '');
|
28 | assert.strictEqual(RES, '');
|
29 | });
|
30 | mocha_1.it('should return custom default value when the value is (null)', function () {
|
31 | const RES = index_1.toStringSafe(null, 'MK');
|
32 | assert.ok('string' === typeof RES);
|
33 | assert.equal(RES, 'MK');
|
34 | assert.strictEqual(RES, 'MK');
|
35 | });
|
36 | });
|
37 | mocha_1.describe('(undefined)', function () {
|
38 | mocha_1.it('should return empty string when the value is (undefined)', function () {
|
39 | const RES = index_1.toStringSafe(undefined);
|
40 | assert.ok('string' === typeof RES);
|
41 | assert.equal(RES, '');
|
42 | assert.strictEqual(RES, '');
|
43 | });
|
44 | mocha_1.it('should return custom default value when the value is (undefined)', function () {
|
45 | const RES = index_1.toStringSafe(undefined, 'TM');
|
46 | assert.ok('string' === typeof RES);
|
47 | assert.equal(RES, 'TM');
|
48 | assert.strictEqual(RES, 'TM');
|
49 | });
|
50 | });
|
51 | mocha_1.describe('String', function () {
|
52 | mocha_1.it('should return same value when the value is of type String', function () {
|
53 | const RES = index_1.toStringSafe('JS');
|
54 | assert.ok('string' === typeof RES);
|
55 | assert.equal(RES, 'JS');
|
56 | assert.strictEqual(RES, 'JS');
|
57 | });
|
58 | });
|
59 | mocha_1.describe('Number', function () {
|
60 | mocha_1.it('should return string representation when the value is of type integer', function () {
|
61 | for (let i = 0; i < 1000; i++) {
|
62 | const RES = index_1.toStringSafe(i);
|
63 | assert.ok('string' === typeof RES);
|
64 | assert.equal(RES, '' + i);
|
65 | assert.strictEqual(RES, '' + i);
|
66 | }
|
67 | });
|
68 | mocha_1.it('should return string representation when the value is of type float', function () {
|
69 | for (let i = 0; i < 1000; i++) {
|
70 | const NR = i / 10.0;
|
71 | const RES = index_1.toStringSafe(NR);
|
72 | assert.ok('string' === typeof RES);
|
73 | assert.equal(RES, '' + NR);
|
74 | assert.strictEqual(RES, '' + NR);
|
75 | }
|
76 | });
|
77 | });
|
78 | mocha_1.describe('Object', function () {
|
79 | mocha_1.it('should return result of #toString() method when the value is an object', function () {
|
80 | const RES = index_1.toStringSafe({
|
81 | toString: () => {
|
82 | return 'MK+TM';
|
83 | },
|
84 | });
|
85 | assert.ok('string' === typeof RES);
|
86 | assert.equal(RES, 'MK+TM');
|
87 | assert.strictEqual(RES, 'MK+TM');
|
88 | });
|
89 | });
|
90 | });
|
91 |
|
\ | No newline at end of file |