UNPKG

stringer-tools

Version:
217 lines (162 loc) 5.34 kB
var stringerTools = require('./index'); var assert = require('assert'); describe('stringerTools', function() { describe('wrap', function() { it('should wrap a given string by another given string', function() { // Arrange let expected = 'DevChengaDev'; // Act let actual = stringerTools.wrap('Chenga', 'Dev'); // Assert assert.equal(actual, expected); }); }); describe('length', function() { it('should return the length of the given string', function() { // Arrange let expectedLength = 6; // Act let actualLength = stringerTools.length('Chenga'); // Assert assert.equal(actualLength, expectedLength); }); }); describe('startBy', function() { it('adds given prefix to a given string', function() { // Arrange let expectedString = 'DevChenga'; // Act let actualString = stringerTools.startBy('Chenga', 'Dev'); // Assert assert.equal(actualString, expectedString); }); }); describe('endBy', function() { it('adds given suffix to a given string', function() { // Arrange let expectedString = 'ChengaDev'; // Act let actualString = stringerTools.endBy('Chenga', 'Dev'); // Assert assert.equal(actualString, expectedString); }); }); describe('isNullOrEmpty', function() { it('string contains undefined value', function() { // Arrange let expected = true; // Act let actual = stringerTools.isNullOrEmpty(undefined); // Assert assert.equal(actual, expected); }); it('string contains null value', function() { // Arrange let expected = true; // Act let actual = stringerTools.isNullOrEmpty(null); // Assert assert.equal(actual, expected); }); it("string contains '' value", function() { // Arrange let expected = true; // Act let actual = stringerTools.isNullOrEmpty(''); // Assert assert.equal(actual, expected); }); it("string contains value other than ''", function() { // Arrange let expected = false; // Act let actual = stringerTools.isNullOrEmpty('Chenga'); // Assert assert.equal(actual, expected); }); }); describe('wordsCount', function() { it('one word', function() { // Arrange let expectedWordCount = 1; // Act let actualWordCount = stringerTools.wordsCount('Chenga'); // Assert assert.equal(actualWordCount, expectedWordCount); }); it('more than one word', function() { // Arrange let expectedWordCount = 3; // Act let actualWordCount = stringerTools.wordsCount('Dev Chenga Dev'); // Assert assert.equal(actualWordCount, expectedWordCount); }); }); describe('containsChar', function() { it('consider case - string contains lower case char', function() { // Arrange let expected = true; // Act let actual = stringerTools.containsChar('Chenga', 'e'); // Assert assert.equal(actual, expected); }); it('consider case - string contains higher case char', function() { // Arrange let expected = true; // Act let actual = stringerTools.containsChar('Chenga', 'C'); // Assert assert.equal(actual, expected); }); it('consider case - string NOT contains lower case char', function() { // Arrange let expected = false; // Act let actual = stringerTools.containsChar('Chenga', 'z'); // Assert assert.equal(actual, expected); }); it('consider case - string NOT contains higher case char', function() { // Arrange let expected = false; // Act let actual = stringerTools.containsChar('Chenga', 'Z'); // Assert assert.equal(actual, expected); }); it('consider case - string NOT contains lower case char - but contains the char in higher case', function() { // Arrange let expected = false; // Act let actual = stringerTools.containsChar('Chenga', 'c'); // Assert assert.equal(actual, expected); }); it('consider case - string NOT contains lower case char - but contains the char in lower case', function() { // Arrange let expected = false; // Act let actual = stringerTools.containsChar('Chenga', 'E'); // Assert assert.equal(actual, expected); }); it('NOT consider case - string contains higher case char - but parameter is lower case', function() { // Arrange let expected = true; // Act let actual = stringerTools.containsChar('Chenga', 'c', false); // Assert assert.equal(actual, expected); }); it('NOT consider case - string contains lower case char - but parameter is higher case', function() { // Arrange let expected = true; // Act let actual = stringerTools.containsChar('Chenga', 'E', false); // Assert assert.equal(actual, expected); }); }); });