"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 {
      (0, _replaceBufferNonRecursive().default)('hello world', 'l', '!');
    } catch (err) {
      (0, _chai().expect)(err.message).to.equal('replaceBuffer expect to get Buffer, got string instead');
    }
  });
});