UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

50 lines (42 loc) 1.76 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _replaceBufferNonRecursive() { const data = _interopRequireDefault(require("../../utils/buffer/replace-buffer-non-recursive")); _replaceBufferNonRecursive = function () { return data; }; return data; } describe('ReplaceBuffer', () => { it('should replace an old string with a new string', () => { const buffer = Buffer.from('hello world'); (0, _chai().expect)((0, _replaceBufferNonRecursive().default)(buffer, 'world', 'david').toString()).to.equal('hello david'); }); it('should not change the buffer if nothing found', () => { const buffer = Buffer.from('hello world!'); (0, _chai().expect)((0, _replaceBufferNonRecursive().default)(buffer, 'non', 'exist').toString()).to.equal('hello world!'); }); it('should replace multiple occurrences', () => { const buffer = Buffer.from('hello world'); (0, _chai().expect)((0, _replaceBufferNonRecursive().default)(buffer, 'l', '!').toString()).to.equal('he!!o wor!d'); }); it('should return a Buffer instance', () => { const buffer = Buffer.from('hello world'); (0, _chai().expect)((0, _replaceBufferNonRecursive().default)(buffer, 'l', '!')).to.be.instanceof(Buffer); }); it('should throw an error if non-buffer argument was passed', () => { try { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! (0, _replaceBufferNonRecursive().default)('hello world', 'l', '!'); } catch (err) { (0, _chai().expect)(err.message).to.equal('replaceBuffer expect to get Buffer, got string instead'); } }); });