UNPKG

@yoroi/common

Version:

The Common package of Yoroi SDK

72 lines (71 loc) 2.57 kB
"use strict"; var _strings = require("./strings"); describe('asConcatenedString', () => { it('should return undefined for null input', () => { expect((0, _strings.asConcatenedString)(null)).toBeUndefined(); }); it('should return anything else', () => { expect((0, _strings.asConcatenedString)({})).toBeUndefined(); expect((0, _strings.asConcatenedString)(['1', 1])).toBeUndefined(); expect((0, _strings.asConcatenedString)(1)).toBeUndefined(); }); it('should return undefined for undefined input', () => { expect((0, _strings.asConcatenedString)(undefined)).toBeUndefined(); }); it('should return the original string for string input', () => { expect((0, _strings.asConcatenedString)('hello')).toBe('hello'); }); it('should join array of strings into a single string', () => { expect((0, _strings.asConcatenedString)(['h', 'e', 'l', 'l', 'o'])).toBe('hello'); }); }); describe('truncateString', () => { it('should return the original string if its length is less than or equal to maxLength', () => { const value = 'hello'; const maxLength = 10; const result = (0, _strings.truncateString)({ value, maxLength }); expect(result).toBe(value); }); it('should truncate the string and add separator if its length is greater than maxLength', () => { const value = 'This is a long string'; const maxLength = 10; const separator = '-'; const result = (0, _strings.truncateString)({ value, maxLength, separator }); expect(result).toBe('This-ring'); }); it('should truncate the string and add separator at the correct position', () => { const value = 'This is a long string'; const maxLength = 15; const separator = '...'; const result = (0, _strings.truncateString)({ value, maxLength, separator }); expect(result).toBe('This i...string'); }); }); describe('hexToAscii', () => { test('converts hex to ascii correctly', () => { expect((0, _strings.hexToAscii)('68656c6c6f')).toBe('hello'); expect((0, _strings.hexToAscii)('776f726c64')).toBe('world'); }); test('returns empty string for invalid hex', () => { expect((0, _strings.hexToAscii)('123')).toBe(''); expect((0, _strings.hexToAscii)('zzzz')).toBe(''); }); }); describe('asciiToHex', () => { test('converts ascii to hex correctly', () => { expect((0, _strings.asciiToHex)('hello')).toBe('68656c6c6f'); expect((0, _strings.asciiToHex)('world')).toBe('776f726c64'); }); }); //# sourceMappingURL=strings.test.js.map