<commit_before>/* globals expect, beforeEach, it, describe, jasmine */
import commandBuilder from '../../../../src/patterns/behavioral/command.js';
import chainOfResponsibilityBuilder from '../../../../src/patterns/behavioral/chainOfResponsibility.js';

describe('command', function() {
  var someMethodSpy;
  var Command;
  var command;
  beforeEach(function() {
    someMethodSpy = jasmine.createSpy('someMethod');
    Command = commandBuilder({
      publics: {
        someMethod: someMethodSpy
      }
    }).build();
    command = new Command();
    command.execute('someMethod', 'test');
  });
  it('should execute a command', function() {
    expect(someMethodSpy).toHaveBeenCalledWith('test');
  });
  describe('Advanced Level: Undo Redo', function() {
    var IUndoRedo;
    var implementsInterface;
    var chain;
    var UndoManager;
    var undoManager;
    var PointInTime;
    var runSpy;
    var redoSpy;
    var undoSpy;
    beforeEach(function() {
      PointInTime = function(data) {
        this.data = data;
        this.previous = null;
        this.next = null;
      };

      IUndoRedo = ['run', 'undo', 'redo'];
      implementsInterface = (i, o) => {
        return i.map(_ => o[_] instanceof Function).reduce((a, b) => a && b);
      };
      chain = (...args) => {
        var Chain = chainOfResponsibilityBuilder().build();
        var overloader = new Chain();
        args.forEach(overloader.add.bind(overloader));
        return overloader.run;
      };

      UndoManager = commandBuilder({
        constructor() {
          this.methods = {};
          this.pit = new PointInTime();
          var execute = this.execute.bind(this);
          this.execute = chain(
            (_, ...args) => { execute(...args); },
            this._onExecute.bind(this)
          );
        },
        publics: {
          _onExecute(next, _, ...args) {
            if(_ !== 'run') {
              return this.execute.apply(null, ['run', _].concat(args));
            }
            var pit = new PointInTime(args);
            pit.previous = this.pit;
            this.pit.next = pit;
            this.pit = pit;
            next();
          },
          run(method, ...args) {
            return this.methods[method] && this.methods[method].run(...args);
          },
          add(method, obj) {
            if(!implementsInterface(IUndoRedo, obj)) {<commit_msg>remove chainOfResponsibility from command pattern advance test<commit_after>/* globals expect, beforeEach, it, describe, jasmine */
import commandBuilder from '../../../../src/patterns/behavioral/command.js';

describe('command', function() {
  var someMethodSpy;
  var Command;
  var command;
  beforeEach(function() {
    someMethodSpy = jasmine.createSpy('someMethod');
    Command = commandBuilder({
      publics: {
        someMethod: someMethodSpy
      }
    }).build();
    command = new Command();
    command.execute('someMethod', 'test');
  });
  it('should execute a command', function() {
    expect(someMethodSpy).toHaveBeenCalledWith('test');
  });
  describe('Advanced Level: Undo Redo', function() {
    var IUndoRedo;
    var implementsInterface;
    var UndoManager;
    var undoManager;
    var PointInTime;
    var runSpy;
    var redoSpy;
    var undoSpy;
    beforeEach(function() {
      PointInTime = function(data) {
        this.data = data;
        this.previous = null;
        this.next = null;
      };

      IUndoRedo = ['run', 'undo', 'redo'];
      implementsInterface = (i, o) => {
        return i.map(_ => o[_] instanceof Function).reduce((a, b) => a && b);
      };

      UndoManager = commandBuilder({
        constructor() {
          this.methods = {};
          this.pit = new PointInTime();
          var execute = this.execute.bind(this);
          this.execute = (...args) => {
            execute(...args);
            this._onExecute(...args);
          };
        },
        publics: {
          _onExecute(_, ...args) {
            if(_ !== 'run') {
              return this.execute('run', _, ...args);
            }
            var pit = new PointInTime(args);
            pit.previous = this.pit;
            this.pit.next = pit;
            this.pit = pit;
          },
          run(method, ...args) {
            return this.methods[method] && this.methods[method].run(...args);
          },
          add(method, obj) {
            if(!implementsInterface(IUndoRedo, obj)) {
{'fraction_non_alphanumeric': 0.15032827711116142, 'fraction_numerical': 0.0, 'mean_word_length': 2.0489993098688752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1879507', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1283, 'n_words': 277}