UNPKG

3.95 kBJavaScriptView Raw
1"use strict";
2/**
3 * This file is part of the @egodigital/egoose distribution.
4 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
5 *
6 * @egodigital/egoose is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * @egodigital/egoose is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19const assert = require("assert");
20const mocha_1 = require("mocha");
21const index_1 = require("../index");
22mocha_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//# sourceMappingURL=toStringSafe.js.map
\No newline at end of file