UNPKG

4.21 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");
22const WHITESPACES = " \t\r\n";
23mocha_1.describe('#normalizeString()', function () {
24 mocha_1.describe('null', function () {
25 mocha_1.it('should return empty string if input is (null)', function () {
26 const RES = index_1.normalizeString(null);
27 assert.ok('string' === typeof RES);
28 assert.equal(RES, '');
29 assert.strictEqual(RES, '');
30 });
31 });
32 mocha_1.describe('undefined', function () {
33 mocha_1.it('should return empty string if input is (undefined)', function () {
34 const RES = index_1.normalizeString(undefined);
35 assert.ok('string' === typeof RES);
36 assert.equal(RES, '');
37 assert.strictEqual(RES, '');
38 });
39 });
40 mocha_1.describe('String', function () {
41 mocha_1.it('should return empty string if input is an empty string', function () {
42 const RES = index_1.normalizeString('');
43 assert.ok('string' === typeof RES);
44 assert.equal(RES, '');
45 assert.strictEqual(RES, '');
46 });
47 mocha_1.it('should return empty string if input contains whitespaces only', function () {
48 for (let i = 1; i <= 1000; i++) {
49 let str = '';
50 for (let j = 0; j < i; j++) {
51 str += WHITESPACES[j % WHITESPACES.length];
52 }
53 const RES = index_1.normalizeString(str);
54 assert.ok('string' === typeof RES);
55 assert.equal(RES, '');
56 assert.strictEqual(RES, '');
57 }
58 });
59 mocha_1.it('should return lower case, trimmed version of an input string', function () {
60 const RES = index_1.normalizeString(' Mk + tM ');
61 assert.ok('string' === typeof RES);
62 assert.equal(RES, 'mk + tm');
63 assert.strictEqual(RES, 'mk + tm');
64 });
65 });
66 mocha_1.describe('Number', function () {
67 mocha_1.it('should return "0" if input is 0', function () {
68 const RES = index_1.normalizeString(0);
69 assert.ok('string' === typeof RES);
70 assert.equal(RES, '0');
71 assert.strictEqual(RES, '0');
72 });
73 });
74 mocha_1.describe('Object', function () {
75 mocha_1.it('should return empty string if #toString() of input returns empty string', function () {
76 const RES = index_1.normalizeString({
77 toString: () => '',
78 });
79 assert.ok('string' === typeof RES);
80 assert.equal(RES, '');
81 assert.strictEqual(RES, '');
82 });
83 mocha_1.it('should return empty string if #toString() of input contains whitespaces only', function () {
84 for (let i = 1; i <= 1000; i++) {
85 let str = '';
86 for (let j = 0; j < i; j++) {
87 str += WHITESPACES[j % WHITESPACES.length];
88 }
89 const RES = index_1.normalizeString({
90 toString: () => str,
91 });
92 assert.ok('string' === typeof RES);
93 assert.equal(RES, '');
94 assert.strictEqual(RES, '');
95 }
96 });
97 });
98});
99//# sourceMappingURL=normalizeString.js.map
\No newline at end of file