<commit_before>import R from 'ramda';
import chai, { expect } from 'chai';
import dirtyChai from 'dirty-chai';

import * as Patch from '../src/patch';
import * as CONST from '../src/constants';

import * as Helper from './helpers';

chai.use(dirtyChai);

describe('Patch', () => {
  // constructors
  describe('createPatch', () => {
    it('should return Patch that is an object', () => {
      const patch = Patch.createPatch();

      expect(patch).is.an('object');
    });
    it('should have key: nodes === {}', () => {
      const patch = Patch.createPatch();

      expect(patch)
        .to.have.property('nodes')
        .that.is.an('object')
        .that.is.empty();
    });
    it('should have key: links === {}', () => {
      const patch = Patch.createPatch();

      expect(patch)
        .to.have.property('links')
        .that.is.an('object')
        .that.is.empty();
    });
  });
  describe('duplicatePatch', () => {
    const patch = { nodes: {}, label: 'test' };
    it('should return new patch (not the same object)', () => {
      const newPatch = Patch.duplicatePatch(patch);
      expect(newPatch)
        .to.be.an('object')
        .and.not.to.be.equal(patch);
    });
    it('should be deeply cloned (not the same nested objects)', () => {
      const newPatch = Patch.duplicatePatch(patch);
      expect(newPatch)
        .have.property('label')
        .that.equal(patch.label);
      expect(newPatch)
        .have.property('nodes')
        .that.not.equal(patch.nodes);
    });
  });

  // properties
  describe('getPatchLabel', () => {
    it('should return empty String for empty patch object', () => {
      expect(Patch.getPatchLabel({})).to.be.equal('');
    });
    it('should return patch label', () => {
      const label = 'patchLabel';
      expect(Patch.getPatchLabel({ label })).to.be.equal(label);
    });
  });
  describe('setPatchLabel', () => {
    it('should return patch with new label', () => {
      const newLabel = 'new label';
      const patch = { label: 'old label' };
      const newPatch = Patch.setPatchLabel(newLabel, patch);

      expect(newPatch)
        .to.have.property('label')
        .that.is.a('string')
        .that.equals(newLabel);
    });
    it('should always set a string to label', () => {
      expect(Patch.setPatchLabel('test', {}))
        .to.have.property('label')
        .that.equals('test');
      expect(Patch.setPatchLabel(5, {}))
        .to.have.property('label')
        .that.equals('5');
      expect(Patch.setPatchLabel([1, 2], {}))
        .to.have.property('label')
        .that.equals('1,2');
      expect(Patch.setPatchLabel({}, {}))
        .to.have.property('label')
        .that.equals('[object Object]');
    });
  });
  describe('listImpls', () => {
    it('should return empty array for empty patch', () => {
      expect(Patch.listImpls({}))
        .to.be.instanceof(Array)
        .to.be.empty();
    });
    it('should return array with keys: `js`, `espruino`', () => {
      const patch = {
        impls: {
          js: '',
          espruino: '',
        },
      };
      expect(Patch.listImpls(patch))
        .to.be.an('array')
        .to.have.members(['js', 'espruino']);
    });
  });
  describe('hasImpl', () => {
    it('should return false for empty', () => {
      expect(Patch.hasImpl(['js'], {})).to.be.false();
    });
    it('should return false if impl not found', () => {
      const patch = {
        impls: {
          js: '//ok',
        },
      };
      expect(Patch.hasImpl(['cpp'], patch)).to.be.false();
    });
    it('should return true for the only correct impl', () => {
      const patch = {
        impls: {
          js: '//ok',
        },
      };
      expect(Patch.hasImpl(['js'], patch)).to.be.true();
    });
    it('should return true for a few existent impls', () => {
      const patch = {
        impls: {
          js: '//ok',
          nodejs: '//ok',
        },
      };
      expect(Patch.hasImpl(['js', 'nodejs'], patch)).to.be.true();
    });
  });
  describe('isTerminalPatch', () => {
    it('should return false for empty', () => {
      expect(Patch.isTerminalPatch({})).to.be.false();
    });
    it('should return false for patch without terminal pin', () => {
      expect(Patch.isTerminalPatch({
        pins: {
          a: {
            key: 'a',
          },
        },
      })).to.be.false();
    });
    it('should return true for patch with terminal input pin', () => {
      expect(Patch.isTerminalPatch({
        pins: {
          __in__: {
            key: '__in__',<commit_msg>fix(xod-project): fix test in case of renaming `hasImpl` -> `hasImpls`<commit_after>import R from 'ramda';
import chai, { expect } from 'chai';
import dirtyChai from 'dirty-chai';

import * as Patch from '../src/patch';
import * as CONST from '../src/constants';

import * as Helper from './helpers';

chai.use(dirtyChai);

describe('Patch', () => {
  // constructors
  describe('createPatch', () => {
    it('should return Patch that is an object', () => {
      const patch = Patch.createPatch();

      expect(patch).is.an('object');
    });
    it('should have key: nodes === {}', () => {
      const patch = Patch.createPatch();

      expect(patch)
        .to.have.property('nodes')
        .that.is.an('object')
        .that.is.empty();
    });
    it('should have key: links === {}', () => {
      const patch = Patch.createPatch();

      expect(patch)
        .to.have.property('links')
        .that.is.an('object')
        .that.is.empty();
    });
  });
  describe('duplicatePatch', () => {
    const patch = { nodes: {}, label: 'test' };
    it('should return new patch (not the same object)', () => {
      const newPatch = Patch.duplicatePatch(patch);
      expect(newPatch)
        .to.be.an('object')
        .and.not.to.be.equal(patch);
    });
    it('should be deeply cloned (not the same nested objects)', () => {
      const newPatch = Patch.duplicatePatch(patch);
      expect(newPatch)
        .have.property('label')
        .that.equal(patch.label);
      expect(newPatch)
        .have.property('nodes')
        .that.not.equal(patch.nodes);
    });
  });

  // properties
  describe('getPatchLabel', () => {
    it('should return empty String for empty patch object', () => {
      expect(Patch.getPatchLabel({})).to.be.equal('');
    });
    it('should return patch label', () => {
      const label = 'patchLabel';
      expect(Patch.getPatchLabel({ label })).to.be.equal(label);
    });
  });
  describe('setPatchLabel', () => {
    it('should return patch with new label', () => {
      const newLabel = 'new label';
      const patch = { label: 'old label' };
      const newPatch = Patch.setPatchLabel(newLabel, patch);

      expect(newPatch)
        .to.have.property('label')
        .that.is.a('string')
        .that.equals(newLabel);
    });
    it('should always set a string to label', () => {
      expect(Patch.setPatchLabel('test', {}))
        .to.have.property('label')
        .that.equals('test');
      expect(Patch.setPatchLabel(5, {}))
        .to.have.property('label')
        .that.equals('5');
      expect(Patch.setPatchLabel([1, 2], {}))
        .to.have.property('label')
        .that.equals('1,2');
      expect(Patch.setPatchLabel({}, {}))
        .to.have.property('label')
        .that.equals('[object Object]');
    });
  });
  describe('listImpls', () => {
    it('should return empty array for empty patch', () => {
      expect(Patch.listImpls({}))
        .to.be.instanceof(Array)
        .to.be.empty();
    });
    it('should return array with keys: `js`, `espruino`', () => {
      const patch = {
        impls: {
          js: '',
          espruino: '',
        },
      };
      expect(Patch.listImpls(patch))
        .to.be.an('array')
        .to.have.members(['js', 'espruino']);
    });
  });
  describe('hasImpls', () => {
    it('should return false for empty', () => {
      expect(Patch.hasImpls(['js'], {})).to.be.false();
    });
    it('should return false if impl not found', () => {
      const patch = {
        impls: {
          js: '//ok',
        },
      };
      expect(Patch.hasImpls(['cpp'], patch)).to.be.false();
    });
    it('should return true for the only correct impl', () => {
      const patch = {
        impls: {
          js: '//ok',
        },
      };
      expect(Patch.hasImpls(['js'], patch)).to.be.true();
    });
    it('should return true for a few existent impls', () => {
      const patch = {
        impls: {
          js: '//ok',
          nodejs: '//ok',
        },
      };
      expect(Patch.hasImpls(['js', 'nodejs'], patch)).to.be.true();
    });
  });
  describe('isTerminalPatch', () => {
    it('should return false for empty', () => {
      expect(Patch.isTerminalPatch({})).to.be.false();
    });
    it('should return false for patch without terminal pin', () => {
      expect(Patch.isTerminalPatch({
        pins: {
          a: {
            key: 'a',
          },
        },
      })).to.be.false();
    });
    it('should return true for patch with terminal input pin', () => {
      expect(Patch.isTerminalPatch({
        pins: {
          __in__: {
            key: '__in__',
{'fraction_non_alphanumeric': 0.19716775599128541, 'fraction_numerical': 0.00130718954248366, 'mean_word_length': 2.1900625434329397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5311092', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2858, 'n_words': 579}